Search in sources :

Example 1 with ExecutionLimiter

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;
}
Also used : TextCellEditorWithProposal(org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) StyledTextHandler(org.talend.designer.dbmap.ui.tabs.StyledTextHandler) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) FocusEvent(org.eclipse.swt.events.FocusEvent) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) ControlListener(org.eclipse.swt.events.ControlListener) ModifiedObjectInfo(org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo) ExecutionLimiter(org.talend.commons.utils.threading.ExecutionLimiter) ControlEvent(org.eclipse.swt.events.ControlEvent) FocusListener(org.eclipse.swt.events.FocusListener)

Example 2 with ExecutionLimiter

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);
                    }
                }
            });
        }
    };
}
Also used : ExecutionLimiter(org.talend.commons.utils.threading.ExecutionLimiter)

Example 3 with ExecutionLimiter

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);
        }
    });
}
Also used : IDocumentListener(org.eclipse.jface.text.IDocumentListener) ExecutionLimiter(org.talend.commons.utils.threading.ExecutionLimiter) DocumentEvent(org.eclipse.jface.text.DocumentEvent)

Aggregations

ExecutionLimiter (org.talend.commons.utils.threading.ExecutionLimiter)3 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IDocumentListener (org.eclipse.jface.text.IDocumentListener)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 StyledText (org.eclipse.swt.custom.StyledText)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 ControlListener (org.eclipse.swt.events.ControlListener)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 FocusListener (org.eclipse.swt.events.FocusListener)1 Text (org.eclipse.swt.widgets.Text)1 CellEditorValueAdapter (org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter)1 ModifiedObjectInfo (org.talend.commons.ui.runtime.swt.tableviewer.data.ModifiedObjectInfo)1 UnnotifiableColorStyledText (org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText)1 TextCellEditorWithProposal (org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal)1 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)1 StyledTextHandler (org.talend.designer.dbmap.ui.tabs.StyledTextHandler)1