Search in sources :

Example 1 with ExtendedModifyListener

use of org.eclipse.swt.custom.ExtendedModifyListener 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) {
            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 2 with ExtendedModifyListener

use of org.eclipse.swt.custom.ExtendedModifyListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_custom_StyledText method test_addExtendedModifyListenerLorg_eclipse_swt_custom_ExtendedModifyListener.

@Test
public void test_addExtendedModifyListenerLorg_eclipse_swt_custom_ExtendedModifyListener() {
    final String line = "Line1";
    boolean exceptionThrown = false;
    ExtendedModifyListener listener = event -> {
        listenerCalled = true;
        assertEquals("ExtendedModify event data invalid", 0, event.start);
        assertEquals("ExtendedModify event data invalid", line.length(), event.length);
        assertEquals("ExtendedModify event data invalid", "", event.replacedText);
    };
    try {
        text.addExtendedModifyListener(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue("Expected exception not thrown", exceptionThrown);
    // test whether all content modifying API methods send an ExtendedModify event
    text.addExtendedModifyListener(listener);
    listenerCalled = false;
    text.append(line);
    assertTrue("append does not send event", listenerCalled);
    listenerCalled = false;
    text.insert(line);
    assertTrue("replaceTextRange does not send event", listenerCalled);
    listenerCalled = false;
    text.removeExtendedModifyListener(listener);
    listener = event -> {
        listenerCalled = true;
        assertEquals("ExtendedModify event data invalid", 0, event.start);
        assertEquals("ExtendedModify event data invalid", line.length(), event.length);
        assertEquals("ExtendedModify event data invalid", line.substring(0, 1), event.replacedText);
    };
    text.addExtendedModifyListener(listener);
    text.replaceTextRange(0, 1, line);
    assertTrue("replaceTextRange does not send event", listenerCalled);
    listenerCalled = false;
    text.removeExtendedModifyListener(listener);
    listener = event -> {
        listenerCalled = true;
        assertEquals("ExtendedModify event data invalid", 0, event.start);
        assertEquals("ExtendedModify event data invalid", line.length(), event.length);
        assertEquals("ExtendedModify event data invalid", line + line.substring(1, line.length()) + line, event.replacedText);
    };
    text.addExtendedModifyListener(listener);
    text.setText(line);
    assertTrue("setText does not send event", listenerCalled);
    listenerCalled = false;
    text.removeExtendedModifyListener(listener);
    // cause StyledText to call the listener.
    text.setText(line);
    assertFalse("Listener not removed", listenerCalled);
}
Also used : Printer(org.eclipse.swt.printing.Printer) RTFTransfer(org.eclipse.swt.dnd.RTFTransfer) StyledTextContent(org.eclipse.swt.custom.StyledTextContent) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) StyledText(org.eclipse.swt.custom.StyledText) Rectangle(org.eclipse.swt.graphics.Rectangle) HashMap(java.util.HashMap) MovementEvent(org.eclipse.swt.custom.MovementEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) Event(org.eclipse.swt.widgets.Event) LineBackgroundListener(org.eclipse.swt.custom.LineBackgroundListener) VerifyListener(org.eclipse.swt.events.VerifyListener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Map(java.util.Map) TextTransfer(org.eclipse.swt.dnd.TextTransfer) After(org.junit.After) RGB(org.eclipse.swt.graphics.RGB) Assert.fail(org.junit.Assert.fail) BidiSegmentListener(org.eclipse.swt.custom.BidiSegmentListener) Font(org.eclipse.swt.graphics.Font) LineStyleListener(org.eclipse.swt.custom.LineStyleListener) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) Before(org.junit.Before) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Assert.assertNotNull(org.junit.Assert.assertNotNull) MovementListener(org.eclipse.swt.custom.MovementListener) Assert.assertTrue(org.junit.Assert.assertTrue) StyleRange(org.eclipse.swt.custom.StyleRange) Caret(org.eclipse.swt.widgets.Caret) Test(org.junit.Test) GlyphMetrics(org.eclipse.swt.graphics.GlyphMetrics) Display(org.eclipse.swt.widgets.Display) CaretListener(org.eclipse.swt.custom.CaretListener) Transfer(org.eclipse.swt.dnd.Transfer) Assert.assertNull(org.junit.Assert.assertNull) Color(org.eclipse.swt.graphics.Color) BidiUtil(org.eclipse.swt.internal.BidiUtil) Assert.assertFalse(org.junit.Assert.assertFalse) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) ST(org.eclipse.swt.custom.ST) FontData(org.eclipse.swt.graphics.FontData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Assert.assertEquals(org.junit.Assert.assertEquals) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) ExtendedModifyListener(org.eclipse.swt.custom.ExtendedModifyListener) Test(org.junit.Test)

Example 3 with ExtendedModifyListener

use of org.eclipse.swt.custom.ExtendedModifyListener 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 4 with ExtendedModifyListener

use of org.eclipse.swt.custom.ExtendedModifyListener 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 5 with ExtendedModifyListener

use of org.eclipse.swt.custom.ExtendedModifyListener 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

ExtendedModifyListener (org.eclipse.swt.custom.ExtendedModifyListener)7 ExtendedModifyEvent (org.eclipse.swt.custom.ExtendedModifyEvent)5 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)5 ModifyListener (org.eclipse.swt.events.ModifyListener)5 TextChangeListener (org.eclipse.swt.custom.TextChangeListener)4 KeyEvent (org.eclipse.swt.events.KeyEvent)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4 VerifyEvent (org.eclipse.swt.events.VerifyEvent)4 StyledText (org.eclipse.swt.custom.StyledText)3 TextChangedEvent (org.eclipse.swt.custom.TextChangedEvent)3 TextChangingEvent (org.eclipse.swt.custom.TextChangingEvent)3 ControlEvent (org.eclipse.swt.events.ControlEvent)3 ControlListener (org.eclipse.swt.events.ControlListener)3 FocusEvent (org.eclipse.swt.events.FocusEvent)3 FocusListener (org.eclipse.swt.events.FocusListener)3 KeyListener (org.eclipse.swt.events.KeyListener)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseListener (org.eclipse.swt.events.MouseListener)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 SelectionListener (org.eclipse.swt.events.SelectionListener)3