Search in sources :

Example 71 with CellEditor

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

the class SpinnerTextEditManager 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);
                    }
                }
            }
            if (keyEvent.keyCode == SWT.ARROW_UP) {
                doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) + step_increment));
                CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
                stack.execute(getEditPart().getCommand(getDirectEditRequest()));
            }
            if (keyEvent.keyCode == SWT.ARROW_DOWN) {
                doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) - step_increment));
                CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
                stack.execute(getEditPart().getCommand(getDirectEditRequest()));
            }
            if (keyEvent.keyCode == SWT.PAGE_UP) {
                doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) + page_increment));
                CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
                stack.execute(getEditPart().getCommand(getDirectEditRequest()));
            }
            if (keyEvent.keyCode == SWT.PAGE_DOWN) {
                doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) - page_increment));
                CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
                stack.execute(getEditPart().getCommand(getDirectEditRequest()));
            }
            super.keyReleaseOccured(keyEvent);
        }
    };
    editor.getControl().moveAbove(null);
    return editor;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) IPVWidgetEditpart(org.csstudio.opibuilder.editparts.IPVWidgetEditpart) CommandStack(org.eclipse.gef.commands.CommandStack) 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 72 with CellEditor

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

the class PVWidgetSelectionHandle method createDragTracker.

@Override
protected DragTracker createDragTracker() {
    DragEditPartsTracker tracker = new DragEditPartsTracker(getOwner()) {

        @Override
        protected boolean handleButtonDown(int button) {
            if ((button == 1 || button == 3) && widgetModel instanceof IPVWidgetModel) {
                DirectEditManager directEditManager = new PVNameDirectEditManager(getOwner(), new CellEditorLocator() {

                    @Override
                    public void relocate(CellEditor celleditor) {
                        Rectangle rect;
                        int width = 120;
                        if (!pvName.isEmpty() && getTextExtent().width > 120)
                            width = getTextExtent().width + 4;
                        rect = new Rectangle(PVWidgetSelectionHandle.this.getLocation(), new Dimension(width, getTextExtent().height));
                        translateToAbsolute(rect);
                        Text control = (Text) celleditor.getControl();
                        org.eclipse.swt.graphics.Rectangle trim = control.computeTrim(0, 0, 0, 0);
                        rect.translate(trim.x, trim.y);
                        rect.width += trim.width;
                        rect.height += trim.height;
                        control.setBounds(rect.x, rect.y, rect.width, rect.height);
                    }
                });
                directEditManager.show();
            }
            return true;
        }
    };
    tracker.setDefaultCursor(getCursor());
    return tracker;
}
Also used : CellEditorLocator(org.eclipse.gef.tools.CellEditorLocator) IPVWidgetModel(org.csstudio.opibuilder.model.IPVWidgetModel) CellEditor(org.eclipse.jface.viewers.CellEditor) PVNameTextCellEditor(org.csstudio.opibuilder.visualparts.PVNameTextCellEditor) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DirectEditManager(org.eclipse.gef.tools.DirectEditManager) Text(org.eclipse.swt.widgets.Text) Dimension(org.eclipse.draw2d.geometry.Dimension) DragEditPartsTracker(org.eclipse.gef.tools.DragEditPartsTracker)

Aggregations

CellEditor (org.eclipse.jface.viewers.CellEditor)72 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)47 ICellModifier (org.eclipse.jface.viewers.ICellModifier)21 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 GridData (org.eclipse.swt.layout.GridData)21 Composite (org.eclipse.swt.widgets.Composite)19 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Map (java.util.Map)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 HashMap (java.util.HashMap)14 TableViewer (org.eclipse.jface.viewers.TableViewer)14 Label (org.eclipse.swt.widgets.Label)14 Item (org.eclipse.swt.widgets.Item)12 Button (org.eclipse.swt.widgets.Button)11 TableItem (org.eclipse.swt.widgets.TableItem)11 Text (org.eclipse.swt.widgets.Text)9 ArrayList (java.util.ArrayList)8 SelectionListener (org.eclipse.swt.events.SelectionListener)8 Group (org.eclipse.swt.widgets.Group)8