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

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

Introduction

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

Prototype

public final void setValue(Object value) 

Source Link

Document

Sets this cell editor's value.

Usage

From source file:com.centurylink.mdw.plugin.designer.dialogs.VariableValueDialog.java

License:Apache License

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.getShell().setText("Variable Value");

    Label nameLabel = new Label(composite, SWT.NONE);
    nameLabel.setFont(new Font(nameLabel.getDisplay(), new FontData("Tahoma", 8, SWT.BOLD)));
    nameLabel.setText(variableValue.getName());

    final String type = variableValue.getType() == null ? "Unknown" : variableValue.getType().getVariableType();
    new Label(composite, SWT.NONE).setText("(" + type + ")");

    if (type.equals("java.lang.Boolean")) {
        valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_CHECKBOX);
    } else if (type.equals("java.util.Date")) {
        valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_DATE_PICKER);
        valueEditor.setWidth(100);// ww w. j  ava  2  s  . c om
    } else if (type.equals("java.lang.Integer") || type.equals("java.lang.Long")) {
        valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_TEXT);
        valueEditor.setWidth(250);
        valueEditor.addValueChangeListener(new ValueChangeListener() {
            public void propertyValueChanged(Object newValue) {
                String stringValue = (String) newValue;
                try {
                    long val = type.equals("java.lang.Long") ? Long.parseLong(stringValue)
                            : Integer.parseInt(stringValue);
                    variableValue.setValue(String.valueOf(val));
                } catch (NumberFormatException ex) {
                    String oldValue = variableValue.getValue();
                    valueEditor.setValue(oldValue);
                }
            }
        });
    } else if (type.equals("java.net.URI")) {
        valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_TEXT);
        valueEditor.setWidth(450);
        valueEditor.addValueChangeListener(new ValueChangeListener() {
            public void propertyValueChanged(Object newValue) {
                try {
                    new URI((String) newValue);
                    valueEditor.setLabel("");
                } catch (URISyntaxException ex) {
                    valueEditor.setLabel(ex.getMessage());
                }
            }
        });
    } else if (type.equals("java.lang.Integer[]") || type.equals("java.lang.Long[]")
            || type.equals("java.lang.String[]")) {
        valueEditor = new TableEditor(null, TableEditor.TYPE_TABLE);
        TableEditor tableEditor = (TableEditor) valueEditor;
        List<ColumnSpec> columnSpecs = new ArrayList<ColumnSpec>();
        ColumnSpec valueColSpec = new ColumnSpec(PropertyEditor.TYPE_TEXT,
                type.substring(type.lastIndexOf('.') + 1, type.length() - 2) + " Values", type);
        columnSpecs.add(valueColSpec);
        tableEditor.setColumnSpecs(columnSpecs);
        tableEditor.setFillWidth(true);
        tableEditor.setRowDelimiter(ROW_DELIMITER);
        tableEditor.setModelUpdater(new CollectionModelUpdater(tableEditor));
    } else if (type.equals("java.util.Map")) {
        valueEditor = new MappingEditor(null);
        MappingEditor mappingEditor = (MappingEditor) valueEditor;
        List<ColumnSpec> columnSpecs = new ArrayList<ColumnSpec>();
        ColumnSpec keyColSpec = new ColumnSpec(PropertyEditor.TYPE_TEXT, "Key", "key");
        keyColSpec.width = 150;
        columnSpecs.add(keyColSpec);
        ColumnSpec valColSpec = new ColumnSpec(PropertyEditor.TYPE_TEXT, "Value", "value");
        valColSpec.width = 150;
        columnSpecs.add(valColSpec);
        mappingEditor.setColumnSpecs(columnSpecs);
        mappingEditor.setHeight(150);
        mappingEditor.setFillWidth(true);
        mappingEditor.setRowDelimiter(ROW_DELIMITER);
        mappingEditor.setColumnDelimiter(COLUMN_DELIMITER);
        mappingEditor.setContentProvider(mappingEditor.new DefaultContentProvider());
        mappingEditor.setLabelProvider(((TableEditor) mappingEditor).new DefaultLabelProvider());
        mappingEditor.setCellModifier(((TableEditor) mappingEditor).new DefaultCellModifier());
        mappingEditor.setModelUpdater(new CollectionModelUpdater(mappingEditor));
    } else {
        valueEditor = new PropertyEditor(null, PropertyEditor.TYPE_TEXT);
        valueEditor.setMultiLine(true);
        valueEditor.setWidth(500);
        valueEditor.setHeight(500);
    }
    valueEditor.setReadOnly(variableValue.isReadOnly());
    valueEditor.render(composite);
    valueEditor.setValue(variableValue.getValue());
    if (!variableValue.isReadOnly()) {
        valueEditor.addValueChangeListener(new ValueChangeListener() {
            public void propertyValueChanged(Object newValue) {
                Button okButton = getButton(Dialog.OK);
                if (okButton != null) // else not editable
                    okButton.setEnabled(true);
            }
        });
    }
    if (isCollectionType(type))
        tentativeValueForCollection = variableValue.getValue();

    if (type.equals("java.lang.Boolean"))
        ((Button) valueEditor.getWidget()).setText("(checked = true)");
    else if (type.equals("java.lang.Object"))
        valueEditor.setValue(variableValue.getValue() == null ? null : variableValue.getValue().toString());
    else if (type.equals("java.lang.Integer[]") || type.equals("java.lang.Long[]")) {
        if (!variableValue.isReadOnly()) {
            TableEditor tableEditor = (TableEditor) valueEditor;
            final CellEditor cellEditor = tableEditor.getTableViewer().getCellEditors()[0];
            cellEditor.setValidator(new ICellEditorValidator() {
                private String oldValue = "";

                public String isValid(Object value) {
                    String message = validateValue((String) value, variableValue.getType().getVariableType());
                    if (message != null)
                        cellEditor.setValue(oldValue);
                    else
                        oldValue = (String) value;
                    return null;
                }
            });
        }
    } else if (type.equals("java.util.Map")) {
        if (!variableValue.isReadOnly()) {
            MappingEditor mappingEditor = (MappingEditor) valueEditor;
            final CellEditor valueCellEditor = mappingEditor.getTableViewer().getCellEditors()[1];
            valueCellEditor.setValidator(new ICellEditorValidator() {
                public String isValid(Object value) {
                    String message = validateValue((String) value, variableValue.getType().getVariableType());
                    if (message != null)
                        getButton(Dialog.OK).setEnabled(false);
                    return null;
                }
            });
        }
    }

    return composite;
}

