use of org.eclipse.swt.custom.TextChangedEvent 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) {
}
});
}
use of org.eclipse.swt.custom.TextChangedEvent in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_TextChangeListener method test_textChangingLorg_eclipse_swt_custom_TextChangingEvent.
@Test
public void test_textChangingLorg_eclipse_swt_custom_TextChangingEvent() {
StyledTextContent content = styledText.getContent();
TextChangeListener listener = new TextChangeListener() {
@Override
public void textChanging(TextChangingEvent event) {
switch(verify) {
case 1:
{
assertTrue(":1a:", event.replaceLineCount == 0);
assertTrue(":1b:", event.newLineCount == 1);
break;
}
case 2:
{
assertTrue(":2a:", event.replaceLineCount == 2);
assertTrue(":2b:", event.newLineCount == 0);
break;
}
case 3:
{
assertTrue(":3a:", event.replaceLineCount == 0);
assertTrue(":3b:", event.newLineCount == 2);
break;
}
case 4:
{
assertTrue(":4:", false);
break;
}
case 5:
{
assertTrue(":5a:", event.replaceLineCount == 0);
assertTrue(":5b:", event.newLineCount == 1);
break;
}
case 6:
{
assertTrue(":6a:", event.replaceLineCount == 1);
assertTrue(":6b:", event.newLineCount == 0);
break;
}
case 7:
{
assertTrue(":7a:", event.replaceLineCount == 0);
assertTrue(":7b:", event.newLineCount == 0);
break;
}
case 8:
{
assertTrue(":8a:", event.replaceLineCount == 1);
assertTrue(":8b:", event.newLineCount == 0);
break;
}
case 9:
{
assertTrue(":9a:", event.replaceLineCount == 1);
assertTrue(":9b:", event.newLineCount == 0);
break;
}
case 10:
{
assertTrue(":10:", false);
break;
}
case 11:
{
assertTrue(":11:", false);
break;
}
case 12:
{
assertTrue(":12a:", event.replaceLineCount == 0);
assertTrue(":12b:", event.newLineCount == 1);
break;
}
case 13:
{
assertTrue(":13a:", event.replaceLineCount == 0);
assertTrue(":13b:", event.newLineCount == 1);
break;
}
case 14:
{
assertTrue(":14:", false);
break;
}
case 15:
{
assertTrue(":15a:", event.replaceLineCount == 1);
assertTrue(":15b:", event.newLineCount == 2);
break;
}
case 16:
{
assertTrue(":16:", false);
break;
}
case 17:
{
assertTrue(":17:", false);
break;
}
case 18:
{
assertTrue(":18a:", event.replaceLineCount == 0);
assertTrue(":18b:", event.newLineCount == 2);
break;
}
case 19:
{
assertTrue(":19a:", event.replaceLineCount == 0);
assertTrue(":19b:", event.newLineCount == 3);
break;
}
case 20:
{
assertTrue(":20:", false);
break;
}
}
}
@Override
public void textChanged(TextChangedEvent event) {
}
@Override
public void textSet(TextChangedEvent event) {
}
};
content.addTextChangeListener(listener);
boolean exceptionHandled = false;
verify = 1;
styledText.setText("testing");
styledText.replaceTextRange(0, 0, "\n");
verify = 2;
styledText.setText("\n\n");
styledText.replaceTextRange(0, 2, "a");
verify = 3;
styledText.setText("a");
styledText.replaceTextRange(0, 1, "\n\n");
verify = 4;
styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
try {
styledText.replaceTextRange(3, 1, "test\n");
} catch (IllegalArgumentException ex) {
exceptionHandled = true;
}
assertTrue(":4: exception not thrown", exceptionHandled);
exceptionHandled = false;
verify = 5;
styledText.setText("Line 1\r\nLine 2");
styledText.replaceTextRange(0, 0, "\r");
verify = 6;
styledText.setText("This\nis a test\nline 3\nline 4");
styledText.replaceTextRange(21, 7, "");
verify = 7;
styledText.setText("This\nis a test\r");
styledText.replaceTextRange(5, 9, "");
verify = 8;
styledText.setText("\nL1\r\nL2\r\n");
styledText.replaceTextRange(7, 2, "");
verify = 9;
styledText.setText("L1\r\n");
styledText.replaceTextRange(2, 2, "test");
verify = 10;
styledText.setText("L1\r\n");
try {
styledText.replaceTextRange(3, 1, "");
} catch (IllegalArgumentException ex) {
exceptionHandled = true;
}
assertTrue(":10: exception not thrown", exceptionHandled);
exceptionHandled = false;
verify = 11;
styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
try {
styledText.replaceTextRange(1, 2, "");
} catch (IllegalArgumentException ex) {
exceptionHandled = true;
}
assertTrue(":11: exception not thrown", exceptionHandled);
exceptionHandled = false;
verify = 12;
styledText.setText("L1\r");
styledText.replaceTextRange(3, 0, "\n");
verify = 13;
styledText.setText("L1\n");
styledText.replaceTextRange(2, 0, "\r");
verify = 14;
styledText.setText("L1\r\n");
try {
styledText.replaceTextRange(3, 0, "test");
} catch (IllegalArgumentException ex) {
exceptionHandled = true;
}
assertTrue(":14: exception not thrown", exceptionHandled);
exceptionHandled = false;
verify = 15;
styledText.setText("L1\r\n");
styledText.replaceTextRange(2, 2, "test\n\n");
verify = 16;
styledText.setText("L1\r\n");
try {
styledText.replaceTextRange(3, 1, "test\r\n");
} catch (IllegalArgumentException ex) {
exceptionHandled = true;
}
assertTrue(":16: exception not thrown", exceptionHandled);
exceptionHandled = false;
verify = 17;
styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
try {
styledText.replaceTextRange(1, 2, "test\n\n");
} catch (IllegalArgumentException ex) {
exceptionHandled = true;
}
assertTrue(":17: exception not thrown", exceptionHandled);
exceptionHandled = false;
verify = 18;
styledText.setText("L1\r");
styledText.replaceTextRange(3, 0, "\ntest\r\n");
verify = 19;
styledText.setText("L1\n");
styledText.replaceTextRange(2, 0, "test\r\r\r");
verify = 20;
styledText.setText("L1\r\nL2\r\nL3\r\nL4\r\n");
try {
styledText.replaceTextRange(3, 1, "test\n");
} catch (IllegalArgumentException ex) {
exceptionHandled = true;
}
assertTrue(":20: exception not thrown", exceptionHandled);
exceptionHandled = false;
content.removeTextChangeListener(listener);
}
use of org.eclipse.swt.custom.TextChangedEvent in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_TextChangeListener method test_textSetLorg_eclipse_swt_custom_TextChangedEvent.
@Test
public void test_textSetLorg_eclipse_swt_custom_TextChangedEvent() {
StyledTextContent content = styledText.getContent();
TextChangeListener listener = new TextChangeListener() {
@Override
public void textChanging(TextChangingEvent event) {
}
@Override
public void textChanged(TextChangedEvent event) {
}
@Override
public void textSet(TextChangedEvent event) {
switch(verify) {
case 1:
{
assertTrue(":1:", styledText.getText().equals("testing"));
break;
}
case 2:
{
assertTrue(":2:", styledText.getText().equals("\n\n"));
break;
}
case 3:
{
assertTrue(":3:", styledText.getText().equals("a"));
break;
}
case 4:
{
assertTrue(":4:", styledText.getText().isEmpty());
break;
}
}
}
};
content.addTextChangeListener(listener);
verify = 1;
styledText.setText("testing");
verify = 2;
styledText.setText("\n\n");
verify = 3;
styledText.setText("a");
verify = 4;
try {
styledText.setText(null);
} catch (IllegalArgumentException ex) {
assertTrue(":4:", true);
}
content.removeTextChangeListener(listener);
}
use of org.eclipse.swt.custom.TextChangedEvent 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.TextChangedEvent 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);
}
Aggregations