Example usage for org.eclipse.jface.viewers CellEditor deactivate

List of usage examples for org.eclipse.jface.viewers CellEditor deactivate

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers CellEditor deactivate.

Prototype

public void deactivate() 

Source Link

Document

Hides this cell editor's control.

Usage

From source file:com.amalto.workbench.dialogs.datacontainer.UpdateAutoIncrementDialog.java

License:Open Source License

private void deactivateCellEditors() {
    CellEditor[] cellEditors = resultsViewer.getCellEditors();
    if (cellEditors != null) {
        for (CellEditor cellEditor : cellEditors) {
            cellEditor.deactivate();
        }/*from   w w  w .  ja  va2s.c o m*/
    }
}

From source file:org.csstudio.sds.components.ui.internal.editparts.ActionButtonEditPart.java

License:Open Source License

private CellEditor createCellEditor2() {
    final CellEditor result = new TextCellEditor((Composite) getViewer().getControl());

    // init cell editor...
    String currentValue = "N/A"; //$NON-NLS-1$
    currentValue = getWidgetModel().getStringProperty(ActionButtonModel.PROP_LABEL);

    result.setValue(currentValue);/* ww  w  . j  ava2 s .c o m*/
    final Text text = (Text) result.getControl();
    // input text
    text.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent e) {
            if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
                getWidgetModel().setPropertyValue(ActionButtonModel.PROP_LABEL, text.getText());
                result.deactivate();
                result.dispose();
            } else if (e.keyCode == SWT.ESC) {
                result.deactivate();
                result.dispose();
            }

        }

    });

    text.setForeground(getModelColor(AbstractWidgetModel.PROP_COLOR_FOREGROUND));
    text.setFont(getModelFont(ActionButtonModel.PROP_FONT));

    // calculate background color
    final RGB backgroundRgb = getModelColor(AbstractWidgetModel.PROP_COLOR_BACKGROUND).getRGB();

    final int red = Math.min(backgroundRgb.red + INPUT_FIELD_BRIGHTNESS, 255);
    final int green = Math.min(backgroundRgb.green + INPUT_FIELD_BRIGHTNESS, 255);
    final int blue = Math.min(backgroundRgb.blue + INPUT_FIELD_BRIGHTNESS, 255);

    final Color backgroundColor = CustomMediaFactory.getInstance().getColor(new RGB(red, green, blue));

    text.setBackground(backgroundColor);
    text.selectAll();

    return result;
}

From source file:org.csstudio.sds.components.ui.internal.editparts.LabelEditPart.java

License:Open Source License

private CellEditor createCellEditor2() {
    final CellEditor result = new TextCellEditor((Composite) getViewer().getControl());

    // init cell editor...
    String currentValue = "N/A"; //$NON-NLS-1$
    currentValue = getWidgetModel().getStringProperty(LabelModel.PROP_TEXTVALUE);

    result.setValue(currentValue);/*from   w w w .j  a v a2 s.c o  m*/
    final Text text = (Text) result.getControl();
    // input text
    text.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent e) {
            if ((e.keyCode == SWT.CR) || (e.keyCode == SWT.KEYPAD_CR)) {
                SetPropertyCommand setPropertyCommand = new SetPropertyCommand(getWidgetModel(),
                        LabelModel.PROP_TEXTVALUE, text.getText());
                getViewer().getEditDomain().getCommandStack().execute(setPropertyCommand);
            } else if (e.keyCode == SWT.ESC) {
                result.deactivate();
            }
        }

    });

    text.setForeground(getModelColor(AbstractWidgetModel.PROP_COLOR_FOREGROUND));
    text.setFont(getModelFont(LabelModel.PROP_FONT));

    // calculate the chosen background color
    RGB backgroundRgb = getModelColor(AbstractWidgetModel.PROP_COLOR_BACKGROUND).getRGB();

    int red = Math.min(backgroundRgb.red + INPUT_FIELD_BRIGHTNESS, 255);
    int green = Math.min(backgroundRgb.green + INPUT_FIELD_BRIGHTNESS, 255);
    int blue = Math.min(backgroundRgb.blue + INPUT_FIELD_BRIGHTNESS, 255);

    Color backgroundColor = CustomMediaFactory.getInstance().getColor(new RGB(red, green, blue));

    text.setBackground(backgroundColor);
    text.selectAll();

    return result;
}

From source file:org.csstudio.sds.components.ui.internal.editparts.TextInputEditPart.java

License:Open Source License

/**
 * Create the cell editor for direct editing.
 *
 * @return The cell editor for direct editing.
 *//*ww w . jav  a 2 s . c om*/
