Search in sources :

Example 6 with TextChangeListener

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

the class Test_org_eclipse_swt_custom_StyledText method test_setContentLorg_eclipse_swt_custom_StyledTextContent.

@Test
public void test_setContentLorg_eclipse_swt_custom_StyledTextContent() {
    boolean exceptionThrown;
    StyledTextContent content = new StyledTextContent() {

        @Override
        public void addTextChangeListener(TextChangeListener listener) {
        }

        @Override
        public int getCharCount() {
            return 0;
        }

        @Override
        public String getLine(int lineIndex) {
            return "";
        }

        @Override
        public int getLineAtOffset(int offset) {
            return 0;
        }

        @Override
        public int getLineCount() {
            return 0;
        }

        @Override
        public String getLineDelimiter() {
            return "";
        }

        @Override
        public int getOffsetAtLine(int lineIndex) {
            return 0;
        }

        @Override
        public String getTextRange(int start, int length) {
            return "";
        }

        @Override
        public void removeTextChangeListener(TextChangeListener listener) {
        }

        @Override
        public void replaceTextRange(int start, int replaceLength, String text) {
        }

        @Override
        public void setText(String text) {
        }
    };
    text.setContent(content);
    assertEquals(content, text.getContent());
    exceptionThrown = false;
    try {
        text.setContent(null);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
}
Also used : StyledTextContent(org.eclipse.swt.custom.StyledTextContent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) Test(org.junit.Test)

Example 7 with TextChangeListener

use of org.eclipse.swt.custom.TextChangeListener in project webtools.sourceediting by eclipse.

the class StructuredDocumentToTextAdapter method relayTextChanging.

/**
 * Sends a text change to all registered listeners
 */
protected void relayTextChanging(int requestedStart, int requestedLength, String requestedChange) {
    if (getDocument() == null)
        return;
    if (isStoppedForwardingChanges()) {
        if (Debug.debugStructuredDocument && getDocument() != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.println("NOT relaying text changing: " + requestedStart + ":" + getDocument().getLength());
        }
        return;
    }
    if (Debug.debugStructuredDocument && getDocument() != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("relaying text changing: " + requestedStart + ":" + getDocument().getLength());
    }
    lastEvent = null;
    try {
        final TextChangingEvent textChangingEvent = new TextChangingEvent(this);
        textChangingEvent.start = requestedStart;
        textChangingEvent.replaceCharCount = requestedLength;
        textChangingEvent.newCharCount = (requestedChange == null ? 0 : requestedChange.length());
        textChangingEvent.replaceLineCount = getDocument().getNumberOfLines(requestedStart, requestedLength) - 1;
        textChangingEvent.newText = requestedChange;
        textChangingEvent.newLineCount = (requestedChange == null ? 0 : getDocument().computeNumberOfLines(requestedChange));
        // we must assign listeners to local variable,
        // since the add and remove listner
        // methods can change the actual instance of the
        // listener array from another thread
        Runnable runnable = new Runnable() {

            public void run() {
                if (fTextChangeListeners != null) {
                    TextChangeListener[] holdListeners = fTextChangeListeners;
                    for (int i = 0; i < holdListeners.length; i++) {
                        // this is a safe cast, since
                        // addListeners requires a
                        // IStructuredDocumentListener
                        holdListeners[i].textChanging(textChangingEvent);
                    }
                }
            }
        };
        runOnDisplayThreadIfNeedede(runnable);
    } catch (BadLocationException e) {
        // log for now, unless we find reason not to
        Logger.log(Logger.INFO, e.getMessage());
    }
}
Also used : TextChangingEvent(org.eclipse.swt.custom.TextChangingEvent) TextChangeListener(org.eclipse.swt.custom.TextChangeListener) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 8 with TextChangeListener

use of org.eclipse.swt.custom.TextChangeListener in project webtools.sourceediting by eclipse.

the class StructuredDocumentToTextAdapter method relayTextChanged.

/**
 * Sends a text replace event to all registered listeners.
 */
protected void relayTextChanged() {
    if (isStoppedForwardingChanges()) {
        if (Debug.debugStructuredDocument && getDocument() != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.println("NOT relaying text changed (" + getDocument().getLength() + ")");
        }
        return;
    }
    if (Debug.debugStructuredDocument && getDocument() != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("relaying text changed (" + getDocument().getLength() + ")");
    }
    final TextChangedEvent textChangedEvent = new TextChangedEvent(this);
    // we must assign listeners to local variable, since
    // the add and remove listener
    // methods can change the actual instance of the
    // listener array from another thread
    Runnable runnable = new Runnable() {

        public void run() {
            if (fTextChangeListeners != null) {
                Object[] holdListeners = fTextChangeListeners;
                for (int i = 0; i < holdListeners.length; i++) {
                    // this is a safe cast, since addListeners
                    // requires a IStructuredDocumentListener
                    ((TextChangeListener) holdListeners[i]).textChanged(textChangedEvent);
                }
            }
        }
    };
    runOnDisplayThreadIfNeedede(runnable);
    redrawTextChanged();
}
Also used : TextChangeListener(org.eclipse.swt.custom.TextChangeListener) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent)

