Search in sources :

Example 6 with TextChangingEvent

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

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

use of org.eclipse.swt.custom.TextChangingEvent in project eclipse.platform.text by eclipse.

the class DefaultDocumentAdapter method fireTextChanging.

/**
 * Sends the text changing event to all registered listeners.
 */
private void fireTextChanging() {
    if (!fIsForwarding)
        return;
    try {
        IDocument document = fEvent.getDocument();
        if (document == null)
            return;
        TextChangingEvent event = new TextChangingEvent(this);
        event.start = fEvent.fOffset;
        event.replaceCharCount = fEvent.fLength;
        event.replaceLineCount = document.getNumberOfLines(fEvent.fOffset, fEvent.fLength) - 1;
        event.newText = fEvent.fText;
        event.newCharCount = (fEvent.fText == null ? 0 : fEvent.fText.length());
        event.newLineCount = (fEvent.fText == null ? 0 : document.computeNumberOfLines(fEvent.fText));
        if (fTextChangeListeners != null && fTextChangeListeners.size() > 0) {
            Iterator<TextChangeListener> e = new ArrayList<>(fTextChangeListeners).iterator();
            while (e.hasNext()) e.next().textChanging(event);
        }
    } catch (BadLocationException e) {
    }
}
Also used : TextChangingEvent(org.eclipse.swt.custom.TextChangingEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener)

Example 9 with TextChangingEvent

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

the class Test_org_eclipse_swt_custom_TextChangeListener method test_textChangedLorg_eclipse_swt_custom_TextChangedEvent.

