Search in sources :

Example 21 with VerifyEvent

use of org.eclipse.swt.events.VerifyEvent in project tesb-studio-se by Talend.

the class ServiceMetadataCustomPropertiesTable method createTableViewer.

private void createTableViewer() {
    tableViewer = new TableViewer(table);
    tableViewer.setUseHashlookup(true);
    tableViewer.setColumnProperties(columnNames);
    CellEditor[] editors = new CellEditor[columnNames.length];
    TextCellEditor textEditor = new TextCellEditor(table) {

        protected Object doGetValue() {
            Object value = super.doGetValue();
            return null == value || ((String) value).trim().isEmpty() ? COLUMN_PROPERTY_NAME_DEFAULT_VALUE : value;
        }
    };
    ((Text) textEditor.getControl()).setTextLimit(64);
    ((Text) textEditor.getControl()).addVerifyListener(new VerifyListener() {

        public void verifyText(VerifyEvent e) {
            //$NON-NLS-1$
            e.doit = !e.text.equals("\"");
        //              e.doit = !e.text.trim().isEmpty();
        }
    });
    editors[0] = textEditor;
    textEditor = new TextCellEditor(table);
    ((Text) textEditor.getControl()).setTextLimit(64);
    ((Text) textEditor.getControl()).addVerifyListener(new VerifyListener() {

        public void verifyText(VerifyEvent e) {
            //$NON-NLS-1$
            e.doit = !e.text.equals("\"");
        }
    });
    editors[1] = textEditor;
    tableViewer.setCellEditors(editors);
    tableViewer.setCellModifier(new PropertyCellModifier(this));
}
Also used : VerifyListener(org.eclipse.swt.events.VerifyListener) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Text(org.eclipse.swt.widgets.Text) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 22 with VerifyEvent

use of org.eclipse.swt.events.VerifyEvent in project eclipse.platform.swt by eclipse.

the class Tab method log.

/**
 * Logs an untyped event to the event console.
 */
