Search in sources :

Example 61 with TextCellEditor

use of org.eclipse.jface.viewers.TextCellEditor in project yamcs-studio by yamcs.

the class SpinnerTextEditManager method createCellEditorOn.

@Override
protected CellEditor createCellEditorOn(Composite composite) {
    CellEditor editor = new TextCellEditor(composite, (multiLine ? SWT.MULTI : SWT.SINGLE) | SWT.WRAP) {

        @Override
        protected void focusLost() {
            // lose focus should cancel the editing.
            if (editPart.getExecutionMode() == ExecutionMode.RUN_MODE && editPart instanceof IPVWidgetEditpart && ((IPVWidgetEditpart) editPart).getPV() != null) {
                if (isActivated()) {
                    fireCancelEditor();
                    deactivate();
                }
                editPart.getFigure().requestFocus();
            } else
                super.focusLost();
        }

        @Override
        protected void handleDefaultSelection(SelectionEvent event) {
            // In run mode, hit ENTER should force to write the new value even it doesn't change.
            if (editPart.getExecutionMode() == ExecutionMode.RUN_MODE) {
                setDirty(true);
            }
            super.handleDefaultSelection(event);
        }

        @Override
        protected void keyReleaseOccured(KeyEvent keyEvent) {
            // In run mode, CTRL+ENTER will always perform a write if it is multiline text input
            if (keyEvent.character == '\r' && editPart.getExecutionMode() == ExecutionMode.RUN_MODE) {
                // Return key
                if (text != null && !text.isDisposed() && (text.getStyle() & SWT.MULTI) != 0) {
                    if ((keyEvent.stateMask & SWT.CTRL) != 0) {
                        setDirty(true);
                    }
                }
            }
            if (keyEvent.keyCode == SWT.ARROW_UP) {
                doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) + step_increment));
                CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
                stack.execute(getEditPart().getCommand(getDirectEditRequest()));
            }
            if (keyEvent.keyCode == SWT.ARROW_DOWN) {
                doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) - step_increment));
                CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
                stack.execute(getEditPart().getCommand(getDirectEditRequest()));
            }
            if (keyEvent.keyCode == SWT.PAGE_UP) {
                doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) + page_increment));
                CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
                stack.execute(getEditPart().getCommand(getDirectEditRequest()));
            }
            if (keyEvent.keyCode == SWT.PAGE_DOWN) {
                doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) - page_increment));
                CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
                stack.execute(getEditPart().getCommand(getDirectEditRequest()));
            }
            super.keyReleaseOccured(keyEvent);
        }
    };
    editor.getControl().moveAbove(null);
    return editor;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) IPVWidgetEditpart(org.csstudio.opibuilder.editparts.IPVWidgetEditpart) CommandStack(org.eclipse.gef.commands.CommandStack) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Aggregations

TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)61 CellEditor (org.eclipse.jface.viewers.CellEditor)46 GridData (org.eclipse.swt.layout.GridData)22 ICellModifier (org.eclipse.jface.viewers.ICellModifier)21 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 Composite (org.eclipse.swt.widgets.Composite)21 GridLayout (org.eclipse.swt.layout.GridLayout)19 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)15 TableViewer (org.eclipse.jface.viewers.TableViewer)14 Label (org.eclipse.swt.widgets.Label)14 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)14 Map (java.util.Map)13 Button (org.eclipse.swt.widgets.Button)12 HashMap (java.util.HashMap)11 Item (org.eclipse.swt.widgets.Item)11 TableColumn (org.eclipse.swt.widgets.TableColumn)10 TableItem (org.eclipse.swt.widgets.TableItem)10 Text (org.eclipse.swt.widgets.Text)10 Group (org.eclipse.swt.widgets.Group)8