Search in sources :

Example 36 with VerifyEvent

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

the class StyledTextHandler method addListeners.

/**
     * DOC amaumont Comment method "addListeners".
     */
private void addListeners() {
    styledText.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            refreshProposalSize();
        }

        public void focusLost(FocusEvent e) {
        }
    });
    styledText.addControlListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        }

        public void controlResized(ControlEvent e) {
            refreshProposalSize();
        }
    });
    styledText.addExtendedModifyListener(new ExtendedModifyListener() {

        public void modifyText(ExtendedModifyEvent event) {
            updateCellExpression();
        // System.out.println("ExtendedModifyListener modify text");
        }
    });
    styledText.getContent().addTextChangeListener(new TextChangeListener() {

        public void textChanged(TextChangedEvent event) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void textChanging(TextChangingEvent event) {
        // System.out.println("textChanging");
        }

        public void textSet(TextChangedEvent event) {
        // System.out.println("textSet");
        }
    });
    styledText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }
    });
    styledText.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void keyReleased(KeyEvent e) {
        // TODO Auto-generated method stub
        }
    });
    styledText.addVerifyKeyListener(new VerifyKeyListener() {

        public void verifyKey(VerifyEvent verifyEvent) {
            if (verifyEvent.character == '\r' && contentProposalAdapter != null && contentProposalAdapter.isProposalOpened()) {
                verifyEvent.doit = false;
            } else {
                verifyEvent.doit = true;
            }
        }
    });
    styledText.addMouseListener(new MouseListener() {

        public void mouseDoubleClick(MouseEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void mouseDown(MouseEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void mouseUp(MouseEvent e) {
        }
    });
}
Also used : ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) TextChangingEvent(org.eclipse.swt.custom.TextChangingEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) MouseListener(org.eclipse.swt.events.MouseListener) ControlListener(org.eclipse.swt.events.ControlListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) KeyListener(org.eclipse.swt.events.KeyListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) FocusListener(org.eclipse.swt.events.FocusListener) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 37 with VerifyEvent

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

the class StyledTextHandler method addListeners.

/**
     * DOC amaumont Comment method "addListeners".
     */
