Search in sources :

Example 36 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project webtools.sourceediting by eclipse.

the class ParametersBlock method createControl.

public void createControl(Composite parent) {
    Font font = parent.getFont();
    Group group = new Group(parent, SWT.NONE);
    group.setText(getName());
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    group.setLayoutData(gd);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    group.setLayout(layout);
    group.setFont(font);
    setControl(group);
    fTable = new Table(group, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    // data.heightHint = 100;
    fTable.setLayoutData(data);
    fTable.setFont(font);
    fTable.setHeaderVisible(true);
    fTable.setLinesVisible(true);
    TableColumn column1 = new TableColumn(fTable, SWT.NONE);
    column1.setWidth(150);
    column1.setResizable(true);
    column1.setText(Messages.ParametersBlock_0);
    TableColumn column3 = new TableColumn(fTable, SWT.NONE);
    column3.setWidth(250);
    column3.setResizable(true);
    column3.setText(Messages.ParametersBlock_2);
    parametersViewer = new ParameterViewer(fTable);
    parametersViewer.getViewer().setLabelProvider(new ParametersLabelProvider());
    parametersViewer.getViewer().setContentProvider(new ParametersContentProvider());
    parametersViewer.addParametersChangedListener(new IParametersChangedListener() {

        public void parametersChanged(ParameterViewer viewer) {
            updateLaunchConfigurationDialog();
        }
    });
    parametersViewer.getViewer().getTable().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.character == SWT.DEL && event.stateMask == 0) {
                RemoveParameterAction ra = new RemoveParameterAction(parametersViewer);
                ra.run();
                updateLaunchConfigurationDialog();
            }
        }
    });
    parametersViewer.getViewer().setColumnProperties(// $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "name", "value" });
    TextCellEditor textEditor = new TextCellEditor(fTable);
    CellEditor[] editors = new CellEditor[] { null, textEditor };
    parametersViewer.getViewer().setCellEditors(editors);
    parametersViewer.getViewer().setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            // $NON-NLS-1$
            return "value".equals(property);
        }

        public Object getValue(Object element, String property) {
            LaunchAttribute att = (LaunchAttribute) element;
            // $NON-NLS-1$
            return att.value == null ? "" : att.value;
        }

        public void modify(Object element, String property, Object value) {
            Item item = (Item) element;
            LaunchAttribute att = (LaunchAttribute) item.getData();
            att.value = (String) value;
            parametersViewer.getViewer().update(att, null);
            updateLaunchConfigurationDialog();
        }
    });
    Composite parameterButtonComp = new Composite(group, SWT.NONE);
    GridLayout parameterButtonCompLayout = new GridLayout();
    parameterButtonCompLayout.marginHeight = 0;
    parameterButtonCompLayout.marginWidth = 0;
    parameterButtonComp.setLayout(parameterButtonCompLayout);
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 2;
    parameterButtonComp.setLayoutData(gd);
    parameterButtonComp.setFont(font);
    addParameterButton = createButton(parameterButtonComp, new AddParameterAction(parametersViewer));
    removeParameterButton = createButton(parameterButtonComp, new RemoveParameterAction(parametersViewer));
    transformsBlock.getStylesheetViewer().addSelectionChangedListener(selectionListener);
    restoreColumnSettings();
}
Also used : Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) TableColumn(org.eclipse.swt.widgets.TableColumn) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute) Font(org.eclipse.swt.graphics.Font) AddParameterAction(org.eclipse.wst.xsl.internal.debug.ui.actions.AddParameterAction) KeyEvent(org.eclipse.swt.events.KeyEvent) Item(org.eclipse.swt.widgets.Item) GridLayout(org.eclipse.swt.layout.GridLayout) RemoveParameterAction(org.eclipse.wst.xsl.internal.debug.ui.actions.RemoveParameterAction) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 37 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project netxms by netxms.

the class AgentFileManager method enableInPlaceRename.

/**
 * Enable in-place renames
 */