From source file:com.nokia.sdt.component.symbian.actions.EditImageActionFilterDelegate.java

License:Open Source License

@Override
protected void executeActionCommand(IAction action, EObject instance, CommandStack commandStack) {
    String propertyPath = getPrimaryImageProperty(instance);
    IPropertyDescriptor descriptor = getImagePropertyDescriptor(instance, propertyPath);
    Check.checkState(descriptor != null);

    CellEditor cellEditor = descriptor.createPropertyEditor(shell);
    IDialogCellEditorActivator activator = (IDialogCellEditorActivator) cellEditor;
    NodePathLookupResult result = ModelUtils.readProperty(instance, propertyPath, true);
    cellEditor.setValue(result.result);
    Object newValue = activator.invokeEditor(shell);
    if (newValue != null) {
        ChangePropertyCommand command = new ChangePropertyCommand(instance, propertyPath, newValue,
                cellEditor.getValidator());
        commandStack.execute(command);/*from w  w w . j av  a 2 s.  com*/
    }
}

From source file:com.nokia.sdt.series60.actions.EditArrayPropertyActionDelegate.java

License:Open Source License

@Override
protected void executeActionCommand(IAction action, EObject selected, CommandStack commandStack) {
    ArrayPropertyDescriptor descriptor = getEditableArrayPropertyDescriptor(selected);
    Check.checkState(descriptor != null);

    CellEditor editor = descriptor.createPropertyEditor(getShell());
    Check.checkState(editor instanceof IDialogCellEditorActivator);

    IPropertySource ps = ModelUtils.getPropertySource(selected);

    // initialize
    editor.setValue(ps.getPropertyValue(descriptor.getId()));

    IDialogCellEditorActivator activator = (IDialogCellEditorActivator) editor;
    Object result = activator.invokeEditor(getShell());
    if (result != null) {
        ChangePropertyCommand command = new ChangePropertyCommand(selected, descriptor.getId().toString(),
                result, null);/*from w w w.  j  a va  2  s. com*/
        commandStack.execute(command);
    }
}