@Test
public void test_textChangedLorg_eclipse_swt_custom_TextChangedEvent() {
    StyledTextContent content = styledText.getContent();
    TextChangeListener listener = new TextChangeListener() {

        @Override
        public void textChanged(TextChangedEvent event) {
            switch(verify) {
                case 1:
                    {
                        assertTrue(":1:", styledText.getText().equals("\ntesting"));
                        break;
                    }
                case 2:
                    {
                        assertTrue(":2:", styledText.getText().equals("a"));
                        break;
                    }
                case 3:
                    {
                        assertTrue(":3:", styledText.getText().equals("\n\n"));
                        break;
                    }
                case 4:
                    {
                        assertTrue(":4:", false);
                        break;
                    }
                case 5:
                    {
                        assertTrue(":5:", styledText.getText().equals("\rLine 1\r\nLine 2"));
                        break;
                    }
                case 6:
                    {
                        assertTrue(":6:", styledText.getText().equals("This\nis a test\nline 3"));
                        break;
                    }
                case 7:
                    {
                        assertTrue(":7:", styledText.getText().equals("This\n\r"));
                        break;
                    }
                case 8:
                    {
                        assertTrue(":8:", styledText.getText().equals("\nL1\r\nL2"));
                        break;
                    }
                case 9:
                    {
                        assertTrue(":9:", styledText.getText().equals("L1test"));
                        break;
                    }
                case 10:
                    {
                        assertTrue(":10:", false);
                        break;
                    }
                case 11:
                    {
                        assertTrue(":11:", false);
                        break;
                    }
                case 12:
                    {
                        assertTrue(":12:", styledText.getText().equals("L1\r\n"));
                        break;
                    }
                case 13:
                    {
                        assertTrue(":13:", styledText.getText().equals("L1\r\n"));
                        break;
                    }
                case 14:
                    {
                        assertTrue(":14:", false);
                        break;
                    }
                case 15:
                    {
                        assertTrue(":15:", styledText.getText().equals("L1test\n\n"));
                        break;
                    }
                case 16:
                    {
                        assertTrue(":16:", false);
                        break;
                    }
                case 17:
                    {
                        assertTrue(":17:", false);
                        break;
                    }
                case 18:
                    {
                        assertTrue(":18:", styledText.getText().equals("L1\r\ntest\r\n"));
                        break;
                    }
                case 19:
                    {
                        assertTrue(":19:", styledText.getText().equals("L1test\r\r\r\n"));
                        break;
                    }
                case 20:
                    {
                        assertTrue(":20:", false);
                        break;
                    }
            }
        }

        @Override
        public void textChanging(TextChangingEvent event) {
        }

        @Override
        public void textSet(TextChangedEvent event) {
        }
    };
    content.addTextChangeListener(listener);
    boolean exceptionHandled = false;
    verify = 0;
    styledText.setText("testing");
    verify = 1;
    styledText.replaceTextRange(0, 0, "\n");
    verify = 0;
    styledText.setText("\n\n");
    verify = 2;
    styledText.replaceTextRange(0, 2, "a");
    verify = 0;
    styledText.setText("a");
    verify = 3;
    styledText.replaceTextRange(0, 1, "\n\n");
    verify = 0;
    styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    verify = 4;
    try {
        styledText.replaceTextRange(3, 1, "test\n");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":4: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("Line 1\r\nLine 2");
    verify = 5;
    styledText.replaceTextRange(0, 0, "\r");
    verify = 0;
    styledText.setText("This\nis a test\nline 3\nline 4");
    verify = 6;
    styledText.replaceTextRange(21, 7, "");
    verify = 0;
    styledText.setText("This\nis a test\r");
    verify = 7;
    styledText.replaceTextRange(5, 9, "");
    verify = 0;
    styledText.setText("\nL1\r\nL2\r\n");
    verify = 8;
    styledText.replaceTextRange(7, 2, "");
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 9;
    styledText.replaceTextRange(2, 2, "test");
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 10;
    try {
        styledText.replaceTextRange(3, 1, "");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":10: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    verify = 11;
    try {
        styledText.replaceTextRange(1, 2, "");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":11: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r");
    verify = 12;
    styledText.replaceTextRange(3, 0, "\n");
    verify = 0;
    styledText.setText("L1\n");
    verify = 13;
    styledText.replaceTextRange(2, 0, "\r");
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 14;
    try {
        styledText.replaceTextRange(3, 0, "test");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":14: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 15;
    styledText.replaceTextRange(2, 2, "test\n\n");
    verify = 0;
    styledText.setText("L1\r\n");
    verify = 16;
    try {
        styledText.replaceTextRange(3, 1, "test\r\n");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":16: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    verify = 17;
    try {
        styledText.replaceTextRange(1, 2, "test\n\n");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":17: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    verify = 0;
    styledText.setText("L1\r");
    verify = 18;
    styledText.replaceTextRange(3, 0, "\ntest\r\n");
    verify = 0;
    styledText.setText("L1\n");
    verify = 19;
    styledText.replaceTextRange(2, 0, "test\r\r\r");
    verify = 0;
    styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
    verify = 20;
    try {
        styledText.replaceTextRange(3, 1, "test\n");
    } catch (IllegalArgumentException ex) {
        exceptionHandled = true;
    }
    assertTrue(":20: exception not thrown", exceptionHandled);
    exceptionHandled = false;
    content.removeTextChangeListener(listener);
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent) TextChangingEvent(org.eclipse.swt.custom.TextChangingEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent) Test(org.junit.Test)

Example 10 with TextChangingEvent

use of org.eclipse.swt.custom.TextChangingEvent in project dbeaver by serge-rider.

the class DisplayedContent method shiftLines.

/**
 * Shifts full lines of text and fills the new empty space with text
 *
 * @param text    to replace new empty lines. Its size determines the number of lines to shift
 * @param forward shifts lines either forward or backward
 */
public void shiftLines(String text, boolean forward) {
    if (text.length() == 0)
        return;
    int linesInText = (text.length() - 1) / numberOfColumns + 1;
    int currentLimit = Math.min(data.length(), linesTimesColumns);
    TextChangingEvent event = new TextChangingEvent(this);
    event.start = forward ? 0 : currentLimit;
    event.newText = text;
    event.replaceCharCount = 0;
    event.newCharCount = text.length();
    event.replaceLineCount = 0;
    event.newLineCount = linesInText;
    for (TextChangeListener myTextListener : textListeners) myTextListener.textChanging(event);
    data.insert(event.start, text);
    TextChangedEvent changedEvent = new TextChangedEvent(this);
    for (TextChangeListener myTextListener : textListeners) myTextListener.textChanged(changedEvent);
    event = new TextChangingEvent(this);
    // event.start = forward ? linesTimesColumns : 0;
    event.start = forward ? linesTimesColumns - 1 : 0;
    event.newText = "";
    event.replaceCharCount = linesInText * numberOfColumns - linesTimesColumns + currentLimit;
    event.newCharCount = 0;
    event.replaceLineCount = linesInText;
    event.newLineCount = 0;
    for (TextChangeListener myTextListener : textListeners) myTextListener.textChanging(event);
    // data.delete(event.start, event.start + event.replaceCharCount);
    if (forward)
        data.delete(linesTimesColumns, linesTimesColumns + event.replaceCharCount);
    else
        data.delete(0, event.replaceCharCount);
    changedEvent = new TextChangedEvent(this);
    for (TextChangeListener myTextListener : textListeners) myTextListener.textChanged(changedEvent);
}
Also used : TextChangingEvent(org.eclipse.swt.custom.TextChangingEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent)

Aggregations

TextChangeListener (org.eclipse.swt.custom.TextChangeListener)10 TextChangingEvent (org.eclipse.swt.custom.TextChangingEvent)10 TextChangedEvent (org.eclipse.swt.custom.TextChangedEvent)8 ExtendedModifyEvent (org.eclipse.swt.custom.ExtendedModifyEvent)3 ExtendedModifyListener (org.eclipse.swt.custom.ExtendedModifyListener)3 StyledTextContent (org.eclipse.swt.custom.StyledTextContent)3 VerifyKeyListener (org.eclipse.swt.custom.VerifyKeyListener)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 KeyEvent (org.eclipse.swt.events.KeyEvent)3 KeyListener (org.eclipse.swt.events.KeyListener)3 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3 ModifyListener (org.eclipse.swt.events.ModifyListener)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseListener (org.eclipse.swt.events.MouseListener)3 VerifyEvent (org.eclipse.swt.events.VerifyEvent)3 Test (org.junit.Test)3 BadLocationException (org.eclipse.jface.text.BadLocationException)1