private CellEditor createCellEditor() {
    final CellEditor result = new TextCellEditor((Composite) getViewer().getControl());

    // init cell editor...
    String currentValue = "N/A"; //$NON-NLS-1$
    currentValue = getWidgetModel().getStringProperty(TextInputModel.PROP_INPUT_TEXT);

    result.setValue(currentValue);
    final Text text = (Text) result.getControl();
    text.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent e) {
            if ((e.keyCode == SWT.CR) || (e.keyCode == SWT.KEYPAD_CR)) {
                int option = getWidgetModel().getArrayOptionProperty(TextInputModel.PROP_TEXT_TYPE);

                TextTypeEnum propertyValue = TextTypeEnum.values()[option];
                if (!propertyValue.isValidFormat(text.getText())) {
                    InvalidFormatDialog dialog = new InvalidFormatDialog(Display.getCurrent().getActiveShell());
                    dialog.setText(text.getText());
                    dialog.open();
                    LOG.warn("Invalid value format: " + text.getText());
                    return;
                }
                DirectEditCommand cmd = new DirectEditCommand(text.getText(), getExecutionMode());
                // In EDIT mode use the CommandStack provided by the DisplayEditor to execute the command.
                if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
                    getViewer().getEditDomain().getCommandStack().execute(cmd);
                } else {
                    cmd.execute();
                }
            } else if (e.keyCode == SWT.ESC) {
                result.deactivate();
            }
        }

    });
    text.addVerifyListener(new VerifyListener() {

        public void verifyText(final VerifyEvent e) {
            e.doit = true;
            int option = getWidgetModel().getArrayOptionProperty(TextInputModel.PROP_TEXT_TYPE);
            TextTypeEnum propertyValue = TextTypeEnum.values()[option];
            e.doit = propertyValue.isValidChars(e.character, e.text, e.start);

        }
    });

    text.setForeground(getModelColor(AbstractWidgetModel.PROP_COLOR_FOREGROUND));
    text.setFont(getModelFont(TextInputModel.PROP_FONT));

    // calculate background color
    RGB backgroundRgb = getModelColor(AbstractWidgetModel.PROP_COLOR_BACKGROUND).getRGB();

    int red = Math.min(backgroundRgb.red + INPUT_FIELD_BRIGHTNESS, 255);
    int green = Math.min(backgroundRgb.green + INPUT_FIELD_BRIGHTNESS, 255);
    int blue = Math.min(backgroundRgb.blue + INPUT_FIELD_BRIGHTNESS, 255);

    Color backgroundColor = CustomMediaFactory.getInstance().getColor(new RGB(red, green, blue));

    text.setBackground(backgroundColor);
    text.selectAll();

    return result;
}

From source file:org.eclipse.debug.internal.ui.viewers.TableEditorImpl.java

License:Open Source License

/**
 * Deactivates the currently active cell editor.
 *//* w w w.  j  av a 2 s.  co  m*/
public void applyEditorValue() {
    CellEditor c = fCellEditor;
    if (c != null) {
        // null out cell editor before calling save
        // in case save results in applyEditorValue being re-entered
        // see 1GAHI8Z: ITPUI:ALL - How to code event notification when
        // using cell editor ?
        fCellEditor = null;
        Item t = fTableItem;
        // don't null out table item -- same item is still selected
        if (t != null && !t.isDisposed()) {
            saveEditorValue(c, t);
        }
        setEditor(null, null, 0);
        c.removeListener(fCellEditorListener);
        Control control = c.getControl();
        if (control != null) {
            if (fMouseListener != null) {
                control.removeMouseListener(fMouseListener);
            }
            if (fFocusListener != null) {
                control.removeFocusListener(fFocusListener);
            }
        }
        c.deactivate();
    }
}

From source file:org.eclipse.debug.internal.ui.viewers.TableEditorImpl.java

License:Open Source License

/**
 * Cancels the active cell editor, without saving the value back to the
 * domain model./*from   www  .ja  v a2s  . c  o  m*/
 */
public void cancelEditing() {
    if (fCellEditor != null) {
        setEditor(null, null, 0);
        fCellEditor.removeListener(fCellEditorListener);
        CellEditor oldEditor = fCellEditor;
        fCellEditor = null;
        oldEditor.deactivate();
    }
}

From source file:org.eclipse.rcptt.tesla.internal.ui.processors.CellEditorSupport.java

License:Open Source License

protected Response handleApplyCellEditor(final ApplyCellEditor command) {
    final Element element = command.getElement();
    final SWTUIElement uiElement = getMapper().get(element);
    if (uiElement != null) {
        final CellEditor cellEditor = cellEditorActivations.get(uiElement.widget);
        if (cellEditor != null) {
            getPlayer().exec("Apply direct edit", new Runnable() {
                public void run() {
                    // TeslaCellEditorManager.getInstance().forceRemove(
                    // cellEditor);
                    TeslaSWTAccess.callMethodValueChanged(cellEditor, "valueChanged", cellEditor.isValueValid(),
                            true);//w ww  . j  a  v  a2  s  .com
                    // Check if there is modal dialog, then no deactivate is
                    // required.
                    TeslaSWTAccess.callMethod(cellEditor, "fireApplyEditorValue");
                    if (cellEditor instanceof ComboBoxViewerCellEditor) {
                        TeslaSWTAccess.callMethod(ComboBoxViewerCellEditor.class, cellEditor,
                                "applyEditorValueAndDeactivate");
                    }
                    if (command.isDeactivate()) {
                        cellEditor.deactivate();
                        cellEditorActivations.remove(uiElement.widget);
                    }
                }
            });
        }
    }

    return ProtocolFactory.eINSTANCE.createBooleanResponse();
}

