List of usage examples for org.eclipse.jface.viewers CellEditor setFocus
public void setFocus()
From source file:gov.nasa.ensemble.common.ui.treetable.TreeTableViewer.java
License:Open Source License
private void activateCellEditor(TreeItem item, Object element, Object facet, int columnIndex, ITreeTableColumn column) {//w w w . java 2 s. c o m trace.debug("activateCellEditor : " + facet); boolean edited = column.editOnActivate(facet, model.getUndoContext(), item, columnIndex); if (edited) { return; } CellEditor cellEditor = column.getCellEditor(getTree(), facet); if (cellEditorActionHandler != null) { cellEditorActionHandler.addCellEditor(cellEditor); } if (cellEditor == null) { return; // no editor } if (currentCellEditorHelper != null) { currentCellEditorHelper.applyEditorValue(); currentCellEditorHelper = null; } CellEditorHelper helper = new CellEditorHelper(facet, column, cellEditor, element); cellEditor.addListener(helper); @SuppressWarnings("unchecked") Font font = column.getFont(facet); if (font == null) { font = getTreeTableLabelProvider().getFont(element); } cellEditor.activate(); LayoutData layoutData = cellEditor.getLayoutData(); treeEditor.grabHorizontal = layoutData.grabHorizontal; treeEditor.horizontalAlignment = layoutData.horizontalAlignment; treeEditor.minimumWidth = layoutData.minimumWidth; Control control = cellEditor.getControl(); if (control != null) { control.setFont(font); control.addFocusListener(helper); control.forceFocus(); int[] order = getTree().getColumnOrder(); int editorIndex = order[columnIndex]; treeEditor.setEditor(control, item, editorIndex); } cellEditor.setFocus(); currentCellEditorHelper = helper; }
From source file:org.chrysalix.eclipse.focustree.FocusTreeCanvas.java
License:Open Source License
private void edit(final Label fieldEdited, final CellEditor editor, final EditorHandler editorHandler) { this.editor = editor; this.editorHandler = editorHandler; this.fieldEdited = fieldEdited; if (editor.getControl() == null) editor.create(this); final Cell cell = cell(fieldEdited); focusCell(column(cell), cell);//from w ww . jav a 2s . c o m getDisplay().asyncExec(new Runnable() { @Override public void run() { editor.setValue(fieldEdited.getText()); final Rectangle fieldBounds = fieldEdited.getBounds(); final Point viewLocation = getViewport().getViewLocation(); editor.getControl().setBounds(fieldBounds.x - viewLocation.x, fieldBounds.y - viewLocation.y, fieldBounds.width, editor.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y); editor.setValidator(new ICellEditorValidator() { private final Color originalForegroundColor = editor.getControl().getForeground(); @Override public String isValid(final Object value) { final String problem = editorHandler.problem(); if (problem == null) { editor.getControl().setToolTipText(null); editor.getControl().setForeground(originalForegroundColor); } else { editor.getControl().setToolTipText(problem); editor.getControl().setForeground(getDisplay().getSystemColor(SWT.COLOR_RED)); } return problem; } }); editor.addListener(new ICellEditorListener() { @Override public void applyEditorValue() { endEdit(); } @Override public void cancelEditor() { endEdit(); } @Override public void editorValueChanged(final boolean oldValidState, final boolean newValidState) { } }); editor.getControl().setVisible(true); editor.setFocus(); editor.performSelectAll(); } }); }
From source file:org.csstudio.sds.components.ui.internal.editparts.ActionButtonEditPart.java
License:Open Source License
private void performEditTextValue() { final CellEditor cellEditor = createCellEditor2(); locateCellEditor(cellEditor);//from ww w .j a v a 2s. c o m cellEditor.activate(); cellEditor.setFocus(); }
From source file:org.csstudio.sds.components.ui.internal.editparts.LabelEditPart.java
License:Open Source License
private void performEditTextValue() { CellEditor cellEditor = createCellEditor2(); locateCellEditor(cellEditor);/* w w w .ja va2 s.c o m*/ cellEditor.activate(); cellEditor.setFocus(); }
From source file:org.csstudio.sds.components.ui.internal.editparts.TextInputEditPart.java
License:Open Source License
/** * Open the cell editor for direct editing. *//*from www.ja v a 2 s .c o m*/ private void performDirectEdit() { CellEditor cellEditor = createCellEditor(); locateCellEditor(cellEditor); cellEditor.activate(); cellEditor.setFocus(); }
From source file:org.eclipse.debug.internal.ui.views.memory.renderings.AsyncTableRenderingViewer.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 for the cell editor *//*from w w w . ja v a2 s . c o m*/ private void activateCellEditor(String initialValue) { final int col = fTableCursor.getColumn(); final int row = indexOf(fSelectionKey); if (row < 0) return; // do not allow user to edit address column if (col == 0 || col > getNumCol()) { return; } ICellModifier cellModifier = null; cellModifier = getCellModifier(); TableItem tableItem = getTable().getItem(row); Object element = tableItem.getData(); if (element != null) { Object property = getColumnProperties()[col]; Object value = cellModifier.getValue(element, (String) property); boolean canEdit = cellModifier.canModify(element, (String) property); if (!canEdit) return; CellEditor editor = getCellEditors()[col]; if (editor != null) { // The control that will be the editor must be a child of the // Table Control control = editor.getControl(); Object cellValue = null; if (initialValue != null) { cellValue = initialValue; } else { cellValue = value; } editor.setValue(cellValue); fCursorEditor.horizontalAlignment = SWT.LEFT; fCursorEditor.grabHorizontal = true; // Open the editor editor in selected column of the selected // row. fCursorEditor.setEditor(control, tableItem, col); // Assign focus to the editor control editor.setFocus(); if (initialValue != null && control instanceof Text) { ((Text) control).clearSelection(); } control.setFont(JFaceResources.getFont(IInternalDebugUIConstants.FONT_NAME)); // add listeners for the editor control addListeners(control); fCellEditorListener = new CellEditorListener(row, col, editor); editor.addListener(fCellEditorListener); // move cursor below editor control fTableCursor.moveBelow(control); } } }
From source file:org.jkiss.dbeaver.ui.properties.PropertyTreeViewer.java
License:Open Source License
private void showEditor(final TreeItem item, boolean isDef) { // Clean up any previous editor control disposeOldEditor();/*from w w w . j a va 2 s . com*/ if (item == null) { return; } // Identify the selected row if (item.getData() instanceof TreeNode) { final Tree treeControl = super.getTree(); final TreeNode prop = (TreeNode) item.getData(); if (prop.property == null || !prop.isEditable()) { return; } final CellEditor cellEditor = UIUtils.createPropertyEditor(DBeaverUI.getActiveWorkbenchWindow(), treeControl, prop.propertySource, prop.property); if (cellEditor == null) { return; } final Object propertyValue = prop.propertySource.getPropertyValue(null, prop.property.getId()); final ICellEditorListener cellEditorListener = new ICellEditorListener() { @Override public void applyEditorValue() { //editorValueChanged(true, true); final Object value = cellEditor.getValue(); final Object oldValue = prop.propertySource.getPropertyValue(null, prop.property.getId()); if (!CommonUtils.equalObjects(oldValue, value)) { prop.propertySource.setPropertyValue(null, prop.property.getId(), value); handlePropertyChange(prop); } } @Override public void cancelEditor() { disposeOldEditor(); } @Override public void editorValueChanged(boolean oldValidState, boolean newValidState) { } }; cellEditor.addListener(cellEditorListener); if (propertyValue != null) { cellEditor.setValue(propertyValue); } curCellEditor = cellEditor; selectedProperty = prop.property; cellEditor.activate(); final Control editorControl = cellEditor.getControl(); if (editorControl != null) { editorControl.addTraverseListener(new TraverseListener() { @Override public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_RETURN) { e.doit = false; e.detail = SWT.TRAVERSE_NONE; cellEditorListener.applyEditorValue(); disposeOldEditor(); } else if (e.detail == SWT.TRAVERSE_ESCAPE) { e.doit = false; e.detail = SWT.TRAVERSE_NONE; disposeOldEditor(); if (prop.isEditable()) { new ActionResetProperty(prop, false).run(); } } } }); treeEditor.setEditor(editorControl, item, 1); } if (isDef) { // Selected by mouse cellEditor.setFocus(); } } }