Search in sources :

Example 1 with UnnotifiableColorStyledText

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) {
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) MouseListener(org.eclipse.swt.events.MouseListener) MouseEvent(org.eclipse.swt.events.MouseEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) KeyListener(org.eclipse.swt.events.KeyListener) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) Point(org.eclipse.swt.graphics.Point)

Example 2 with UnnotifiableColorStyledText

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;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 3 with UnnotifiableColorStyledText

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;
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) StyledText(org.eclipse.swt.custom.StyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 4 with UnnotifiableColorStyledText

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;
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) StyledText(org.eclipse.swt.custom.StyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)4 UnnotifiableColorStyledText (org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText)4 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 RepositoryContext (org.talend.core.context.RepositoryContext)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 Point (org.eclipse.swt.graphics.Point)1 Text (org.eclipse.swt.widgets.Text)1 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)1