From source file:com.nokia.sdt.symbian.ui.images.DirectEditingUtilities.java

License:Open Source License

/**
 * Edit the given image property in a dialog and return the command.
 * @param shell/* w  w  w . ja v a  2  s.  c  o  m*/
 * @param instance
 * @param propertyPath
 * @return command, or null if no change
 */
public static Command editImageProperty(Shell shell, EObject instance, String propertyPath) {
    IDialogCellEditorActivator activator = getCellEditorActivator(shell, instance, propertyPath);
    if (activator == null)
        return null;

    NodePathLookupResult result = ModelUtils.readProperty(instance, propertyPath, true);

    CellEditor cellEditor = (CellEditor) activator;
    cellEditor.setValue(result.result);

    Object newValue = activator.invokeEditor(shell);
    if (newValue != null) {
        ChangePropertyCommand command = new ChangePropertyCommand(instance, propertyPath, newValue,
                cellEditor.getValidator());
        return command;
    }
    return null;
}

From source file:com.worldline.awltech.i18ntools.editor.ui.EditorDefaultMessageEditingSupport.java

License:Open Source License

@Override
protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
    Object value = getValue(cell.getElement());
    cellEditor.setValue(value != null ? value : "");
}

From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.commands.renaming.FeatureLabelEditManager.java

License:Open Source License

@Override
protected void initCellEditor() {
    final CellEditor cellEditor = getCellEditor();
    final Control control = cellEditor.getControl();
    final String oldValue = ((FeatureEditPart) getEditPart()).getFeature().getName();

    control.setFont(DEFAULT_FONT);//from www .  j a  v  a2s.co m
    cellEditor.setValue(oldValue);

    cellEditor.addListener(new ICellEditorListener() {
        private ToolTip tooltip;

        public void editorValueChanged(boolean oldValidState, boolean newValidState) {
            boolean notvalid;
            closeTooltip();
            String value = (String) cellEditor.getValue();
            if (!value.equals(oldValue)) {
                if (value.equalsIgnoreCase(oldValue))
                    createTooltip(
                            "It is not recommended to change upper and lower case. You currently try to rename "
                                    + oldValue + " to " + value + ".",
                            SWT.ICON_WARNING);
                // TODO #455 wrong usage of extension
                else if ((notvalid = !featureModel.isValidFeatureName(value))
                        && !featureModel.isFeatureModelingComposer())
                    createTooltip("The name need to be a valid Java identifier.", SWT.ICON_ERROR);
                else if (notvalid)
                    createTooltip("The following Characaters are not allowed \", (, )", SWT.ICON_ERROR);
                else if (featureModel.getFeatureNames().contains(value))
                    createTooltip("This name is already used for another feature.", SWT.ICON_ERROR);
            }
        }

        public void cancelEditor() {
            closeTooltip();
        }

        public void applyEditorValue() {
            closeTooltip();
        }

        private void createTooltip(String message, int icon) {
            tooltip = new ToolTip(control.getShell(), SWT.BALLOON | icon);
            tooltip.setAutoHide(false);
            tooltip.setLocation(control.toDisplay(control.getSize().x / 2, control.getSize().y + 5));
            tooltip.setText("Invalid Name");
            tooltip.setMessage(message);
            tooltip.setVisible(true);
        }

        private void closeTooltip() {
            if (tooltip != null) {
                tooltip.setVisible(false);
                tooltip = null;
            }
        }
    });
}

From source file:eu.aniketos.wp1.ststool.diagram.edit.parts.STSTextDirectEditManager.java

License:Open Source License

/**
 * This method is used to set the cell editors text
 * /*from  w w  w  .  java  2  s .co m*/
 * @param toEdit
 *           String to be set in the cell editor
 */
