use of org.eclipse.swt.custom.ExtendedModifyListener 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.ExtendedModifyListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_custom_StyledText method test_addExtendedModifyListenerLorg_eclipse_swt_custom_ExtendedModifyListener.
@Test
public void test_addExtendedModifyListenerLorg_eclipse_swt_custom_ExtendedModifyListener() {
final String line = "Line1";
boolean exceptionThrown = false;
ExtendedModifyListener listener = event -> {
listenerCalled = true;
assertEquals("ExtendedModify event data invalid", 0, event.start);
assertEquals("ExtendedModify event data invalid", line.length(), event.length);
assertEquals("ExtendedModify event data invalid", "", event.replacedText);
};
try {
text.addExtendedModifyListener(null);
} catch (IllegalArgumentException e) {
exceptionThrown = true;
}
assertTrue("Expected exception not thrown", exceptionThrown);
// test whether all content modifying API methods send an ExtendedModify event
text.addExtendedModifyListener(listener);
listenerCalled = false;
text.append(line);
assertTrue("append does not send event", listenerCalled);
listenerCalled = false;
text.insert(line);
assertTrue("replaceTextRange does not send event", listenerCalled);
listenerCalled = false;
text.removeExtendedModifyListener(listener);
listener = event -> {
listenerCalled = true;
assertEquals("ExtendedModify event data invalid", 0, event.start);
assertEquals("ExtendedModify event data invalid", line.length(), event.length);
assertEquals("ExtendedModify event data invalid", line.substring(0, 1), event.replacedText);
};
text.addExtendedModifyListener(listener);
text.replaceTextRange(0, 1, line);
assertTrue("replaceTextRange does not send event", listenerCalled);
listenerCalled = false;
text.removeExtendedModifyListener(listener);
listener = event -> {
listenerCalled = true;
assertEquals("ExtendedModify event data invalid", 0, event.start);
assertEquals("ExtendedModify event data invalid", line.length(), event.length);
assertEquals("ExtendedModify event data invalid", line + line.substring(1, line.length()) + line, event.replacedText);
};
text.addExtendedModifyListener(listener);
text.setText(line);
assertTrue("setText does not send event", listenerCalled);
listenerCalled = false;
text.removeExtendedModifyListener(listener);
// cause StyledText to call the listener.
text.setText(line);
assertFalse("Listener not removed", listenerCalled);
}
use of org.eclipse.swt.custom.ExtendedModifyListener 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) {
}
});
}
use of org.eclipse.swt.custom.ExtendedModifyListener 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) {
}
});
}
use of org.eclipse.swt.custom.ExtendedModifyListener in project knime-core by knime.
the class StyledTextEditor method createStyledText.
private Control createStyledText(final Composite parent) {
m_styledText = new StyledText(parent, SWT.MULTI | SWT.WRAP | SWT.FULL_SELECTION);
// by default we are a workflow annotation editor
// can be changed by changing the default font (setDefaultFont(Font))
m_styledText.setFont(AnnotationEditPart.getWorkflowAnnotationDefaultFont());
m_styledText.setAlignment(SWT.LEFT);
m_styledText.setText("");
m_styledText.setTabs(TAB_SIZE);
m_styledText.addVerifyKeyListener(new VerifyKeyListener() {
@Override
public void verifyKey(final VerifyEvent event) {
if (event.character == SWT.CR && (event.stateMask & SWT.MOD1) != 0) {
event.doit = false;
}
}
});
// forward some events to the cell editor
m_styledText.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(final KeyEvent e) {
keyReleaseOccured(e);
}
});
m_styledText.addFocusListener(new FocusAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void focusLost(final org.eclipse.swt.events.FocusEvent e) {
// effect of an opening font editor, for instance)
if (m_allowFocusLost.get()) {
lostFocus();
}
}
});
m_styledText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
// super marks it dirty (otherwise no commit at the end)
fireEditorValueChanged(true, true);
}
});
m_styledText.addExtendedModifyListener(new ExtendedModifyListener() {
@Override
public void modifyText(final ExtendedModifyEvent event) {
if (event.length > 0) {
textInserted(event.start, event.length);
}
}
});
m_styledText.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(final SelectionEvent e) {
selectionChanged();
}
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
selectionChanged();
}
});
m_styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
addMenu(m_styledText);
// toolbar gets created first - enable its style buttons!
selectionChanged();
return m_styledText;
}
Aggregations