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

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

Introduction

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

Prototype

public void activate() 

Source Link

Document

Activates this cell editor.

Usage

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) {//from ww  w.  jav  a2  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.apache.directory.studio.aciitemeditor.dialogs.MultiValuedDialog.java

License:Apache License

/**
 * Opens the editor and adds the new value to the list.
 *///from   ww w  .j  av  a2  s .c o m
private void addValue() {
    IAttribute attribute = new Attribute(context.getEntry(), ""); //$NON-NLS-1$
    IValue value = new Value(attribute, ""); //$NON-NLS-1$
    Object oldRawValue = valueEditor.getRawValue(value); //$NON-NLS-1$

    CellEditor cellEditor = valueEditor.getCellEditor();
    cellEditor.setValue(oldRawValue);
    cellEditor.activate();
    Object newRawValue = cellEditor.getValue();

    if (newRawValue != null) {
        String newValue = (String) valueEditor.getStringOrBinaryValue(newRawValue);

        values.add(newValue);
        tableViewer.refresh();
    }
}

From source file:org.apache.directory.studio.aciitemeditor.dialogs.MultiValuedDialog.java

License:Apache License

/**
 * Opens the editor with the currently selected
 * value and puts the modified value into the list.
 *///from  ww  w.  j  a v a 2 s  .c  o m
private void editValue() {
    String oldValue = getSelectedValue();
    if (oldValue != null) {
        IAttribute attribute = new Attribute(context.getEntry(), ""); //$NON-NLS-1$
        IValue value = new Value(attribute, oldValue); //$NON-NLS-1$
        Object oldRawValue = valueEditor.getRawValue(value); //$NON-NLS-1$

        CellEditor cellEditor = valueEditor.getCellEditor();
        cellEditor.setValue(oldRawValue);
        cellEditor.activate();
        Object newRawValue = cellEditor.getValue();

        if (newRawValue != null) {
            String newValue = (String) valueEditor.getStringOrBinaryValue(newRawValue);

            values.remove(oldValue);
            values.add(newValue);
            tableViewer.refresh();
        }
    }
}

From source file:org.apache.directory.studio.aciitemeditor.widgets.ACIItemProtectedItemsComposite.java

License:Apache License

/**
 * Called, when pushing the edit button. Opens the text editor.
 *
 *//*from  w  ww .j av a 2s. co m*/
private void editProtectedItem() {
    ProtectedItemWrapper protectedItemWrapper = getSelectedProtectedItemWrapper();

    AbstractDialogStringValueEditor valueEditor = protectedItemWrapper.getValueEditor();
    if (valueEditor != null) {
        if (protectedItemWrapper.isMultivalued()) {
            MultiValuedDialog dialog = new MultiValuedDialog(getShell(), protectedItemWrapper.getDisplayName(),
                    protectedItemWrapper.getValues(), context, valueEditor);
            dialog.open();
            refreshTable();
        } else {
            List<String> values = protectedItemWrapper.getValues();
            String oldValue = values.isEmpty() ? null : values.get(0);
            if (oldValue == null) {
                oldValue = ""; //$NON-NLS-1$
            }

            IAttribute attribute = new Attribute(context.getEntry(), ""); //$NON-NLS-1$
            IValue value = new Value(attribute, oldValue); //$NON-NLS-1$
            Object oldRawValue = valueEditor.getRawValue(value); //$NON-NLS-1$

            CellEditor cellEditor = valueEditor.getCellEditor();
            cellEditor.setValue(oldRawValue);
            cellEditor.activate();
            Object newRawValue = cellEditor.getValue();

            if (newRawValue != null) {
                String newValue = (String) valueEditor.getStringOrBinaryValue(newRawValue);

                values.clear();
                values.add(newValue);
                tableViewer.refresh();
            }
        }
    }
}

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   w w w.j  av a 2 s. 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);/*from  w  ww.  j  a va 2s .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.
 *//*w  w w .j  a  va2 s  . c  o m*/
private void performDirectEdit() {
    CellEditor cellEditor = createCellEditor();
    locateCellEditor(cellEditor);
    cellEditor.activate();
    cellEditor.setFocus();
}

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();/*  www .j  a va 2 s. c  o  m*/
    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();
        }
    }
}