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) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void mouseUp(MouseEvent e) {
}
});
}
use of org.eclipse.swt.custom.TextChangingEvent 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.TextChangingEvent 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.TextChangingEvent in project dbeaver by dbeaver.
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);
}
use of org.eclipse.swt.custom.TextChangingEvent 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());
}
}
Aggregations