Search in sources :

Example 6 with ColorStyledText

use of org.talend.commons.ui.swt.colorstyledtext.ColorStyledText in project tdi-studio-se by Talend.

the class SqlMemoController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createControl
     * (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
public Control createControl(Composite subComposite, IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    this.curParameter = param;
    this.paramFieldType = param.getFieldType();
    switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    final DecoratedField dField1 = new DecoratedField(subComposite, SWT.PUSH, new IControlCreator() {

        @Override
        public Control createControl(Composite parent, int style) {
            return new Button(parent, style);
        }
    });
    Control buttonControl = dField1.getLayoutControl();
    openSQLEditorButton = (Button) dField1.getControl();
    openSQLEditorButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    openSQLEditorButton.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    buttonControl.setBackground(subComposite.getBackground());
    openSQLEditorButton.setEnabled(true);
    openSQLEditorButton.setData(NAME, SQLEDITOR);
    openSQLEditorButton.setData(PARAMETER_NAME, param.getName());
    openSQLEditorButton.setEnabled(!param.isReadOnly());
    openSQLEditorButton.addSelectionListener(listenerSelection);
    if (param.getFieldType() == EParameterFieldType.MEMO_SQL) {
        openSQLEditorButton.setEnabled(ExtractMetaDataUtils.getInstance().haveLoadMetadataNode());
    }
    // Added by Marvin Wang on Dec.13, 2012 for bug TDI-7559.
    //$NON-NLS-1$
    IElementParameter typePara = elem.getElementParameter("TYPE");
    if (typePara != null && "Hive".equalsIgnoreCase((String) typePara.getValue())) {
        //$NON-NLS-1$
        openSQLEditorButton.setVisible(false);
    }
    if (typePara != null && "Impala".equalsIgnoreCase((String) typePara.getValue())) {
        //$NON-NLS-1$
        openSQLEditorButton.setVisible(false);
    }
    FormData data1 = new FormData();
    data1.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
    data1.left = new FormAttachment(100, -(ITabbedPropertyConstants.HSPACE + STANDARD_BUTTON_WIDTH));
    data1.top = new FormAttachment(0, top);
    buttonControl.setLayoutData(data1);
    int nbLines = param.getNbLines();
    IControlCreator txtCtrl = new IControlCreator() {

        @Override
        public Control createControl(final Composite parent, final int style) {
            return createColorStyledText(parent, style);
        }
    };
    DecoratedField dField = null;
    if (param.getNbLines() != 1) {
        dField = new DecoratedField(subComposite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, txtCtrl);
    } else {
        dField = new DecoratedField(subComposite, SWT.BORDER, txtCtrl);
    }
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    Control cLayout = dField.getLayoutControl();
    queryText = (ColorStyledText) dField.getControl();
    queryText.setData(PARAMETER_NAME, param.getName());
    editionControlHelper.register(param.getName(), queryText);
    FormData d = (FormData) queryText.getLayoutData();
    if (getAdditionalHeightSize() != 0) {
        nbLines += this.getAdditionalHeightSize() / queryText.getLineHeight();
    }
    d.height = queryText.getLineHeight() * nbLines;
    FormData data;
    queryText.getParent().setSize(subComposite.getSize().x, queryText.getLineHeight() * nbLines);
    cLayout.setBackground(subComposite.getBackground());
    // for bug 7580
    if (!(queryText instanceof ColorStyledText)) {
        queryText.setEnabled(!param.isReadOnly());
    } else {
        queryText.setEditable(!param.isReadOnly());
    }
    if (elem instanceof Node) {
        queryText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    queryText.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (switchParam != null) {
                switchParam.setValue(Boolean.FALSE);
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });
    if (param.isReadOnly() && param.isRepositoryValueUsed()) {
        cLayout.addMouseListener(listenerClick);
    }
    addDragAndDropTarget(queryText);
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    // *********************
    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
    }
    data.right = new FormAttachment(buttonControl, -5, SWT.LEFT);
    data.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);
    // **********************
    hashCurControls.put(param.getName(), queryText);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    // curRowSize = initialSize.y + ITabbedPropertyConstants.VSPACE;
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return null;
}
Also used : FormData(org.eclipse.swt.layout.FormData) CLabel(org.eclipse.swt.custom.CLabel) Composite(org.eclipse.swt.widgets.Composite) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) DecoratedField(org.eclipse.jface.fieldassist.DecoratedField) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) IControlCreator(org.eclipse.jface.fieldassist.IControlCreator) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) IElementParameter(org.talend.core.model.process.IElementParameter) KeyListener(org.eclipse.swt.events.KeyListener) ColorStyledText(org.talend.commons.ui.swt.colorstyledtext.ColorStyledText) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 7 with ColorStyledText

