Search in sources :

Example 36 with CellEditor

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

the class TextEditManager 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);
                    }
                }
            }
            super.keyReleaseOccured(keyEvent);
        }
    };
    editor.getControl().moveAbove(null);
    return editor;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) IPVWidgetEditpart(org.csstudio.opibuilder.editparts.IPVWidgetEditpart) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 37 with CellEditor

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

the class MultiLineTextPropertyDescriptor method createPropertyEditor.

/**
 * {@inheritDoc}
 */
@Override
public CellEditor createPropertyEditor(final Composite parent) {
    final String title = NLS.bind("Edit {0}", getDisplayName());
    CellEditor editor = new MultiLineTextCellEditor(parent, title);
    if (getValidator() != null) {
        editor.setValidator(getValidator());
    }
    return editor;
}
Also used : MultiLineTextCellEditor(org.csstudio.opibuilder.visualparts.MultiLineTextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) MultiLineTextCellEditor(org.csstudio.opibuilder.visualparts.MultiLineTextCellEditor)

Example 38 with CellEditor

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

the class RuleDataEditDialog method createExpressionsTableViewer.

/**
 * Creates and configures a {@link TableViewer}.
 *
 * @param parent
 *            The parent for the table
 * @return The {@link TableViewer}
 */
private TableViewer createExpressionsTableViewer(final Composite parent) {
    final TableViewer viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    TableViewerColumn expressionColumn = new TableViewerColumn(viewer, SWT.NONE);
    expressionColumn.getColumn().setText("Boolean Expression");
    expressionColumn.getColumn().setMoveable(false);
    expressionColumn.getColumn().setWidth(200);
    expressionColumn.setEditingSupport(new EditingSupport(viewer) {

        @Override
        protected void setValue(Object element, Object value) {
            if (element instanceof Expression)
                ((Expression) element).setBooleanExpression(value.toString());
            viewer.refresh();
        }

        @Override
        protected Object getValue(Object element) {
            if (element instanceof Expression)
                return ((Expression) element).getBooleanExpression();
            return null;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new TextCellEditor(viewer.getTable());
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }
    });
    valueColumn = new TableViewerColumn(viewer, SWT.NONE);
    valueColumn.getColumn().setText(ruleData.isOutputExpValue() ? "Output Expression" : "Output Value");
    valueColumn.getColumn().setMoveable(false);
    valueColumn.getColumn().setWidth(200);
    EditingSupport editingSupport = new EditingSupport(viewer) {

        @Override
        protected void setValue(Object element, Object value) {
            if (element instanceof Expression) {
                ((Expression) element).setValue(value);
            }
            viewer.refresh();
        }

        @Override
        protected Object getValue(Object element) {
            if (element instanceof Expression) {
                if (((Expression) element).getValue() == null)
                    // $NON-NLS-1$
                    return "";
                return ((Expression) element).getValue();
            }
            return null;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            if (element instanceof Expression) {
                if (ruleData.isOutputExpValue() || ruleData.getProperty().getPropertyDescriptor() == null)
                    return new TextCellEditor(viewer.getTable());
                else
                    return ruleData.getProperty().getPropertyDescriptor().createPropertyEditor(viewer.getTable());
            }
            return null;
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }
    };
    valueColumn.setEditingSupport(editingSupport);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ExpressionLabelProvider());
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    viewer.getTable().setLayoutData(gd);
    return viewer;
}
Also used : Expression(org.csstudio.opibuilder.script.Expression) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) EditingSupport(org.eclipse.jface.viewers.EditingSupport) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 39 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project dbeaver by dbeaver.

the class UIUtils method createPropertyEditor.

