use of org.talend.designer.dbmap.ui.tabs.StyledTextHandler in project tdi-studio-se by Talend.
the class DataMapTableView method createExpressionCellEditor.
protected TextCellEditor createExpressionCellEditor(final TableViewerCreator tableViewerCreator, TableViewerCreatorColumn column, final Zone[] zones, boolean isConstraintExpressionCellEditor) {
final TextCellEditorWithProposal cellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), SWT.MULTI | SWT.BORDER, column);
final Text expressionTextEditor = (Text) cellEditor.getControl();
if (isConstraintExpressionCellEditor) {
// moved to it's caller to execute
// constraintExpressionTextEditor = expressionTextEditor;
} else {
columnExpressionTextEditor = expressionTextEditor;
}
cellEditor.addListener(new ICellEditorListener() {
Text text = (Text) cellEditor.getControl();
@Override
public void applyEditorValue() {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
mapperManager.getUiManager().parseNewExpression(text.getText(), (ITableEntry) modifiedObjectInfo.getCurrentModifiedBean(), true);
}
@Override
public void cancelEditor() {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
text.setText((String) modifiedObjectInfo.getOriginalPropertyBeanValue());
ITableEntry tableEntry = (ITableEntry) (modifiedObjectInfo.getCurrentModifiedBean() != null ? modifiedObjectInfo.getCurrentModifiedBean() : modifiedObjectInfo.getPreviousModifiedBean());
String originalExpression = (String) modifiedObjectInfo.getOriginalPropertyBeanValue();
mapperManager.getUiManager().parseNewExpression(originalExpression, tableEntry, true);
}
@Override
public void editorValueChanged(boolean oldValidState, boolean newValidState) {
if (expressionTextEditor.isFocusControl() || lastExpressionEditorTextWhichLostFocus == expressionTextEditor) {
ModifiedObjectInfo modifiedObjectInfo = tableViewerCreator.getModifiedObjectInfo();
ITableEntry tableEntry = (ITableEntry) (modifiedObjectInfo.getCurrentModifiedBean() != null ? modifiedObjectInfo.getCurrentModifiedBean() : modifiedObjectInfo.getPreviousModifiedBean());
mapperManager.getUiManager().parseNewExpression(text.getText(), tableEntry, false);
resizeTextEditor(text, tableViewerCreator);
}
}
});
expressionTextEditor.addControlListener(new ControlListener() {
ExecutionLimiter executionLimiter = null;
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (executionLimiter == null) {
executionLimiter = new ExecutionLimiter(50, true) {
@Override
public void execute(boolean isFinalExecution, Object data) {
if (isFinalExecution && !expressionTextEditor.isDisposed()) {
expressionTextEditor.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
if (expressionTextEditor.isDisposed()) {
return;
}
resizeTextEditor(expressionTextEditor, tableViewerCreator);
}
});
}
}
};
}
executionLimiter.startIfExecutable();
}
});
expressionTextEditor.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
ITableEntry currentModifiedEntry = (ITableEntry) tableViewerCreator.getModifiedObjectInfo().getCurrentModifiedBean();
initExpressionProposals(cellEditor, zones, tableViewerCreator, currentModifiedEntry);
resizeTextEditor(expressionTextEditor, tableViewerCreator);
StyledTextHandler styledTextHandler = mapperManager.getUiManager().getTabFolderEditors().getStyledTextHandler();
styledTextHandler.setCurrentEntry(currentModifiedEntry);
//$NON-NLS-1$
styledTextHandler.setTextWithoutNotifyListeners(currentModifiedEntry.getExpression() == null ? "" : currentModifiedEntry.getExpression());
}
@Override
public void focusLost(FocusEvent e) {
expressionEditorTextSelectionBeforeFocusLost = expressionTextEditor.getSelection();
lastExpressionEditorTextWhichLostFocus = expressionTextEditor;
}
});
column.setCellEditor(cellEditor, new CellEditorValueAdapter() {
@Override
public Object getCellEditorTypedValue(CellEditor cellEditor, Object originalTypedValue) {
return super.getCellEditorTypedValue(cellEditor, originalTypedValue);
}
@Override
public String getColumnText(CellEditor cellEditor, Object bean, Object cellEditorTypedValue) {
//$NON-NLS-1$ //$NON-NLS-2$
return super.getColumnText(cellEditor, bean, cellEditorTypedValue).replaceAll("[\r\n\t]+", " ... ");
}
@Override
public Object getOriginalTypedValue(CellEditor cellEditor, Object cellEditorTypedValue) {
return super.getOriginalTypedValue(cellEditor, cellEditorTypedValue);
}
});
return cellEditor;
}
use of org.talend.designer.dbmap.ui.tabs.StyledTextHandler in project tdi-studio-se by Talend.
the class DataMapTableView method highlightLineAndSetSelectionOfStyledText.
private void highlightLineAndSetSelectionOfStyledText(final Text expressionTextEditor) {
final StyledTextHandler styledTextHandler = mapperManager.getUiManager().getTabFolderEditors().getStyledTextHandler();
Runnable runnable = new Runnable() {
@Override
public void run() {
StyledText styledText = styledTextHandler.getStyledText();
if (styledText.isDisposed()) {
return;
}
String text = expressionTextEditor.getText();
Point selection = expressionTextEditor.getSelection();
if (selection.x - 1 > 0) {
while (expressionTextEditor.getLineDelimiter().equals(text.charAt(selection.x - 1))) {
selection.x++;
}
}
if (selection.y - 1 > 0) {
while (expressionTextEditor.getLineDelimiter().equals(text.charAt(selection.y - 1))) {
selection.y++;
}
}
int length = styledText.getText().length();
if (selection.x < 0) {
selection.x = 0;
}
if (selection.x > length) {
selection.x = length;
}
if (selection.y < 0) {
selection.y = 0;
}
if (selection.y > length) {
selection.y = length;
}
styledText.setSelection(selection);
styledTextHandler.highlightLineOfCursorPosition(selection);
}
};
new AsynchronousThreading(50, true, DataMapTableView.this.getDisplay(), runnable).start();
}
use of org.talend.designer.dbmap.ui.tabs.StyledTextHandler in project tdi-studio-se by Talend.
the class DataMapTableView method initExpressionProposals.
/**
*
* Init proposals of Text control, and StyledText in tab "Expression editor".
*
* @param textControl
* @param zones
* @param tableViewerCreator
* @param currentModifiedEntry
*/
protected void initExpressionProposals(final TextCellEditorWithProposal textCellEditor, Zone[] zones, final TableViewerCreator tableViewerCreator, ITableEntry currentModifiedEntry) {
if (this.expressionProposalProvider == null) {
IContentProposalProvider[] contentProposalProviders = new IContentProposalProvider[0];
if (!MapperMain.isStandAloneMode()) {
contentProposalProviders = new IContentProposalProvider[] { // new ProcessProposalProvider(mapperManager.getComponent().getProcess())
new KeyWordProposalProvider("tsql", //$NON-NLS-1$ //$NON-NLS-2$
"KEYWORD1") };
}
this.expressionProposalProvider = new ExpressionProposalProvider(mapperManager, contentProposalProviders);
}
this.expressionProposalProvider.init(abstractDataMapTable, zones, currentModifiedEntry);
textCellEditor.setContentProposalProvider(this.expressionProposalProvider);
StyledTextHandler styledTextHandler = mapperManager.getUiManager().getTabFolderEditors().getStyledTextHandler();
styledTextHandler.getStyledText().setEnabled(true);
ContentProposalAdapterExtended expressionProposalStyledText = styledTextHandler.getContentProposalAdapter();
expressionProposalStyledText.setContentProposalProvider(this.expressionProposalProvider);
// System.out.println("init expression proposal:"+this.expressionProposal);
}
Aggregations