use of org.talend.commons.utils.threading.ExecutionLimiter 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.commons.utils.threading.ExecutionLimiter in project tdi-studio-se by Talend.
the class MapperUI method addBackgroundRefreshLimiters.
private void addBackgroundRefreshLimiters(final Display display) {
backgroundRefreshLimiter = new ExecutionLimiter(DEFAULT_TIME_BEFORE_NEW_BG_REFRESH, true) {
@Override
public void execute(final boolean isFinalExecution, Object data) {
display.asyncExec(new Runnable() {
public void run() {
if (mouseMoveScrollZoneHelper.mouseDownOnScroll && mouseMoveScrollZoneHelper.scrolling) {
updateBackground(false, false);
} else {
updateBackground(false, true);
}
}
});
}
};
backgroundRefreshLimiterForceRecalculate = new ExecutionLimiter(DEFAULT_TIME_BEFORE_NEW_BG_REFRESH, true) {
@Override
public void execute(final boolean isFinalExecution, Object data) {
display.asyncExec(new Runnable() {
public void run() {
if (!isFinalExecution) {
updateBackground(true, false);
} else {
updateBackground(true, true);
}
}
});
}
};
}
use of org.talend.commons.utils.threading.ExecutionLimiter in project tdi-studio-se by Talend.
the class ReconcilerViewer method addDocumentListener.
private void addDocumentListener(final IDocument document) {
final ExecutionLimiter documentReconcilerLimiter = new ExecutionLimiter(500, true) {
@Override
protected void execute(boolean isFinalExecution, Object data) {
if (isFinalExecution) {
if (getControl() != null && !getControl().isDisposed()) {
getControl().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
// System.out.println(System.currentTimeMillis())
// ;
updateContents();
if (document.get().length() != 0) {
calculatePositions();
}
// (bug 4289)
updateVisibleRegion();
}
});
}
}
}
};
document.addDocumentListener(new IDocumentListener() {
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
// nothing
}
@Override
public void documentChanged(DocumentEvent event) {
documentReconcilerLimiter.resetTimer();
documentReconcilerLimiter.startIfExecutable(true, null);
}
});
}
Aggregations