public static CellEditor createPropertyEditor(final IServiceLocator serviceLocator, Composite parent, DBPPropertySource source, DBPPropertyDescriptor property, int style) {
    if (source == null) {
        return null;
    }
    final Object object = source.getEditableValue();
    if (!property.isEditable(object)) {
        return null;
    }
    CellEditor cellEditor = UIUtils.createCellEditor(parent, object, property, style);
    if (cellEditor != null) {
        final Control editorControl = cellEditor.getControl();
        addDefaultEditActionsSupport(serviceLocator, editorControl);
    }
    return cellEditor;
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Example 40 with CellEditor

use of org.eclipse.jface.viewers.CellEditor in project erlide_eclipse by erlang.

the class ControlPanelView method createProcessesTable.

private Composite createProcessesTable(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout());
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    final int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
    final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.grabExcessVerticalSpace = true;
    processesTableViewer = new TableViewer(container, style);
    processesTableViewer.setUseHashlookup(true);
    // table
    final Table table = processesTableViewer.getTable();
    table.setLayoutData(gridData);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    // columns
    final String[] columnProperties = new String[ProcessColumn.values().length + ProcessFlag.values().length];
    // columns: process properties
    for (final ProcessColumn column : ProcessColumn.values()) {
        final TableColumn tableColumn = new TableColumn(table, SWT.LEFT, column.ordinal());
        tableColumn.setResizable(true);
        tableColumn.setMoveable(false);
        tableColumn.setWidth(column.getWidth());
        tableColumn.setText(column.getName());
        columnProperties[column.ordinal()] = column.name();
    }
    // columns: process flags
    for (final ProcessFlag flag : ProcessFlag.values()) {
        final TableColumn tableColumn = new TableColumn(table, SWT.CENTER, ProcessColumn.values().length + flag.ordinal());
        tableColumn.setResizable(true);
        tableColumn.setMoveable(false);
        tableColumn.setWidth(60);
        tableColumn.setText(flag.getName());
        columnProperties[ProcessColumn.values().length + flag.ordinal()] = flag.name();
    }
    processesTableViewer.setColumnProperties(columnProperties);
    // providers
    processesTableViewer.setLabelProvider(new ProcessLabelProvider());
    processesTableViewer.setContentProvider(new ProcessContentProvider());
    // input
    fillProcessesList(processesTableViewer);
    processesTableViewer.setInput(TraceBackend.getInstance().getProcesses());
    // editors
    final CellEditor[] editors = new CellEditor[ProcessFlag.values().length + ProcessFlag.values().length];
    editors[ProcessColumn.SELECTED.ordinal()] = new CheckboxCellEditor(table);
    for (final ProcessFlag flag : ProcessFlag.values()) {
        editors[ProcessColumn.values().length + flag.ordinal()] = new CheckboxCellEditor(table);
    }
    processesTableViewer.setCellEditors(editors);
    processesTableViewer.setCellModifier(new ProcessCellModifier(processesTableViewer));
    return container;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) MatchSpecCellEditor(org.erlide.tracing.core.mvc.view.MatchSpecCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ProcessLabelProvider(org.erlide.tracing.core.mvc.view.ProcessLabelProvider) TableColumn(org.eclipse.swt.widgets.TableColumn) ProcessFlag(org.erlide.tracing.core.ProcessFlag) ProcessColumn(org.erlide.tracing.core.mvc.view.ProcessColumn) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ProcessCellModifier(org.erlide.tracing.core.mvc.controller.ProcessCellModifier) ProcessContentProvider(org.erlide.tracing.core.mvc.view.ProcessContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

CellEditor (org.eclipse.jface.viewers.CellEditor)142 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)88 TableViewer (org.eclipse.jface.viewers.TableViewer)45 GridData (org.eclipse.swt.layout.GridData)44 Composite (org.eclipse.swt.widgets.Composite)37 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)35 ICellModifier (org.eclipse.jface.viewers.ICellModifier)32 GridLayout (org.eclipse.swt.layout.GridLayout)30 SelectionEvent (org.eclipse.swt.events.SelectionEvent)29 TableColumn (org.eclipse.swt.widgets.TableColumn)29 CheckboxCellEditor (org.eclipse.jface.viewers.CheckboxCellEditor)25 Table (org.eclipse.swt.widgets.Table)24 Button (org.eclipse.swt.widgets.Button)23 ArrayList (java.util.ArrayList)21 Label (org.eclipse.swt.widgets.Label)21 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)20 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)20 Text (org.eclipse.swt.widgets.Text)19 Map (java.util.Map)18 EditingSupport (org.eclipse.jface.viewers.EditingSupport)18