use of org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText 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) {
}
});
}
use of org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText in project tdi-studio-se by Talend.
the class TabFolderEditors method createStyledText.
private StyledText createStyledText(CTabItem item) {
StyledText styledText = null;
if (MapperMain.isStandAloneMode()) {
styledText = new StyledText(tabFolderEditors, SWT.V_SCROLL | SWT.H_SCROLL);
} else {
IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
styledText = new UnnotifiableColorStyledText(tabFolderEditors, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, preferenceStore, //$NON-NLS-1$
"tsql");
}
styledText.setEnabled(false);
item.setControl(styledText);
return styledText;
}
use of org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText in project tdi-studio-se by Talend.
the class TabFolderEditors method createStyledText.
private StyledText createStyledText(CTabItem item) {
StyledText styledText = null;
RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
ECodeLanguage language = repositoryContext.getProject().getLanguage();
IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
styledText = new UnnotifiableColorStyledText(tabFolderEditors, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, preferenceStore, language.getName());
styledText.setEnabled(false);
item.setControl(styledText);
return styledText;
}
use of org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText in project tdi-studio-se by Talend.
the class TabFolderEditors method createStyledText.
private StyledText createStyledText(CTabItem item) {
StyledText styledText = null;
if (MapperMain.isStandAloneMode()) {
styledText = new StyledText(tabFolderEditors, SWT.V_SCROLL | SWT.H_SCROLL);
} else {
RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
ECodeLanguage language = repositoryContext.getProject().getLanguage();
IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
// styledText = new ColorStyledText(tabFolderEditors, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL,
// colorManager, language.getName());
styledText = new UnnotifiableColorStyledText(tabFolderEditors, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, preferenceStore, language.getName());
}
styledText.setEnabled(false);
item.setControl(styledText);
return styledText;
}
Aggregations