Search in sources :

Example 1 with StyledTextHandler

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;
}
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 StyledTextHandler

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();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) StyledTextHandler(org.talend.designer.dbmap.ui.tabs.StyledTextHandler) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) AsynchronousThreading(org.talend.commons.ui.runtime.thread.AsynchronousThreading)

Example 3 with StyledTextHandler

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);
}
Also used : IContentProposalProvider(org.eclipse.jface.fieldassist.IContentProposalProvider) ContentProposalAdapterExtended(org.talend.commons.ui.swt.proposal.ContentProposalAdapterExtended) StyledTextHandler(org.talend.designer.dbmap.ui.tabs.StyledTextHandler) KeyWordProposalProvider(org.talend.designer.dbmap.ui.proposal.expression.KeyWordProposalProvider) ExpressionProposalProvider(org.talend.designer.dbmap.ui.proposal.expression.ExpressionProposalProvider)

Aggregations

StyledTextHandler (org.talend.designer.dbmap.ui.tabs.StyledTextHandler)3 StyledText (org.eclipse.swt.custom.StyledText)2 UnnotifiableColorStyledText (org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText)2 IContentProposalProvider (org.eclipse.jface.fieldassist.IContentProposalProvider)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)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 Point (org.eclipse.swt.graphics.Point)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 AsynchronousThreading (org.talend.commons.ui.runtime.thread.AsynchronousThreading)1 ContentProposalAdapterExtended (org.talend.commons.ui.swt.proposal.ContentProposalAdapterExtended)1 TextCellEditorWithProposal (org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal)1 ExecutionLimiter (org.talend.commons.utils.threading.ExecutionLimiter)1 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)1