use of org.talend.commons.ui.swt.colorstyledtext.ColorStyledText in project tdi-studio-se by Talend.

the class SqlMemoController method refresh.

@Override
public void refresh(IElementParameter param, boolean checkErrorsWhenViewRefreshed) {
    ColorStyledText labelText = (ColorStyledText) hashCurControls.get(param.getName());
    if (labelText == null || labelText.isDisposed()) {
        return;
    }
    Object value = param.getValue();
    boolean valueChanged = false;
    if (value == null) {
        //$NON-NLS-1$
        labelText.setText("");
    } else {
        if (!value.equals(labelText.getText())) {
            labelText.setText((String) value);
            valueChanged = true;
        }
    }
    if (checkErrorsWhenViewRefreshed || valueChanged) {
        checkErrorsForPropertiesOnly(labelText);
    }
    fixedCursorPosition(param, labelText, value, valueChanged);
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ColorStyledText(org.talend.commons.ui.swt.colorstyledtext.ColorStyledText)

Example 8 with ColorStyledText

use of org.talend.commons.ui.swt.colorstyledtext.ColorStyledText in project tdi-studio-se by Talend.

the class SqlEditDialog method createDialogArea.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
     */
@Override
protected Control createDialogArea(Composite parent) {
    Composite control = (Composite) super.createDialogArea(parent);
    // create text viewer
    GridData gid = new GridData();
    gid.grabExcessHorizontalSpace = true;
    gid.grabExcessVerticalSpace = true;
    gid.horizontalAlignment = GridData.FILL;
    gid.verticalAlignment = GridData.FILL;
    control.setLayoutData(gid);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginBottom = 0;
    gridLayout.marginHeight = 0;
    gridLayout.marginLeft = 0;
    gridLayout.marginRight = 0;
    gridLayout.marginTop = 0;
    gridLayout.marginWidth = 0;
    control.setLayout(gridLayout);
    colorText = new ColorStyledText(control, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, CorePlugin.getDefault().getPreferenceStore(), language);
    IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
    String fontType = preferenceStore.getString(TalendDesignerPrefConstants.MEMO_TEXT_FONT);
    FontData fontData = new FontData(fontType);
    Font font = new Font(null, fontData);
    addResourceDisposeListener(colorText, font);
    colorText.setFont(font);
    GridData gd = new GridData(GridData.FILL_BOTH);
    colorText.setLayoutData(gd);
    colorText.setText(sql);
    colorText.addModifyListener(new ModifyListener() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
             */
        @Override
        public void modifyText(ModifyEvent e) {
            sql = colorText.getText();
        }
    });
    createEditorProposal();
    return control;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) FontData(org.eclipse.swt.graphics.FontData) GridData(org.eclipse.swt.layout.GridData) ColorStyledText(org.talend.commons.ui.swt.colorstyledtext.ColorStyledText) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Font(org.eclipse.swt.graphics.Font)

Example 9 with ColorStyledText

use of org.talend.commons.ui.swt.colorstyledtext.ColorStyledText in project tdi-studio-se by Talend.

the class SQLBuilderEditorComposite method createEditorArea.