Example 9 with TextChangeListener

use of org.eclipse.swt.custom.TextChangeListener in project webtools.sourceediting by eclipse.

the class StructuredDocumentToTextAdapter method relayTextSet.

/**
 * Sends a text set event to all registered listeners. Widget should
 * redraw itself automatically.
 */
protected void relayTextSet() {
    if (isStoppedForwardingChanges()) {
        if (Debug.debugStructuredDocument && getDocument() != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.println("NOT relaying text set (" + getDocument().getLength() + ")");
        }
        return;
    }
    if (Debug.debugStructuredDocument && getDocument() != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("relaying text set (" + getDocument().getLength() + ")");
    }
    lastEvent = null;
    final TextChangedEvent textChangedEvent = new TextChangedEvent(this);
    // we must assign listeners to local variable, since
    // the add and remove listner
    // methods can change the actual instance of the
    // listener array from another thread
    Runnable runnable = new Runnable() {

        public void run() {
            if (fTextChangeListeners != null) {
                TextChangeListener[] holdListeners = fTextChangeListeners;
                for (int i = 0; i < holdListeners.length; i++) {
                    holdListeners[i].textSet(textChangedEvent);
                }
            }
        }
    };
    runOnDisplayThreadIfNeedede(runnable);
}
Also used : TextChangeListener(org.eclipse.swt.custom.TextChangeListener) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent)

Example 10 with TextChangeListener

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

the class DisplayedContent method setText.

/**
 * @see org.eclipse.swt.custom.StyledTextContent#setText(java.lang.String)
 */
@Override
public void setText(String text) {
    data.setLength(0);
    data.append(text, 0, Math.min(text.length(), Math.max(0, linesTimesColumns)));
    TextChangedEvent changedEvent = new TextChangedEvent(this);
    for (TextChangeListener textListener : textListeners) {
        textListener.textSet(changedEvent);
    }
}
Also used : TextChangeListener(org.eclipse.swt.custom.TextChangeListener) TextChangedEvent(org.eclipse.swt.custom.TextChangedEvent)

Aggregations

TextChangeListener (org.eclipse.swt.custom.TextChangeListener)17 TextChangedEvent (org.eclipse.swt.custom.TextChangedEvent)12 TextChangingEvent (org.eclipse.swt.custom.TextChangingEvent)10 StyledTextContent (org.eclipse.swt.custom.StyledTextContent)6 Test (org.junit.Test)6 ExtendedModifyEvent (org.eclipse.swt.custom.ExtendedModifyEvent)3 ExtendedModifyListener (org.eclipse.swt.custom.ExtendedModifyListener)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 Point (org.eclipse.swt.graphics.Point)2