List of usage examples for org.eclipse.jface.viewers TextCellEditor setFocus
public void setFocus()
From source file:org.eclipse.debug.ui.memory.AbstractTableRendering.java
License:Open Source License
/** * Activate cell editor and pre-fill it with initial value. * If initialValue is null, use cell content as initial value * @param initialValue the initial value to edit *///from w w w . ja va 2s. c o m private void activateCellEditor(String initialValue) { int col = fTableCursor.getColumn(); int row = findAddressIndex(fSelectedAddress); if (row < 0) return; // do not allow user to edit address column if (col == 0 || col > getNumCol()) { return; } ICellModifier cellModifier = null; if (fTableViewer == null) { return; } cellModifier = fTableViewer.getCellModifier(); TableItem tableItem = fTableViewer.getTable().getItem(row); Object element = tableItem.getData(); Object property = fTableViewer.getColumnProperties()[col]; Object value = cellModifier.getValue(element, (String) property); // The cell modifier canModify function always returns false if the edit action // is not invoked from here. This is to prevent data to be modified when // the table cursor loses focus from a cell. By default, data will // be changed in a table when the cell loses focus. This is to workaround // this default behavior and only change data when the cell editor // is activated. ((TableRenderingCellModifier) cellModifier).setEditActionInvoked(true); boolean canEdit = cellModifier.canModify(element, (String) property); ((TableRenderingCellModifier) cellModifier).setEditActionInvoked(false); if (!canEdit) return; // activate based on current cursor position TextCellEditor selectedEditor = (TextCellEditor) fTableViewer.getCellEditors()[col]; if (fTableViewer != null && selectedEditor != null) { // The control that will be the editor must be a child of the Table Text text = (Text) selectedEditor.getControl(); String cellValue = null; if (initialValue != null) { cellValue = initialValue; } else { cellValue = ((String) value); } text.setText(cellValue); fCursorEditor.horizontalAlignment = SWT.LEFT; fCursorEditor.grabHorizontal = true; // Open the text editor in selected column of the selected row. fCursorEditor.setEditor(text, tableItem, col); // Assign focus to the text control selectedEditor.setFocus(); if (initialValue != null) { text.clearSelection(); } text.setFont(JFaceResources.getFont(IInternalDebugUIConstants.FONT_NAME)); // add listeners for the text control addListeners(text); // move cursor below text control fTableCursor.moveBelow(text); } }