private void addListeners() {
    styledText.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            refreshProposalSize();
        }

        public void focusLost(FocusEvent e) {
        }
    });
    styledText.addControlListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        }

        public void controlResized(ControlEvent e) {
            refreshProposalSize();
        }
    });
    styledText.addExtendedModifyListener(new ExtendedModifyListener() {

        public void modifyText(ExtendedModifyEvent event) {
            // System.out.println("ExtendedModifyListener modify text");
            updateCellExpression();
        }
    });
    styledText.getContent().addTextChangeListener(new TextChangeListener() {

        public void textChanged(TextChangedEvent event) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void textChanging(TextChangingEvent event) {
        // System.out.println("textChanging");
        }

        public void textSet(TextChangedEvent event) {
        // System.out.println("textSet");
        }
    });
    styledText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }
    });
    styledText.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void keyReleased(KeyEvent e) {
        // TODO Auto-generated method stub
        }
    });
    styledText.addVerifyKeyListener(new VerifyKeyListener() {

        public void verifyKey(VerifyEvent verifyEvent) {
            if (verifyEvent.character == '\r' && contentProposalAdapter != null && contentProposalAdapter.isProposalOpened()) {
                verifyEvent.doit = false;
            } else {
                verifyEvent.doit = true;
            }
        }
    });
    styledText.addMouseListener(new MouseListener() {

        public void mouseDoubleClick(MouseEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void mouseDown(MouseEvent e) {
            mapperManager.fireCurrentDirectEditApply();
            highlightLineOfCursorPosition(styledText.getSelection());
        }

        public void mouseUp(MouseEvent e) {
        }
    });
}
Also used : ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) TextChangingEvent(org.eclipse.swt.custom.TextChangingEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ExtendedModifyEvent(org.eclipse.swt.custom.ExtendedModifyEvent) MouseListener(org.eclipse.swt.events.MouseListener) ControlListener(org.eclipse.swt.events.ControlListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) KeyListener(org.eclipse.swt.events.KeyListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) FocusListener(org.eclipse.swt.events.FocusListener) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 38 with VerifyEvent

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

the class SQLBuilderEditorComposite method createEditorArea.

/**
     * Creates UI for editor.
     * 
     * @param parent
     */
private void createEditorArea(Composite parent) {
    // create divider line
    Composite div1 = new Composite(parent, SWT.NONE);
    GridData lgid = new GridData();
    lgid.grabExcessHorizontalSpace = true;
    lgid.horizontalAlignment = GridData.FILL;
    lgid.heightHint = 1;
    lgid.verticalIndent = 1;
    div1.setLayoutData(lgid);
    div1.setBackground(parent.getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
    // create text viewer
    GridData gid = new GridData();
    gid.grabExcessHorizontalSpace = true;
    gid.grabExcessVerticalSpace = true;
    gid.horizontalAlignment = GridData.FILL;
    gid.verticalAlignment = GridData.FILL;
    colorText = new ColorStyledText(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, CorePlugin.getDefault().getPreferenceStore(), language);
    IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
    String fontType = preferenceStore.getString(TalendDesignerPrefConstants.MEMO_TEXT_FONT);
    FontData fontData = new FontData(fontType);
    Font font = new Font(null, fontData);
    addResourceDisposeListener(colorText, font);
    colorText.setFont(font);
    GridData gd = new GridData(GridData.FILL_BOTH);
    colorText.setLayoutData(gd);
    colorText.setText(this.connParam.getQuery());
    colorText.addVerifyKeyListener(new VerifyKeyListener() {

        @Override
        public void verifyKey(VerifyEvent event) {
            if (event.stateMask == SWT.CTRL && event.keyCode == 13) {
                event.doit = false;
                execSQLAction.run();
            }
        }
    });
    colorText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            isModified = true;
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) FontData(org.eclipse.swt.graphics.FontData) GridData(org.eclipse.swt.layout.GridData) ColorStyledText(org.talend.commons.ui.swt.colorstyledtext.ColorStyledText) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) VerifyEvent(org.eclipse.swt.events.VerifyEvent) Font(org.eclipse.swt.graphics.Font)

Example 39 with VerifyEvent

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

the class ExtendedDirectEditManager method initCellEditor.

/**
 * @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
 */
@Override
protected void initCellEditor() {
    Text text = (Text) getCellEditor().getControl();
    // add the verifyListener to apply changes to the control size
    verifyListener = new VerifyListener() {

        /**
         * Changes the size of the editor control to reflect the changed
         * text
         */
        @Override
        public void verifyText(VerifyEvent event) {
            Text text = (Text) getCellEditor().getControl();
            String oldText = text.getText();
            String leftText = oldText.substring(0, event.start);
            String rightText = oldText.substring(event.end, oldText.length());
            GC gc = new GC(text);
            if (leftText == null)
                leftText = "";
            if (rightText == null)
                rightText = "";
            String s = leftText + event.text + rightText;
            Point size = gc.textExtent(leftText + event.text + rightText);
            gc.dispose();
            if (size.x != 0)
                size = text.computeSize(size.x, SWT.DEFAULT);
            else {
                // just make it square
                size.x = size.y;
            }
            getCellEditor().getControl().setSize(size.x, size.y);
        }
    };
    text.addVerifyListener(verifyListener);
    // set the initial value of the
    originalValue = this.label.getText();
    getCellEditor().setValue(originalValue);
    // calculate the font size of the underlying
    IFigure figure = getEditPart().getFigure();
    figureFont = figure.getFont();
    FontData data = figureFont.getFontData()[0];
    Dimension fontSize = new Dimension(0, data.getHeight());
    // set the font to be used
    this.label.translateToAbsolute(fontSize);
    data.setHeight(fontSize.height);
    figureFont = new Font(null, data);
    // set the validator for the CellEditor
    getCellEditor().setValidator(validator);
    text.setFont(figureFont);
    text.selectAll();
}
Also used : VerifyListener(org.eclipse.swt.events.VerifyListener) FontData(org.eclipse.swt.graphics.FontData) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) GC(org.eclipse.swt.graphics.GC) VerifyEvent(org.eclipse.swt.events.VerifyEvent) Font(org.eclipse.swt.graphics.Font) IFigure(org.eclipse.draw2d.IFigure)

Example 40 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)

Aggregations

VerifyEvent (org.eclipse.swt.events.VerifyEvent)57 VerifyListener (org.eclipse.swt.events.VerifyListener)41 Text (org.eclipse.swt.widgets.Text)29 GridData (org.eclipse.swt.layout.GridData)21 ModifyEvent (org.eclipse.swt.events.ModifyEvent)19 ModifyListener (org.eclipse.swt.events.ModifyListener)18 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 Composite (org.eclipse.swt.widgets.Composite)18 Label (org.eclipse.swt.widgets.Label)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)14 Point (org.eclipse.swt.graphics.Point)14 KeyEvent (org.eclipse.swt.events.KeyEvent)12 Button (org.eclipse.swt.widgets.Button)11 FocusEvent (org.eclipse.swt.events.FocusEvent)10 StyledText (org.eclipse.swt.custom.StyledText)7 MouseEvent (org.eclipse.swt.events.MouseEvent)7 Font (org.eclipse.swt.graphics.Font)7 Pattern (java.util.regex.Pattern)6