void log(Event event) {
    int i = 0;
    while (i < EVENT_INFO.length) {
        if (EVENT_INFO[i].type == event.type)
            break;
        i++;
    }
    String toString = EVENT_INFO[i].name + " [" + event.type + "]: ";
    if (!untypedEvents) {
        switch(event.type) {
            case SWT.KeyDown:
            case SWT.KeyUp:
                toString += new KeyEvent(event).toString();
                break;
            case SWT.MouseDown:
            case SWT.MouseUp:
            case SWT.MouseMove:
            case SWT.MouseEnter:
            case SWT.MouseExit:
            case SWT.MouseDoubleClick:
            case SWT.MouseWheel:
            case SWT.MouseHover:
                toString += new MouseEvent(event).toString();
                break;
            case SWT.Paint:
                toString += new PaintEvent(event).toString();
                break;
            case SWT.Move:
            case SWT.Resize:
                toString += new ControlEvent(event).toString();
                break;
            case SWT.Dispose:
                toString += new DisposeEvent(event).toString();
                break;
            case SWT.Selection:
            case SWT.DefaultSelection:
                toString += new SelectionEvent(event).toString();
                break;
            case SWT.FocusIn:
            case SWT.FocusOut:
                toString += new FocusEvent(event).toString();
                break;
            case SWT.Expand:
            case SWT.Collapse:
                toString += new TreeEvent(event).toString();
                break;
            case SWT.Iconify:
            case SWT.Deiconify:
            case SWT.Close:
            case SWT.Activate:
            case SWT.Deactivate:
                toString += new ShellEvent(event).toString();
                break;
            case SWT.Show:
            case SWT.Hide:
                toString += (event.widget instanceof Menu) ? new MenuEvent(event).toString() : event.toString();
                break;
            case SWT.Modify:
                toString += new ModifyEvent(event).toString();
                break;
            case SWT.Verify:
                toString += new VerifyEvent(event).toString();
                break;
            case SWT.Help:
                toString += new HelpEvent(event).toString();
                break;
            case SWT.Arm:
                toString += new ArmEvent(event).toString();
                break;
            case SWT.Traverse:
                toString += new TraverseEvent(event).toString();
                break;
            case SWT.HardKeyDown:
            case SWT.HardKeyUp:
            case SWT.DragDetect:
            case SWT.MenuDetect:
            case SWT.SetData:
            default:
                toString += event.toString();
        }
    } else {
        toString += event.toString();
    }
    log(toString);
    /* Return values for event fields. */
    int mask = EVENT_INFO[i].setFields;
    if (!ignore && mask != 0) {
        Event setFieldsEvent = EVENT_INFO[i].event;
        if ((mask & DOIT) != 0)
            event.doit = setFieldsEvent.doit;
        if ((mask & DETAIL) != 0)
            event.detail = setFieldsEvent.detail;
        if ((mask & TEXT) != 0)
            event.text = setFieldsEvent.text;
        if ((mask & X) != 0)
            event.x = setFieldsEvent.x;
        if ((mask & Y) != 0)
            event.y = setFieldsEvent.y;
        if ((mask & WIDTH) != 0)
            event.width = setFieldsEvent.width;
        if ((mask & HEIGHT) != 0)
            event.height = setFieldsEvent.height;
        eventConsole.append(ControlExample.getResourceString("Returning"));
        ignore = true;
        log(event);
        ignore = false;
    }
}
Also used : HelpEvent(org.eclipse.swt.events.HelpEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ArmEvent(org.eclipse.swt.events.ArmEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) TypedEvent(org.eclipse.swt.events.TypedEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ArmEvent(org.eclipse.swt.events.ArmEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) TreeEvent(org.eclipse.swt.events.TreeEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) HelpEvent(org.eclipse.swt.events.HelpEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 23 with VerifyEvent

use of org.eclipse.swt.events.VerifyEvent in project eclipse.platform.text by eclipse.

the class AbstractControlContentAssistSubjectAdapter method installControlListener.

/**
 * Installs <code>fControlListener</code>, which handles VerifyEvents and KeyEvents by
 * passing them to {@link #fVerifyKeyListeners} and {@link #fKeyListeners}.
 */
private void installControlListener() {
    if (DEBUG)
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() -> k: " + fKeyListeners.size() + ", v: " + fVerifyKeyListeners.size());
    if (fControlListener != null)
        return;
    fControlListener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (!getControl().isFocusControl())
                // SWT.TRAVERSE_MNEMONIC events can also come in to inactive widgets
                return;
            VerifyEvent verifyEvent = new VerifyEvent(e);
            KeyEvent keyEvent = new KeyEvent(e);
            switch(e.type) {
                case SWT.Traverse:
                    if (DEBUG)
                        // $NON-NLS-1$
                        dump("before traverse", e, verifyEvent);
                    verifyEvent.doit = true;
                    for (VerifyKeyListener verifyKeyListener : fVerifyKeyListeners) {
                        verifyKeyListener.verifyKey(verifyEvent);
                        if (!verifyEvent.doit) {
                            e.detail = SWT.TRAVERSE_NONE;
                            e.doit = true;
                            if (DEBUG)
                                // $NON-NLS-1$
                                dump("traverse eaten by verify", e, verifyEvent);
                            return;
                        }
                        if (DEBUG)
                            // $NON-NLS-1$
                            dump("traverse OK", e, verifyEvent);
                    }
                    break;
                case SWT.KeyDown:
                    for (VerifyKeyListener verifyKeyListener : fVerifyKeyListeners) {
                        verifyKeyListener.verifyKey(verifyEvent);
                        if (!verifyEvent.doit) {
                            e.doit = verifyEvent.doit;
                            if (DEBUG)
                                // $NON-NLS-1$
                                dump("keyDown eaten by verify", e, verifyEvent);
                            return;
                        }
                    }
                    if (DEBUG)
                        // $NON-NLS-1$
                        dump("keyDown OK", e, verifyEvent);
                    for (KeyListener keyListener : fKeyListeners) {
                        keyListener.keyPressed(keyEvent);
                    }
                    break;
                default:
                    Assert.isTrue(false);
            }
        }

        /**
         * Dump the given events to "standard" output.
         *
         * @param who who dump's
         * @param e the event
         * @param ve the verify event
         */
        private void dump(String who, Event e, VerifyEvent ve) {
            // $NON-NLS-1$
            StringBuilder sb = new StringBuilder("--- [AbstractControlContentAssistSubjectAdapter]\n");
            sb.append(who);
            // $NON-NLS-1$
            sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode));
            // $NON-NLS-1$
            sb.append("; character=" + e.character + hex(e.character));
            // $NON-NLS-1$
            sb.append("; stateMask=" + e.stateMask + hex(e.stateMask));
            // $NON-NLS-1$
            sb.append("; doit=" + e.doit);
            // $NON-NLS-1$
            sb.append("; detail=" + e.detail + hex(e.detail));
            // $NON-NLS-1$
            sb.append("; widget=" + e.widget);
            // $NON-NLS-1$
            sb.append("\n");
            // $NON-NLS-1$
            sb.append("  verifyEvent keyCode=" + e.keyCode + hex(e.keyCode));
            // $NON-NLS-1$
            sb.append("; character=" + e.character + hex(e.character));
            // $NON-NLS-1$
            sb.append("; stateMask=" + e.stateMask + hex(e.stateMask));
            // $NON-NLS-1$
            sb.append("; doit=" + ve.doit);
            // $NON-NLS-1$
            sb.append("; widget=" + e.widget);
            System.out.println(sb);
        }

        private String hex(int i) {
            // $NON-NLS-1$
            return "[0x" + Integer.toHexString(i) + ']';
        }
    };
    getControl().addListener(SWT.Traverse, fControlListener);
    getControl().addListener(SWT.KeyDown, fControlListener);
    if (DEBUG)
        // $NON-NLS-1$
        System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() - installed");
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) DisposeListener(org.eclipse.swt.events.DisposeListener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) Listener(org.eclipse.swt.widgets.Listener) KeyListener(org.eclipse.swt.events.KeyListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) LabelProviderChangedEvent(org.eclipse.jface.viewers.LabelProviderChangedEvent) Event(org.eclipse.swt.widgets.Event) VerifyEvent(org.eclipse.swt.events.VerifyEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) KeyListener(org.eclipse.swt.events.KeyListener) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 24 with VerifyEvent

