Search in sources :

Example 26 with GC

use of org.eclipse.swt.graphics.GC in project tdi-studio-se by Talend.

the class DirectoryController 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(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
    this.curParameter = param;
    FormData data;
    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);
    }
    //$NON-NLS-1$
    Button btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    data = new FormData();
    data.left = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), -STANDARD_BUTTON_WIDTH);
    data.right = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), 0);
    data.top = new FormAttachment(labelLabel, 0, SWT.CENTER);
    data.height = STANDARD_HEIGHT - 2;
    btnEdit.setLayoutData(data);
    btnEdit.setData(NAME, DIRECTORY);
    btnEdit.setData(PARAMETER_NAME, param.getName());
    btnEdit.setEnabled(!param.isReadOnly());
    btnEdit.addSelectionListener(listenerSelection);
    DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, new SelectAllTextControlCreator());
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    Control cLayout = dField.getLayoutControl();
    Text labelText = (Text) dField.getControl();
    cLayout.setBackground(subComposite.getBackground());
    if (!elem.isReadOnly()) {
        if (param.isRepositoryValueUsed()) {
            addRepositoryPropertyListener(labelText);
        }
        labelText.setEditable(!param.isReadOnly() && !param.isRepositoryValueUsed());
    } else {
        labelText.setEditable(false);
    }
    labelText.setData(PARAMETER_NAME, param.getName());
    editionControlHelper.register(param.getName(), labelText);
    addDragAndDropTarget(labelText);
    if (elem instanceof Node) {
        labelText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    // **************************
    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(btnEdit, 0);
    data.top = new FormAttachment(labelLabel, 0, SWT.CENTER);
    cLayout.setLayoutData(data);
    hashCurControls.put(param.getName(), labelText);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return btnEdit;
}
Also used : FormData(org.eclipse.swt.layout.FormData) CLabel(org.eclipse.swt.custom.CLabel) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) Node(org.talend.designer.core.ui.editor.nodes.Node) Text(org.eclipse.swt.widgets.Text) DecoratedField(org.eclipse.jface.fieldassist.DecoratedField) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) SelectAllTextControlCreator(org.talend.designer.core.ui.editor.properties.controllers.creator.SelectAllTextControlCreator) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 27 with GC

use of org.eclipse.swt.graphics.GC in project tdi-studio-se by Talend.

the class InsertionIndicator method addListeners.

/**
     * DOC amaumont Comment method "addListeners".
     */
private void addListeners() {
    Listener paintListener = new Listener() {

        public void handleEvent(Event event) {
            Composite composite = (Composite) event.widget;
            Rectangle bounds = composite.getBounds();
            // //////////////////////////////////////////////////////////
            // draw image filled with transparent pixels
            RGB transparentColor = new RGB(0, 255, 0);
            PaletteData paletteData = new PaletteData(new RGB[] { transparentColor });
            ImageData imageData = new ImageData(bounds.width, bounds.height, 1, paletteData);
            int transparentPixelValue = imageData.palette.getPixel(transparentColor);
            imageData.transparentPixel = transparentPixelValue;
            GC gc = event.gc;
            final Image image = new Image(gc.getDevice(), imageData);
            gc.drawImage(image, 0, 0);
            image.dispose();
            // ////////////////////////////////////////////////////////////////////////////
            // //////////////////////////////////////////////////////////
            // draw left arrow
            int yCenter = bounds.height / 2;
            int widthExternalArrow = 10;
            gc.setBackground(colorIndicator);
            gc.setForeground(colorIndicator);
            if (composite == leftArrowDraggingIndicator) {
                // external left arrow
                Point leftCrossPoint = new Point(widthExternalArrow, yCenter);
                gc.fillPolygon(new int[] { 0, 0, leftCrossPoint.x, leftCrossPoint.y, 0, bounds.height });
                gc.drawLine(leftCrossPoint.x, leftCrossPoint.y, bounds.width, leftCrossPoint.y);
            } else {
                // external right arrow
                Point rightCrossPoint = new Point(bounds.width - widthExternalArrow, yCenter);
                gc.fillPolygon(new int[] { bounds.width, 0, rightCrossPoint.x, rightCrossPoint.y, bounds.width, bounds.height });
                gc.drawLine(rightCrossPoint.x, rightCrossPoint.y, -bounds.width, rightCrossPoint.y);
            }
        }
    };
    leftArrowDraggingIndicator.addListener(SWT.Paint, paintListener);
    rightArrowDraggingIndicator.addListener(SWT.Paint, paintListener);
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) ImageData(org.eclipse.swt.graphics.ImageData) Rectangle(org.eclipse.swt.graphics.Rectangle) Event(org.eclipse.swt.widgets.Event) Point(org.eclipse.swt.graphics.Point) RGB(org.eclipse.swt.graphics.RGB) GC(org.eclipse.swt.graphics.GC) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 28 with GC

use of org.eclipse.swt.graphics.GC in project tdi-studio-se by Talend.

the class Marker method getExtent.

/**
     * Gets the text extent.
     * 
     * @param hover The hover
     * @param text The text
     * @return The text extent
     */