/**
     * Creates UI for editor.
     * 
     * @param parent
     */
private void createEditorArea(Composite parent) {
    // create divider line
    Composite div1 = new Composite(parent, SWT.NONE);
    GridData lgid = new GridData();
    lgid.grabExcessHorizontalSpace = true;
    lgid.horizontalAlignment = GridData.FILL;
    lgid.heightHint = 1;
    lgid.verticalIndent = 1;
    div1.setLayoutData(lgid);
    div1.setBackground(parent.getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
    // create text viewer
    GridData gid = new GridData();
    gid.grabExcessHorizontalSpace = true;
    gid.grabExcessVerticalSpace = true;
    gid.horizontalAlignment = GridData.FILL;
    gid.verticalAlignment = GridData.FILL;
    colorText = new ColorStyledText(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, CorePlugin.getDefault().getPreferenceStore(), language);
    IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
    String fontType = preferenceStore.getString(TalendDesignerPrefConstants.MEMO_TEXT_FONT);
    FontData fontData = new FontData(fontType);
    Font font = new Font(null, fontData);
    addResourceDisposeListener(colorText, font);
    colorText.setFont(font);
    GridData gd = new GridData(GridData.FILL_BOTH);
    colorText.setLayoutData(gd);
    colorText.setText(this.connParam.getQuery());
    colorText.addVerifyKeyListener(new VerifyKeyListener() {

        @Override
        public void verifyKey(VerifyEvent event) {
            if (event.stateMask == SWT.CTRL && event.keyCode == 13) {
                event.doit = false;
                execSQLAction.run();
            }
        }
    });
    colorText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            isModified = true;
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) FontData(org.eclipse.swt.graphics.FontData) GridData(org.eclipse.swt.layout.GridData) ColorStyledText(org.talend.commons.ui.swt.colorstyledtext.ColorStyledText) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) VerifyEvent(org.eclipse.swt.events.VerifyEvent) Font(org.eclipse.swt.graphics.Font)

Example 10 with ColorStyledText

use of org.talend.commons.ui.swt.colorstyledtext.ColorStyledText in project tdi-studio-se by Talend.

the class MessageMemoController method createColorStyledText.

private ColorStyledText createColorStyledText(final Composite parent, final int style) {
    IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
    //$NON-NLS-1$
    ColorStyledText colorText = new ColorStyledText(parent, style, preferenceStore, "tsql");
    String fontType = preferenceStore.getString(TalendDesignerPrefConstants.MEMO_TEXT_FONT);
    FontData fontData = new FontData(fontType);
    Font font = new Font(parent.getDisplay(), fontData);
    // Font font = new Font(null, "courier", 8, SWT.NONE); //$NON-NLS-1$
    addResourceDisposeListener(colorText, font);
    colorText.setFont(font);
    return colorText;
}
Also used : FontData(org.eclipse.swt.graphics.FontData) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ColorStyledText(org.talend.commons.ui.swt.colorstyledtext.ColorStyledText) Font(org.eclipse.swt.graphics.Font)

Aggregations

ColorStyledText (org.talend.commons.ui.swt.colorstyledtext.ColorStyledText)12 Composite (org.eclipse.swt.widgets.Composite)7 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)6 Font (org.eclipse.swt.graphics.Font)6 FontData (org.eclipse.swt.graphics.FontData)6 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)5 IControlCreator (org.eclipse.jface.fieldassist.IControlCreator)5 Point (org.eclipse.swt.graphics.Point)5 FormData (org.eclipse.swt.layout.FormData)5 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3 ModifyListener (org.eclipse.swt.events.ModifyListener)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Control (org.eclipse.swt.widgets.Control)3 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)2 CLabel (org.eclipse.swt.custom.CLabel)2 StyledText (org.eclipse.swt.custom.StyledText)2 GC (org.eclipse.swt.graphics.GC)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 Display (org.eclipse.swt.widgets.Display)2