private void enableInPlaceRename() {
    TreeViewerEditor.create(viewer, new ColumnViewerEditorActivationStrategy(viewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    }, ColumnViewerEditor.DEFAULT);
    viewer.setCellEditors(new CellEditor[] { new TextCellEditor(viewer.getTree()) });
    // $NON-NLS-1$
    viewer.setColumnProperties(new String[] { "name" });
    viewer.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            if (element instanceof Item)
                element = ((Item) element).getData();
            if (// $NON-NLS-1$
            property.equals("name")) {
                if (element instanceof AgentFile) {
                    doRename((AgentFile) element, value.toString());
                }
            }
        }

        @Override
        public Object getValue(Object element, String property) {
            if (// $NON-NLS-1$
            property.equals("name")) {
                if (element instanceof AgentFile) {
                    return ((AgentFile) element).getName();
                }
            }
            return null;
        }

        @Override
        public boolean canModify(Object element, String property) {
            // $NON-NLS-1$
            return property.equals("name");
        }
    });
}
Also used : Item(org.eclipse.swt.widgets.Item) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) AgentFile(org.netxms.client.server.AgentFile) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 38 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project tdq-studio-se by Talend.

the class UDIMasterPage method attachDefiniationParameterCellEditors.

/**
 * attach Definiation Parameter Cell Editors.
 *
 * @param table
 * @param titles
 */
private void attachDefiniationParameterCellEditors(Composite table, String[] titles) {
    parameterTableViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            return true;
        }

        public Object getValue(Object element, String property) {
            if (PARAMETERS_KEY.equals(property)) {
                return ((IndicatorDefinitionParameter) element).getKey();
            } else if (PARAMETERS_VALUE.equals(property)) {
                return ((IndicatorDefinitionParameter) element).getValue();
            }
            return null;
        }

        public void modify(Object element, String property, Object value) {
            TableItem tableItem = (TableItem) element;
            IndicatorDefinitionParameter data = (IndicatorDefinitionParameter) tableItem.getData();
            if (PARAMETERS_KEY.equals(property)) {
                if (!data.getKey().equals(value.toString())) {
                    data.setKey(value.toString());
                    parameterTableViewer.refresh(data);
                    setDirty(true);
                }
            } else if (PARAMETERS_VALUE.equals(property)) {
                if (!data.getValue().equals(value)) {
                    data.setValue((String) value);
                    parameterTableViewer.refresh(data);
                    setDirty(true);
                }
            }
        }
    });
    parameterTableViewer.setColumnProperties(titles);
    parameterTableViewer.setCellEditors(new CellEditor[] { new TextCellEditor(table), new TextCellEditor(table) });
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ICellModifier(org.eclipse.jface.viewers.ICellModifier) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 39 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project tdq-studio-se by Talend.

the class JavaUDIParametersForm method attachCellEditors.

/**
 * DOC klliu Comment method "attachCellEditors".figure 13429 2010-08-03.
 *
 * @param viewer
 * @param parent
 */
private void attachCellEditors(final TableViewer viewer, Composite parent) {
    viewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            return true;
        }

        public Object getValue(Object element, String property) {
            if (NAME_PROPERTY.equals(property)) {
                return ((JavaUDIIndicatorParameter) element).getKey();
            } else {
                return ((JavaUDIIndicatorParameter) element).getValue();
            }
        }

        public void modify(Object element, String property, Object value) {
            TableItem tableItem = (TableItem) element;
            JavaUDIIndicatorParameter data = (JavaUDIIndicatorParameter) tableItem.getData();
            if (NAME_PROPERTY.equals(property)) {
                data.setKey(value.toString());
            } else {
                data.setValue(value.toString());
            }
            viewer.refresh(data);
            checkFieldsValue();
        }
    });
    viewer.setCellEditors(new CellEditor[] { new TextCellEditor(parent), new TextCellEditor(parent) });
    viewer.setColumnProperties(new String[] { NAME_PROPERTY, VALUE_PROPERTY });
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ICellModifier(org.eclipse.jface.viewers.ICellModifier) JavaUDIIndicatorParameter(org.talend.dataquality.domain.JavaUDIIndicatorParameter) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 40 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier in project bndtools by bndtools.

the class NewTypeWizardPage method createSuperInterfacesControls.

/**
 * Creates the controls for the superclass name field. Expects a <code>GridLayout</code> with at least 3 columns.
 *
 * @param composite the parent composite
 * @param nColumns number of columns to span
 */