use of org.eclipse.swt.events.VerifyEvent in project eclipse.platform.text by eclipse.

the class ContextInformationPopup method createContextSelector.

/**
 * Creates the context selector in case the user has the choice between multiple valid contexts
 * at a given offset.
 */
private void createContextSelector() {
    if (Helper.okToUse(fContextSelectorShell))
        return;
    Control control = fContentAssistSubjectControlAdapter.getControl();
    fContextSelectorShell = new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    fContextSelectorShell.setLayout(layout);
    fContextSelectorShell.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    fContextSelectorShell.addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            fContextSelectorPopupSize = fContextSelectorShell.getSize();
        }
    });
    if (fViewer instanceof ITextViewerExtension) {
        final ITextViewerExtension textViewerExtension = (ITextViewerExtension) fViewer;
        final StyledText textWidget = fViewer.getTextWidget();
        final VerifyKeyListener verifyListener = new VerifyKeyListener() {

            @Override
            public void verifyKey(VerifyEvent event) {
                if (isActive() && event.keyCode == 13 && event.character == '\r' && event.widget == textWidget) {
                    event.doit = false;
                    insertSelectedContext();
                    hideContextSelector();
                }
            }
        };
        textViewerExtension.prependVerifyKeyListener(verifyListener);
        fContextSelectorShell.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                textViewerExtension.removeVerifyKeyListener(verifyListener);
            }
        });
    }
    fContextSelectorTable = new Table(fContextSelectorShell, SWT.H_SCROLL | SWT.V_SCROLL);
    fContextSelectorTable.setLocation(1, 1);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = fContextSelectorTable.getItemHeight() * 10;
    gd.widthHint = 300;
    fContextSelectorTable.setLayoutData(gd);
    Point size = fContentAssistant.restoreContextSelectorPopupSize();
    if (size != null)
        fContextSelectorShell.setSize(size);
    else
        fContextSelectorShell.pack(true);
    Color c = fContentAssistant.getContextSelectorBackground();
    if (c == null)
        c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
    fContextSelectorTable.setBackground(c);
    c = fContentAssistant.getContextSelectorForeground();
    if (c == null)
        c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
    fContextSelectorTable.setForeground(c);
    fContextSelectorTable.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            insertSelectedContext();
            hideContextSelector();
        }
    });
    fPopupCloser.install(fContentAssistant, fContextSelectorTable);
    fContextSelectorTable.setHeaderVisible(false);
    fContentAssistant.addToLayout(this, fContextSelectorShell, ContentAssistant.LayoutManager.LAYOUT_CONTEXT_SELECTOR, fContentAssistant.getSelectionOffset());
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) StyledText(org.eclipse.swt.custom.StyledText) Table(org.eclipse.swt.widgets.Table) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) Color(org.eclipse.swt.graphics.Color) Point(org.eclipse.swt.graphics.Point) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IContentAssistSubjectControl(org.eclipse.jface.contentassist.IContentAssistSubjectControl) Control(org.eclipse.swt.widgets.Control) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 25 with VerifyEvent

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

