/** * Activate a cell editor for the given mouse position. */ private void activateCellEditor(MouseEvent event) { if (tableItem == null || tableItem.isDisposed()) { // item no longer exists return; } int columnToEdit; int columns = getColumnCount(); if (columns == 0) { // If no TableColumn, Table acts as if it has a single column // which takes the whole width. columnToEdit = 0; } else { columnToEdit = -1; for (int i = 0; i < columns; i++) { Rectangle bounds = getBounds(tableItem, i); if (bounds.contains(event.x, event.y)) { columnToEdit = i; break; } } if (columnToEdit == -1) { return; } } columnNumber = columnToEdit; activateCellEditor(); }
/** * Handles the mouse down event; activates the cell editor. * * @param event * the mouse event that should be handled */ public void handleMouseDown(MouseEvent event) { if (event.button != 1) { return; } if (cellEditor != null) { applyEditorValue(); } // activate the cell editor immediately. If a second mouseDown // is received prior to the expiration of the doubleClick time then // the cell editor will be deactivated and a doubleClick event will // be processed. // doubleClickExpirationTime = event.time + Display.getCurrent().getDoubleClickTime(); Item[] items = getSelection(); // Do not edit if more than one row is selected. if (items.length != 1) { tableItem = null; return; } tableItem = items[0]; activateCellEditor(event); }
/** * Start editing the given element. * * @param element * @param column */ public void editElement(Object element, int column) { if (cellEditor != null) { applyEditorValue(); } setSelection(new StructuredSelection(element), true); Item[] selection = getSelection(); if (selection.length != 1) { return; } tableItem = selection[0]; // Make sure selection is visible showSelection(); columnNumber = column; activateCellEditor(); }