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);
}
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());
}
}
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();
}
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);
}
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);
}
}
Aggregations