Search in sources :

Example 66 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project knime-core by knime.

the class MetaPortDialog method createControl.

private void createControl(final Shell parent) {
    Composite composite = new Composite(parent, SWT.BORDER);
    composite.setLayout(new GridLayout(2, false));
    m_error = new Label(composite, SWT.NONE);
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
    gridData.horizontalSpan = 2;
    m_error.setLayoutData(gridData);
    m_typeLabel = new Label(composite, SWT.NONE);
    m_typeLabel.setText("Port Type:");
    m_type = new Combo(composite, SWT.DROP_DOWN | SWT.SIMPLE | SWT.READ_ONLY | SWT.BORDER);
    String[] names = new String[PORT_TYPES.size()];
    int i = 0;
    for (PortType pt : PORT_TYPES) {
        names[i++] = pt.getName();
    }
    m_type.setItems(names);
    m_type.select(0);
    m_type.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            resetError();
        }
    });
    Button ok = new Button(composite, SWT.PUSH);
    ok.setText("OK");
    ok.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (m_type.getSelectionIndex() < 0) {
                setError("Please select port type");
                return;
            }
            resetError();
            String selected = m_type.getItem(m_type.getSelectionIndex());
            Optional<PortType> pt = PORT_TYPES.stream().filter(p -> p.getName().equals(selected)).findFirst();
            m_port = pt.orElseThrow(() -> new IllegalStateException("Unknown port type: " + selected));
            m_shell.dispose();
        }
    });
    gridData = new GridData();
    gridData.widthHint = 80;
    ok.setLayoutData(gridData);
    Button cancel = new Button(composite, SWT.PUSH);
    cancel.setText("Cancel");
    cancel.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            m_port = null;
            m_shell.dispose();
        }
    });
    gridData = new GridData();
    gridData.widthHint = 80;
    cancel.setLayoutData(gridData);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Composite(org.eclipse.swt.widgets.Composite) Optional(java.util.Optional) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PortType(org.knime.core.node.port.PortType) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 67 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project yamcs-studio by yamcs.

the class NativeTextEditpart method doCreateFigure.

@Override
protected IFigure doCreateFigure() {
    initFields();
    int style = SWT.NONE;
    NativeTextModel model = getWidgetModel();
    if (model.isShowNativeBorder())
        style |= SWT.BORDER;
    if (model.isMultilineInput()) {
        style |= SWT.MULTI;
        if (model.isShowHScroll())
            style |= SWT.H_SCROLL;
        if (model.isShowVScroll())
            style |= SWT.V_SCROLL;
        if (model.isWrapWords())
            style |= SWT.WRAP;
    } else {
        style |= SWT.SINGLE;
        if (model.isPasswordInput())
            style |= SWT.PASSWORD;
    }
    if (model.isReadOnly())
        style |= SWT.READ_ONLY;
    switch(model.getHorizontalAlignment()) {
        case CENTER:
            style |= SWT.CENTER;
            break;
        case LEFT:
            style |= SWT.LEFT;
            break;
        case RIGHT:
            style |= SWT.RIGHT;
        default:
            break;
    }
    final NativeTextFigure figure = new NativeTextFigure(this, style);
    text = figure.getSWTWidget();
    if (!model.isReadOnly()) {
        if (model.isMultilineInput()) {
            text.addKeyListener(new KeyAdapter() {

                @Override
                public void keyPressed(KeyEvent keyEvent) {
                    if (keyEvent.character == '\r') {
                        // Return key
                        if (text != null && !text.isDisposed() && (text.getStyle() & SWT.MULTI) != 0) {
                            if ((keyEvent.stateMask & SWT.CTRL) != 0) {
                                outputText(text.getText());
                                keyEvent.doit = false;
                                text.getShell().setFocus();
                            }
                        }
                    }
                }
            });
        } else {
            text.addListener(SWT.DefaultSelection, new Listener() {

                @Override
                public void handleEvent(Event e) {
                    outputText(text.getText());
                    switch(getWidgetModel().getFocusTraverse()) {
                        case LOSE:
                            text.getShell().setFocus();
                            break;
                        case NEXT:
                            SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_PREVIOUS);
                            break;
                        case PREVIOUS:
                            SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_NEXT);
                            break;
                        case KEEP:
                        default:
                            break;
                    }
                }
            });
        }
        // Recover text if editing aborted.
        text.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent keyEvent) {
                if (keyEvent.character == SWT.ESC) {
                    text.setText(getWidgetModel().getText());
                }
            }
        });
        text.addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent e) {
                if (getPV() != null)
                    text.setText(getWidgetModel().getText());
                else if (figure.isEnabled())
                    outputText(text.getText());
            }
        });
    }
    getPVWidgetEditpartDelegate().setUpdateSuppressTime(-1);
    updatePropSheet();
    return figure;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) PropertyChangeListener(java.beans.PropertyChangeListener) Listener(org.eclipse.swt.widgets.Listener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) NativeTextModel(org.csstudio.opibuilder.widgets.model.NativeTextModel) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) NativeTextFigure(org.csstudio.opibuilder.widgets.figures.NativeTextFigure) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 68 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project yamcs-studio by yamcs.