From source file:org.eclipse.rcptt.tesla.internal.ui.processors.CellEditorSupport.java

License:Open Source License

protected Response handleDeactivateCellEditor(final DeactivateCellEditor command) {
    final Element element = command.getElement();
    final SWTUIElement uiElement = getMapper().get(element);
    if (uiElement != null) {
        final CellEditor cellEditor = cellEditorActivations.get(uiElement.widget);
        if (cellEditor != null) {
            getPlayer().exec("Deactivate cell edit", new Runnable() {
                public void run() {
                    cellEditor.deactivate();
                    getPlayer().getEvents().sendFocus(uiElement.unwrap());
                    cellEditorActivations.remove(uiElement.widget);
                }/*from  w ww.j a  v a 2s .  c  o  m*/
            });
        }
    }
    return ProtocolFactory.eINSTANCE.createBooleanResponse();
}

From source file:org.eclipse.rcptt.tesla.nebula.NebulaUIProcessor.java

License:Open Source License

@Override
protected CellEditorSupport createCellEditorSupport() {
    return new CellEditorSupport(this) {
        protected Response handleActivateCellEditor(final ActivateCellEditor command) {
            Element element = command.getElement();
            if (!element.getKind().equals(NebulaElementKinds.GRID))
                return super.handleActivateCellEditor(command);

            SWTUIElement uiElement = getMapper().get(element);
            final Grid grid = (Grid) PlayerWrapUtils.unwrapWidget(uiElement);
            final ColumnViewer viewer = TeslaSWTAccess.getThis(ColumnViewer.class, grid, SWT.MouseDown);

            getPlayer().exec("Activate editor in Nebula Grid", new Runnable() {
                public void run() {
                    Object item = ((IStructuredSelection) viewer.getSelection()).getFirstElement();

                    if (item != null)
                        viewer.editElement(item, command.getColumn());
                }/*from  w ww  . j  a  va  2s.  c o  m*/
            });

            return factory.createBooleanResponse();
        }

        protected Response handleCancelCellEditor(final CancelCellEditor command) {
            Element element = command.getElement();
            if (!element.getKind().equals(NebulaElementKinds.GRID))
                return super.handleCancelCellEditor(command);

            SWTUIElement uiElement = getMapper().get(element);
            final Grid grid = (Grid) PlayerWrapUtils.unwrapWidget(uiElement);
            final ColumnViewer viewer = TeslaSWTAccess.getThis(ColumnViewer.class, grid, SWT.MouseDown);

            getPlayer().exec("Cancel editing in Nebula Grid", new Runnable() {
                public void run() {
                    viewer.cancelEditing();
                }
            });

            return factory.createBooleanResponse();
        }

        @Override
        protected Response handleApplyCellEditor(final ApplyCellEditor command) {
            Element element = command.getElement();
            if (!element.getKind().equals(NebulaElementKinds.GRID))
                return super.handleApplyCellEditor(command);

            getPlayer().exec("Apply editing in Nebula Grid", new Runnable() {
                public void run() {
                    CellEditor editor = TeslaCellEditorManager.getInstance().getLastActivatedByAnyMethod();
                    if (editor != null) {
                        TeslaCellEditorManager.getInstance().forceRemove(editor);
                        TeslaSWTAccess.callMethodValueChanged(editor, "valueChanged", editor.isValueValid(),
                                true);
                        TeslaSWTAccess.callMethod(editor, "fireApplyEditorValue");
                        if (editor instanceof ComboBoxViewerCellEditor) {
                            TeslaSWTAccess.callMethod(ComboBoxViewerCellEditor.class, editor,
                                    "applyEditorValueAndDeactivate");
                        }
                        editor.deactivate();
                    }
                }
            });

            return factory.createBooleanResponse();
        }
    };
}

From source file:org.eclipse.wst.common.snippets.internal.util.TableViewerImpl.java

License:Open Source License

/**
 * Deactivates the currently active cell editor.
 *//*from   w w  w. jav  a2s.  co  m*/
public void applyEditorValue() {
    CellEditor c = this.fCellEditor;
    if (c != null) {
        // null out cell editor before calling save
        // in case save results in applyEditorValue being re-entered
        // see 1GAHI8Z: ITPUI:ALL - How to code event notification when
        // using cell editor ?
        this.fCellEditor = null;
        Item t = this.fTableItem;
        // don't null out table item -- same item is still selected
        if (t != null && !t.isDisposed()) {
            saveEditorValue(c, t);
        }
        setEditor(null, null, 0);
        c.removeListener(fCellEditorListener);
        c.deactivate();
    }
}