protected void createSuperInterfacesControls(Composite composite, int nColumns) {
    // $NON-NLS-1$
    final String INTERFACE = "interface";
    fSuperInterfacesDialogField.doFillIntoGrid(composite, nColumns);
    final TableViewer tableViewer = fSuperInterfacesDialogField.getTableViewer();
    tableViewer.setColumnProperties(new String[] { INTERFACE });
    TableTextCellEditor cellEditor = new TableTextCellEditor(tableViewer, 0) {

        @Override
        protected void doSetFocus() {
            if (text != null) {
                text.setFocus();
                text.setSelection(text.getText().length());
                checkSelection();
                checkDeleteable();
                checkSelectable();
            }
        }
    };
    JavaTypeCompletionProcessor superInterfaceCompletionProcessor = new JavaTypeCompletionProcessor(false, false, true);
    superInterfaceCompletionProcessor.setCompletionContextRequestor(new CompletionContextRequestor() {

        @Override
        public StubTypeContext getStubTypeContext() {
            return getSuperInterfacesStubTypeContext();
        }
    });
    @SuppressWarnings("deprecation") org.eclipse.jface.contentassist.SubjectControlContentAssistant contentAssistant = ControlContentAssistHelper.createJavaContentAssistant(superInterfaceCompletionProcessor);
    Text cellEditorText = cellEditor.getText();
    @SuppressWarnings({ "deprecation", "unused" }) org.eclipse.ui.contentassist.ContentAssistHandler contentAssistantHandler = org.eclipse.ui.contentassist.ContentAssistHandler.createHandlerForText(cellEditorText, contentAssistant);
    TextFieldNavigationHandler.install(cellEditorText);
    cellEditor.setContentAssistant(contentAssistant);
    tableViewer.setCellEditors(new CellEditor[] { cellEditor });
    tableViewer.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            Object el = element;
            if (el instanceof Item)
                el = ((Item) el).getData();
            ((InterfaceWrapper) el).interfaceName = (String) value;
            fSuperInterfacesDialogField.elementChanged((InterfaceWrapper) el);
        }

        @Override
        public Object getValue(Object element, String property) {
            return ((InterfaceWrapper) element).interfaceName;
        }

        @Override
        public boolean canModify(Object element, String property) {
            return true;
        }
    });
    tableViewer.getTable().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.F2 && event.stateMask == 0) {
                ISelection selection = tableViewer.getSelection();
                if (!(selection instanceof IStructuredSelection))
                    return;
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                tableViewer.editElement(structuredSelection.getFirstElement(), 0);
            }
        }
    });
    GridData gd = (GridData) fSuperInterfacesDialogField.getListControl(null).getLayoutData();
    if (fTypeKind == CLASS_TYPE) {
        gd.heightHint = convertHeightInCharsToPixels(3);
    } else {
        gd.heightHint = convertHeightInCharsToPixels(6);
    }
    gd.grabExcessVerticalSpace = false;
    gd.widthHint = getMaxFieldWidth();
}
Also used : KeyAdapter(org.eclipse.swt.events.KeyAdapter) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) JavaTypeCompletionProcessor(org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor) KeyEvent(org.eclipse.swt.events.KeyEvent) Item(org.eclipse.swt.widgets.Item) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ISelection(org.eclipse.jface.viewers.ISelection) GridData(org.eclipse.swt.layout.GridData) StubTypeContext(org.eclipse.jdt.internal.corext.refactoring.StubTypeContext) CompletionContextRequestor(org.eclipse.jdt.internal.ui.refactoring.contentassist.CompletionContextRequestor) TableViewer(org.eclipse.jface.viewers.TableViewer) TableTextCellEditor(org.eclipse.jdt.internal.ui.dialogs.TableTextCellEditor)

Aggregations

ICellModifier (org.eclipse.jface.viewers.ICellModifier)45 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)42 CellEditor (org.eclipse.jface.viewers.CellEditor)30 GridData (org.eclipse.swt.layout.GridData)29 Composite (org.eclipse.swt.widgets.Composite)26 TableItem (org.eclipse.swt.widgets.TableItem)26 GridLayout (org.eclipse.swt.layout.GridLayout)23 TableViewer (org.eclipse.jface.viewers.TableViewer)22 TableColumn (org.eclipse.swt.widgets.TableColumn)20 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)17 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)17 Item (org.eclipse.swt.widgets.Item)16 SelectionListener (org.eclipse.swt.events.SelectionListener)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)10 Button (org.eclipse.swt.widgets.Button)9 Label (org.eclipse.swt.widgets.Label)9 Table (org.eclipse.swt.widgets.Table)9