Search in sources :

Example 81 with FormAttachment

use of org.eclipse.swt.layout.FormAttachment in project tdi-studio-se by Talend.

the class NameAndLabelsTreeController method createControl.

@Override
public Control createControl(Composite subComposite, final IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    FormData data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.top = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(100, 0);
    Composite parentComp = new Composite(subComposite, SWT.NONE);
    parentComp.setLayoutData(data);
    parentComp.setLayout(new GridLayout());
    ElementsSelectionComposite<NamedThing> selectionComposite = new ElementsSelectionComposite<NamedThing>(parentComp) {

        @Override
        protected IBaseLabelProvider getLabelProvider() {
            return new LabelProvider() {

                @Override
                public String getText(Object obj) {
                    NamedThing nal = (NamedThing) obj;
                    return nal.getDisplayName();
                }

                @Override
                public Image getImage(Object obj) {
                    return null;
                }
            };
        }

        ;

        @Override
        protected void doSelectionChanged() {
            param.setValue(getSelectedElements());
        }

        @Override
        protected List<String> getSelectedElementLabels() {
            List<String> labels = new ArrayList<>();
            Object value = param.getValue();
            if (value instanceof List) {
                List<?> values = (List<?>) value;
                for (Object valueObj : values) {
                    if (valueObj instanceof NamedThing) {
                        labels.add(((NamedThing) valueObj).getName());
                    }
                }
                return labels;
            }
            return null;
        }

        @Override
        protected List<NamedThing> getInitSelectedElements(List<String> selectedElementLabels) {
            List<NamedThing> selectedElements = new ArrayList<>();
            List<NamedThing> viewerDatas = getViewerData();
            for (NamedThing viewerData : viewerDatas) {
                if (selectedElementLabels.contains(viewerData.getName())) {
                    selectedElements.add(viewerData);
                }
            }
            return selectedElements;
        }
    }.setShowToolbar(true).create();
    selectionComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    if (param instanceof GenericElementParameter) {
        selectionComposite.setViewerData(ComponentsUtils.getFormalPossibleValues((GenericElementParameter) param));
    }
    selectionComposite.setCheckedState();
    return parentComp;
}
Also used : FormData(org.eclipse.swt.layout.FormData) ElementsSelectionComposite(org.talend.core.ui.composite.ElementsSelectionComposite) ElementsSelectionComposite(org.talend.core.ui.composite.ElementsSelectionComposite) Composite(org.eclipse.swt.widgets.Composite) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 82 with FormAttachment

use of org.eclipse.swt.layout.FormAttachment 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 83 with FormAttachment

use of org.eclipse.swt.layout.FormAttachment in project tdi-studio-se by Talend.

the class GenericHiddenTextController method addButton.

protected Control addButton(Composite subComposite, IElementParameter param, Control lastControl, int numInRow, int nbInRow, int top) {
    Button btn;
    Control lastControlUsed = lastControl;
    Point btnSize;
    FormData data;
    //$NON-NLS-1$
    btn = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    btnSize = btn.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    btn.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    btn.addSelectionListener(listenerSelection);
    btn.setData(NAME, HIDDEN_TEXT);
    btn.setData(PARAMETER_NAME, param.getName());
    lastControlUsed = btn;
    data = new FormData();
    // data.right = new FormAttachment(lastControl, -5, SWT.LEFT);
    // data.left = new FormAttachment(lastControl, -(15 + STANDARD_BUTTON_WIDTH), SWT.LEFT);
    // data.right = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), 0);
    // data.left = new FormAttachment(((numInRow * MAX_PERCENT) / nbInRow), -STANDARD_BUTTON_WIDTH);
    data.left = new FormAttachment(lastControl, 0);
    data.right = new FormAttachment(lastControl, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
    data.top = new FormAttachment(0, top);
    data.height = STANDARD_HEIGHT - 2;
    btn.setLayoutData(data);
    // dynamicProperty.setCurRowSize(btnSize.y + ITabbedPropertyConstants.VSPACE);
    int buttonHeight = btnSize.y + ITabbedPropertyConstants.VSPACE;
    if (dynamicProperty.getCurRowSize() < buttonHeight) {
        dynamicProperty.setCurRowSize(buttonHeight);
    }
    return lastControlUsed;
}
Also used : FormData(org.eclipse.swt.layout.FormData) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) Point(org.eclipse.swt.graphics.Point) FormAttachment(org.eclipse.swt.layout.FormAttachment) Point(org.eclipse.swt.graphics.Point)