public void setEditText(String toEdit) {

    // Get the cell editor
    CellEditor cellEditor = getCellEditor();

    // IF the cell editor doesn't exist yet...
    if (cellEditor == null) {
        // Do nothing
        return;
    }

    // Get the Text Compartment Edit Part
    ITextAwareEditPart textEP = (ITextAwareEditPart) getEditPart();

    // Get the Text control
    Text textControl = (Text) cellEditor.getControl();

    // Set the Figures text
    textEP.setLabelText(toEdit);

    // See RATLC00522324
    if (cellEditor instanceof TextCellEditorEx) {
        ((TextCellEditorEx) cellEditor).setValueAndProcessEditOccured(toEdit);
    } else {
        cellEditor.setValue(toEdit);
    }

    // Set the controls text and position the caret at the end of the text
    textControl.setSelection(toEdit.length());
}

From source file:featureide.fm.ui.editors.featuremodel.commands.renaming.FeatureLabelEditManager.java

License:Open Source License

@Override
protected void initCellEditor() {
    final CellEditor cellEditor = getCellEditor();
    final Control control = cellEditor.getControl();
    final String oldValue = ((FeatureEditPart) getEditPart()).getFeatureModel().getName();

    control.setFont(DEFAULT_FONT);//from   ww  w.  ja  v a2 s .c  om
    cellEditor.setValue(oldValue);

    cellEditor.addListener(new ICellEditorListener() {
        private ToolTip tooltip;

        @Override
        public void editorValueChanged(boolean oldValidState, boolean newValidState) {
            closeTooltip();
            String value = (String) cellEditor.getValue();
            if (!value.equals(oldValue)) {
                if (value.equalsIgnoreCase(oldValue))
                    createTooltip(
                            "It is not recommended to change upper and lower case. You currently try to rename "
                                    + oldValue + " to " + value + ".",
                            SWT.ICON_WARNING);
                else if (!FeatureRenamingCommand.isValidJavaIdentifier(value))
                    createTooltip("The name need to be a valid Java identifier.", SWT.ICON_ERROR);
                else if (featureModel.getFeatureNames().contains(value))
                    createTooltip("This name is already used for another feature.", SWT.ICON_ERROR);
            }
        }

        @Override
        public void cancelEditor() {
            closeTooltip();
        }

        @Override
        public void applyEditorValue() {
            closeTooltip();
        }

        private void createTooltip(String message, int icon) {
            tooltip = new ToolTip(control.getShell(), SWT.BALLOON | icon);
            tooltip.setAutoHide(false);
            tooltip.setLocation(control.toDisplay(control.getSize().x / 2, control.getSize().y + 5));
            tooltip.setText("Invalid Name");
            tooltip.setMessage(message);
            tooltip.setVisible(true);
        }

        private void closeTooltip() {
            if (tooltip != null) {
                tooltip.setVisible(false);
                tooltip = null;
            }
        }
    });
}

From source file:gov.redhawk.diagram.ui.tools.ComboDirectEditManager.java

License:Open Source License

/**
 * This method is used to set the cell editors text
 * /*from  w  w w  .j  a  v a2s. c om*/
 * @param toEdit
 *            String to be set in the cell editor
 */
public void setEditText(final String toEdit) {

    // Get the cell editor
    final CellEditor cellEditor = getCellEditor();

    // IF the cell editor doesn't exist yet...
    if (cellEditor == null) {
        // Do nothing
        return;
    }

    // Get the Text Compartment Edit Part
    final ITextAwareEditPart textEP = (ITextAwareEditPart) getEditPart();

    // Get the Text control
    final CCombo textControl = (CCombo) cellEditor.getControl();

    // Set the Figures text
    textEP.setLabelText(toEdit);

    cellEditor.setValue(toEdit);

    // Set the controls text and position the caret at the end of the text
    textControl.setSelection(new Point(0, toEdit.length()));
}

From source file:net.karlmartens.ui.viewer.TimeSeriesTableValueEditingSupport.java

License:Apache License

@Override
protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
    cellEditor.setValue("");

    final TimeSeriesEditingSupport editingSupport = _viewer.getEditingSupport();
    if (editingSupport == null)
        return;//from   ww  w  .  j av a2s  .c o m

    final TimeSeriesContentProvider cp = (TimeSeriesContentProvider) _viewer.getContentProvider();
    if (cp == null)
        return;

    final double value = cp.getValue(cell.getElement(), computePeriodIndex(cell));
    final NumberFormat format = getEditingNumberFormat(editingSupport);
    cellEditor.setValue(format.format(value));
}