Search in sources :

Example 1 with StyledTextHandler

use of org.talend.designer.xmlmap.ui.tabs.StyledTextHandler in project tdi-studio-se by Talend.

the class ExpressionCellEditor method highlightLineAndSetSelectionOfStyledTextFromTextControl.

protected void highlightLineAndSetSelectionOfStyledTextFromTextControl(final Control textWidget) {
    final StyledTextHandler styledTextHandler = mapperManager.getMapperUI().getTabFolderEditors().getStyledTextHandler();
    Runnable runnable = new Runnable() {

        public void run() {
            StyledText styledText = styledTextHandler.getStyledText();
            if (styledText.isDisposed() || textWidget.isDisposed()) {
                return;
            }
            String text = ControlUtils.getText(textWidget);
            Point selection = ControlUtils.getSelection(textWidget);
            String lineDelimiter = ControlUtils.getLineDelimiter(textWidget);
            if (selection.x - 1 > 0) {
                while (lineDelimiter.equals(text.charAt(selection.x - 1))) {
                    selection.x++;
                }
            }
            if (selection.y - 1 > 0) {
                while (lineDelimiter.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, parent.getDisplay(), runnable).start();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) StyledTextHandler(org.talend.designer.xmlmap.ui.tabs.StyledTextHandler) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) AsynchronousThreading(org.talend.commons.ui.runtime.thread.AsynchronousThreading)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)1 Point (org.eclipse.swt.graphics.Point)1 AsynchronousThreading (org.talend.commons.ui.runtime.thread.AsynchronousThreading)1 UnnotifiableColorStyledText (org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText)1 StyledTextHandler (org.talend.designer.xmlmap.ui.tabs.StyledTextHandler)1