Example 84 with FormAttachment

use of org.eclipse.swt.layout.FormAttachment in project tdi-studio-se by Talend.

the class GenericHiddenTextController method createControl.

@Override
public Control createControl(Composite subComposite, IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    Control lastControlUsed = super.createControl(subComposite, param, numInRow, nbInRow, top, lastControl);
    Text labelText = (Text) hashCurControls.get(param.getName());
    if (labelText != null && param != null && isPasswordParam(param)) {
        labelText.setEchoChar('*');
    }
    FormData data = (FormData) lastControlUsed.getLayoutData();
    if (!param.isRepositoryValueUsed() && !isInWizard()) {
        data.right = new FormAttachment((numInRow * MAX_PERCENT) / nbInRow, -STANDARD_BUTTON_WIDTH);
        lastControlUsed = addButton(subComposite, param, lastControlUsed, numInRow, nbInRow, top);
    }
    return lastControlUsed;
}
Also used : FormData(org.eclipse.swt.layout.FormData) Control(org.eclipse.swt.widgets.Control) Text(org.eclipse.swt.widgets.Text) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 85 with FormAttachment

use of org.eclipse.swt.layout.FormAttachment in project tdi-studio-se by Talend.

the class ButtonController method createControl.

@Override
public Control createControl(Composite subComposite, IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    //$NON-NLS-1$
    Button theBtn = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    theBtn.setBackground(subComposite.getBackground());
    if (param.getDisplayName().equals("")) {
        //$NON-NLS-1$
        theBtn.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    } else {
        theBtn.setText(param.getDisplayName());
    }
    FormData data = new FormData();
    if (isInWizard()) {
        if (lastControl != null) {
            data.right = new FormAttachment(lastControl, 0);
        } else {
            data.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
        }
    } else {
        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);
    theBtn.setLayoutData(data);
    theBtn.setEnabled(!param.isReadOnly());
    theBtn.setData(param);
    hashCurControls.put(param.getName(), theBtn);
    theBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Command cmd = createCommand((Button) e.getSource());
            executeCommand(cmd);
        }
    });
    Point initialSize = theBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return theBtn;
}
Also used : FormData(org.eclipse.swt.layout.FormData) Button(org.eclipse.swt.widgets.Button) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

FormAttachment (org.eclipse.swt.layout.FormAttachment)253 FormData (org.eclipse.swt.layout.FormData)245 Composite (org.eclipse.swt.widgets.Composite)97 Point (org.eclipse.swt.graphics.Point)96 Button (org.eclipse.swt.widgets.Button)95 FormLayout (org.eclipse.swt.layout.FormLayout)93 Control (org.eclipse.swt.widgets.Control)64 Label (org.eclipse.swt.widgets.Label)59 CLabel (org.eclipse.swt.custom.CLabel)56 SelectionEvent (org.eclipse.swt.events.SelectionEvent)55 Node (org.talend.designer.core.ui.editor.nodes.Node)49 Text (org.eclipse.swt.widgets.Text)48 GC (org.eclipse.swt.graphics.GC)46 SelectionListener (org.eclipse.swt.events.SelectionListener)37 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)36 GridData (org.eclipse.swt.layout.GridData)36 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)34 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)32 GridLayout (org.eclipse.swt.layout.GridLayout)32 Group (org.eclipse.swt.widgets.Group)29