the class NativeTextEditpartDelegate method doCreateFigure.

@Override
public IFigure doCreateFigure() {
    int style = SWT.NONE;
    if (model.isShowNativeBorder())
        style |= SWT.BORDER;
    if (model.isMultilineInput()) {
        style |= SWT.MULTI;
        if (model.isShowHScroll())
            style |= SWT.H_SCROLL;
        if (model.isShowVScroll())
            style |= SWT.V_SCROLL;
        if (model.isWrapWords())
            style |= SWT.WRAP;
    } else {
        style |= SWT.SINGLE;
        if (model.isPasswordInput())
            style |= SWT.PASSWORD;
    }
    if (model.isReadOnly())
        style |= SWT.READ_ONLY;
    switch(model.getHorizontalAlignment()) {
        case CENTER:
            style |= SWT.CENTER;
            break;
        case LEFT:
            style |= SWT.LEFT;
            break;
        case RIGHT:
            style |= SWT.RIGHT;
        default:
            break;
    }
    final NativeTextFigure figure = new NativeTextFigure(editpart, style);
    text = figure.getSWTWidget();
    if (!model.isReadOnly()) {
        if (model.isMultilineInput()) {
            text.addKeyListener(new KeyAdapter() {

                @Override
                public void keyPressed(KeyEvent keyEvent) {
                    if (keyEvent.character == '\r') {
                        // Return key
                        if (text != null && !text.isDisposed() && (text.getStyle() & SWT.MULTI) != 0) {
                            if ((keyEvent.stateMask & SWT.CTRL) != 0) {
                                outputText(text.getText());
                                keyEvent.doit = false;
                                text.getShell().setFocus();
                            }
                        }
                    }
                }
            });
        } else {
            text.addListener(SWT.DefaultSelection, new Listener() {

                @Override
                public void handleEvent(Event e) {
                    outputText(text.getText());
                    switch(model.getFocusTraverse()) {
                        case LOSE:
                            text.getShell().setFocus();
                            break;
                        case NEXT:
                            SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_PREVIOUS);
                            break;
                        case PREVIOUS:
                            SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_NEXT);
                            break;
                        case KEEP:
                        default:
                            break;
                    }
                }
            });
            text.addTraverseListener(e -> {
                // if key code is not tab, ignore
                if (e.character != '\t' || skipTraverse)
                    return;
                e.doit = false;
                skipTraverse = true;
                if (e.stateMask == 0) {
                    SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_PREVIOUS);
                } else {
                    SingleSourceHelper.swtControlTraverse(text, SWT.TRAVERSE_TAB_NEXT);
                }
                skipTraverse = false;
            });
        }
        // Recover text if editing aborted.
        text.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent keyEvent) {
                if (keyEvent.character == SWT.ESC) {
                    text.setText(model.getText());
                }
            }
        });
        text.addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent e) {
                if (editpart.getPV() != null)
                    text.setText(model.getText());
                else if (figure.isEnabled())
                    outputText(text.getText());
            }
        });
    }
    return figure;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) PropertyChangeListener(java.beans.PropertyChangeListener) Listener(org.eclipse.swt.widgets.Listener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) NativeTextFigure(org.csstudio.opibuilder.widgets.figures.NativeTextFigure) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

FocusAdapter (org.eclipse.swt.events.FocusAdapter)68 FocusEvent (org.eclipse.swt.events.FocusEvent)64 SelectionEvent (org.eclipse.swt.events.SelectionEvent)42 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)36 Composite (org.eclipse.swt.widgets.Composite)29 GridData (org.eclipse.swt.layout.GridData)28 Text (org.eclipse.swt.widgets.Text)26 GridLayout (org.eclipse.swt.layout.GridLayout)25 Label (org.eclipse.swt.widgets.Label)20 Button (org.eclipse.swt.widgets.Button)17 Menu (org.eclipse.swt.widgets.Menu)17 Point (org.eclipse.swt.graphics.Point)16 MenuManager (org.eclipse.jface.action.MenuManager)15 MenuItem (org.eclipse.swt.widgets.MenuItem)15 ModifyEvent (org.eclipse.swt.events.ModifyEvent)14 ModifyListener (org.eclipse.swt.events.ModifyListener)14 KeyEvent (org.eclipse.swt.events.KeyEvent)12 Combo (org.eclipse.swt.widgets.Combo)12 KeyAdapter (org.eclipse.swt.events.KeyAdapter)11 Group (org.eclipse.swt.widgets.Group)11