private static Point getExtent(Shell hover, String text) {
    GC gc = new GC(hover);
    Point textExtent = gc.textExtent(text);
    gc.dispose();
    return textExtent;
}
Also used : Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC)

Example 29 with GC

use of org.eclipse.swt.graphics.GC in project tdi-studio-se by Talend.

the class ComponentRefController method createControl.

@Override
public Control createControl(final Composite subComposite, final IElementParameter param, final int numInRow, final int nbInRow, final int top, final Control lastControl) {
    DecoratedField dField = new DecoratedField(subComposite, SWT.BORDER, cbCtrl);
    if (param.isRequired()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_REQUIRED);
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.TOP, false);
    }
    if (param.isRepositoryValueUsed()) {
        FieldDecoration decoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
        //$NON-NLS-1$
        decoration.setDescription(Messages.getString("ComboController.valueFromRepository"));
        dField.addFieldDecoration(decoration, SWT.RIGHT | SWT.BOTTOM, false);
    }
    Control cLayout = dField.getLayoutControl();
    CCombo combo = (CCombo) dField.getControl();
    FormData data;
    combo.setEditable(false);
    cLayout.setBackground(subComposite.getBackground());
    combo.setEnabled(!param.isReadOnly());
    GenericElementParameter gParam = (GenericElementParameter) param;
    ComponentReferenceProperties props = (ComponentReferenceProperties) gParam.getWidget().getContent();
    combo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            if (!(event.getSource() instanceof CCombo)) {
                return;
            }
            Command cmd = createComboCommand(event, gParam, props);
            executeCommand(cmd);
        }
    });
    combo.setData(PARAMETER_NAME, param.getName());
    int nbLines = param.getNbLines();
    if (nbLines > 5) {
        combo.setVisibleItemCount(nbLines);
    }
    if (elem instanceof Node) {
        combo.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, Messages.getString("ComponentRefController.connectionLabel"));
    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(Messages.getString("ComponentRefController.connectionLabel"));
    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.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);
    // **********************
    hashCurControls.put(param.getName(), combo);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return cLayout;
}
Also used : FormData(org.eclipse.swt.layout.FormData) CLabel(org.eclipse.swt.custom.CLabel) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) 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) Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GC(org.eclipse.swt.graphics.GC) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 30 with GC

use of org.eclipse.swt.graphics.GC in project tdi-studio-se by Talend.

the class MessageMemoController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.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();
    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();
    messageEditorButton = (Button) dField1.getControl();
    messageEditorButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    messageEditorButton.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    buttonControl.setBackground(subComposite.getBackground());
    messageEditorButton.setEnabled(true);
    messageEditorButton.setData(NAME, SQLEDITOR);
    messageEditorButton.setData(PARAMETER_NAME, param.getName());
    messageEditorButton.setEnabled(!param.isReadOnly());
    messageEditorButton.addSelectionListener(listenerSelection);
    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();
    messageText = (ColorStyledText) dField.getControl();
    messageText.setText(getCurrentMessage());
    messageText.setData(PARAMETER_NAME, param.getName());
    editionControlHelper.register(param.getName(), messageText);
    FormData d = (FormData) messageText.getLayoutData();
    if (getAdditionalHeightSize() != 0) {
        nbLines += this.getAdditionalHeightSize() / messageText.getLineHeight();
    }
    d.height = messageText.getLineHeight() * nbLines;
    FormData data;
    messageText.getParent().setSize(subComposite.getSize().x, messageText.getLineHeight() * nbLines);
    cLayout.setBackground(subComposite.getBackground());
    messageText.setEnabled(!param.isReadOnly());
    if (elem instanceof Node) {
        messageText.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    addDragAndDropTarget(messageText);
    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(), messageText);
    Point initialSize = dField.getLayoutControl().computeSize(SWT.DEFAULT, SWT.DEFAULT);
    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) DecoratedField(org.eclipse.jface.fieldassist.DecoratedField) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IControlCreator(org.eclipse.jface.fieldassist.IControlCreator) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

GC (org.eclipse.swt.graphics.GC)122 Point (org.eclipse.swt.graphics.Point)90 FormAttachment (org.eclipse.swt.layout.FormAttachment)46 FormData (org.eclipse.swt.layout.FormData)46 CLabel (org.eclipse.swt.custom.CLabel)42 Node (org.talend.designer.core.ui.editor.nodes.Node)39 Control (org.eclipse.swt.widgets.Control)31 Rectangle (org.eclipse.swt.graphics.Rectangle)29 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)28 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)27 Image (org.eclipse.swt.graphics.Image)27 Button (org.eclipse.swt.widgets.Button)24 Composite (org.eclipse.swt.widgets.Composite)18 CCombo (org.eclipse.swt.custom.CCombo)16 Text (org.eclipse.swt.widgets.Text)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 GridData (org.eclipse.swt.layout.GridData)11 SelectAllTextControlCreator (org.talend.designer.core.ui.editor.properties.controllers.creator.SelectAllTextControlCreator)11 INode (org.talend.core.model.process.INode)10 Label (org.eclipse.swt.widgets.Label)9