use of org.eclipse.swt.events.KeyListener 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.events.KeyListener in project tdi-studio-se by Talend.
the class BasicNotePropertyComposite method createTextControl.
/**
* DOC qwei Comment method "createTextcontrol".
*/
private void createTextControl(Composite parent) {
//$NON-NLS-1$
CLabel textLabel = getWidgetFactory().createCLabel(composite, Messages.getString("TextNoteSection.Label"));
//$NON-NLS-1$
FormData data = new FormData();
data.left = new FormAttachment(0, 0);
data.top = new FormAttachment(colorsAndFontsGroup, 30);
textLabel.setLayoutData(data);
//$NON-NLS-1$
text = getWidgetFactory().createText(composite, "", SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
//$NON-NLS-1$
data = new FormData();
data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
data.right = new FormAttachment(textLabel, 560);
data.top = new FormAttachment(textLabel, 0, SWT.TOP);
// 5 lines
data.height = 5 * text.getLineHeight();
text.setLayoutData(data);
text.setForeground(new Color(null, ColorUtils.stringToRGB((String) note.getPropertyValue(EParameterName.NOTETXT_COLOR.getName()))));
text.setText(note.getText());
text.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
if (!text.getText().equals(note.getText())) {
ChangeNoteTextCommand command = new ChangeNoteTextCommand(note, text.getText());
getCommandStack().execute(command);
}
}
});
text.addKeyListener(new KeyListener() {
@Override
public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
// TODO Auto-generated method stub
if (!text.getText().equals(note.getText())) {
ChangeNoteTextCommand command = new ChangeNoteTextCommand(note, text.getText());
getCommandStack().execute(command);
}
}
});
textChanged();
}
use of org.eclipse.swt.events.KeyListener in project tdi-studio-se by Talend.
the class TalendEditorComponentCreationAssist method initListeners.
private void initListeners() {
assistText.addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
if (e.stateMask == SWT.NONE) {
if (e.keyCode == SWT.ESC) {
disposeAssistText();
} else if (e.keyCode == SWT.CR) {
acceptProposal();
}
}
}
@Override
public void keyPressed(KeyEvent e) {
}
});
assistText.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
if (!(contentProposalAdapter.isProposalPopupOpen())) {
disposeAssistText();
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
contentProposalAdapter.addContentProposalListener(new IContentProposalListener2() {
@Override
public void proposalPopupOpened(ContentProposalAdapter adapter) {
}
@Override
public void proposalPopupClosed(ContentProposalAdapter adapter) {
if (assistText != null && !assistText.isFocusControl()) {
disposeAssistText();
}
}
});
contentProposalAdapter.addContentProposalListener(new IContentProposalListener() {
@Override
public void proposalAccepted(IContentProposal proposal) {
acceptProposal();
}
});
}
use of org.eclipse.swt.events.KeyListener in project tdi-studio-se by Talend.
the class TalendEditorComponentCreationUtil method removeComponentCreationAssist.
public static void removeComponentCreationAssist(AbstractTalendEditor talendEditor) {
GraphicalViewer graphicalViewer = (GraphicalViewer) talendEditor.getAdapter(GraphicalViewer.class);
Object data = graphicalViewer.getControl().getData(COMPONENT_CREATION_ASSIST_LISTENER);
if (data != null && data instanceof KeyListener) {
graphicalViewer.getControl().removeKeyListener((KeyListener) data);
graphicalViewer.getControl().update();
}
}
use of org.eclipse.swt.events.KeyListener in project tdi-studio-se by Talend.
the class DataMapTableView method attachCellExpressionToStyledTextEditor.
/**
* DOC amaumont Comment method "attachCellExpressionToStyledTextEditor".
*
* @param tableViewerCreator TODO
* @param styledTextHandler
* @param expressionEditorText2
*/
protected void attachCellExpressionToStyledTextEditor(final TableViewerCreator tableViewerCreator, final Text expressionTextEditor, final StyledTextHandler styledTextHandler) {
expressionTextEditor.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
ITableEntry currentModifiedEntry = (ITableEntry) tableViewerCreator.getModifiedObjectInfo().getCurrentModifiedBean();
styledTextHandler.setCurrentEntry(currentModifiedEntry);
Text text = (Text) e.widget;
if (Math.abs(text.getText().length() - styledTextHandler.getStyledText().getText().length()) > 1) {
styledTextHandler.setTextWithoutNotifyListeners(text.getText());
// highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
}
}
});
expressionTextEditor.addKeyListener(new KeyListener() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
*/
@Override
public void keyPressed(KeyEvent e) {
// System.out.println("e.character=" + e.character);
// System.out.println("keyCode=" + e.keyCode);
boolean ctrl = (e.stateMask & SWT.CTRL) != 0;
boolean altgr = (e.stateMask & SWT.ALT) != 0;
if (e.character == '\0' || ctrl && !altgr) {
highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
} else {
UnnotifiableColorStyledText mapperColorStyledText = (UnnotifiableColorStyledText) styledTextHandler.getStyledText();
Point selection = expressionTextEditor.getSelection();
if (e.character == '\r' || e.character == '') {
e.doit = false;
styledTextHandler.setTextWithoutNotifyListeners(expressionTextEditor.getText());
highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
} else {
if (e.character == SWT.BS || e.character == SWT.DEL) {
if (selection.x == selection.y) {
if (e.character == SWT.BS) {
if (selection.x - 1 > 0 && mapperColorStyledText.getText().length() > selection.x - 1) {
char previousChar = mapperColorStyledText.getText().charAt(selection.x - 1);
if (previousChar == '\n') {
//$NON-NLS-1$
mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x - 2, 2, "");
} else {
//$NON-NLS-1$
mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x - 1, 1, "");
}
}
} else {
if (selection.x < mapperColorStyledText.getText().length()) {
char nextChar = mapperColorStyledText.getText().charAt(selection.x);
if (nextChar == '\r') {
//$NON-NLS-1$
mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x, 2, "");
} else {
//$NON-NLS-1$
mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x, 1, "");
}
}
}
} else {
if (selection.y <= mapperColorStyledText.getCharCount()) {
mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x, selection.y - selection.x, //$NON-NLS-1$
"");
}
highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
}
} else {
// System.out.println("mapperColorStyledText.getText()="+mapperColorStyledText.getText().length());
if (selection.y <= mapperColorStyledText.getCharCount()) {
mapperColorStyledText.replaceTextRangeWithoutNotifyListeners(selection.x, selection.y - selection.x, String.valueOf(e.character));
}
highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
}
}
}
}
@Override
public void keyReleased(KeyEvent e) {
// highlightLineOfCursorPosition();
}
});
expressionTextEditor.addMouseListener(new MouseListener() {
@Override
public void mouseDoubleClick(MouseEvent e) {
highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
}
@Override
public void mouseDown(MouseEvent e) {
highlightLineAndSetSelectionOfStyledText(expressionTextEditor);
}
@Override
public void mouseUp(MouseEvent e) {
}
});
}
Aggregations