the class StyledTextEditor method createStyledText.

private Control createStyledText(final Composite parent) {
    m_styledText = new StyledText(parent, SWT.MULTI | SWT.WRAP | SWT.FULL_SELECTION);
    // by default we are a workflow annotation editor
    // can be changed by changing the default font (setDefaultFont(Font))
    m_styledText.setFont(AnnotationEditPart.getWorkflowAnnotationDefaultFont());
    m_styledText.setAlignment(SWT.LEFT);
    m_styledText.setText("");
    m_styledText.setTabs(TAB_SIZE);
    m_styledText.addVerifyKeyListener(new VerifyKeyListener() {

        @Override
        public void verifyKey(final VerifyEvent event) {
            if (event.character == SWT.CR && (event.stateMask & SWT.MOD1) != 0) {
                event.doit = false;
            }
        }
    });
    // forward some events to the cell editor
    m_styledText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(final KeyEvent e) {
            keyReleaseOccured(e);
        }
    });
    m_styledText.addFocusListener(new FocusAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void focusLost(final org.eclipse.swt.events.FocusEvent e) {
            // effect of an opening font editor, for instance)
            if (m_allowFocusLost.get()) {
                lostFocus();
            }
        }
    });
    m_styledText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            // super marks it dirty (otherwise no commit at the end)
            fireEditorValueChanged(true, true);
        }
    });
    m_styledText.addExtendedModifyListener(new ExtendedModifyListener() {

        @Override
        public void modifyText(final ExtendedModifyEvent event) {
            if (event.length > 0) {
                textInserted(event.start, event.length);
            }
        }
    });
    m_styledText.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            selectionChanged();
        }
    });
    m_styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    addMenu(m_styledText);
    // toolbar gets created first - enable its style buttons!
    selectionChanged();
    return m_styledText;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) StyledText(org.eclipse.swt.custom.StyledText) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) VerifyEvent(org.eclipse.swt.events.VerifyEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

VerifyEvent (org.eclipse.swt.events.VerifyEvent)25 VerifyListener (org.eclipse.swt.events.VerifyListener)15 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 ModifyEvent (org.eclipse.swt.events.ModifyEvent)10 Text (org.eclipse.swt.widgets.Text)10 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)9 KeyEvent (org.eclipse.swt.events.KeyEvent)9 ModifyListener (org.eclipse.swt.events.ModifyListener)9 GridData (org.eclipse.swt.layout.GridData)9 FocusEvent (org.eclipse.swt.events.FocusEvent)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 Composite (org.eclipse.swt.widgets.Composite)7 Point (org.eclipse.swt.graphics.Point)6 Button (org.eclipse.swt.widgets.Button)6 StyledText (org.eclipse.swt.custom.StyledText)5 FocusAdapter (org.eclipse.swt.events.FocusAdapter)5 Label (org.eclipse.swt.widgets.Label)5 ExtendedModifyEvent (org.eclipse.swt.custom.ExtendedModifyEvent)4 ExtendedModifyListener (org.eclipse.swt.custom.ExtendedModifyListener)4 ControlEvent (org.eclipse.swt.events.ControlEvent)4