Search in sources :

Example 86 with FormAttachment

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

the class PropertyTypeController method addButton.

/**
     * 
     * DOC wzhang Comment method "addButton".
     * 
     * @param subComposite
     * @param param
     * @param lastControl
     * @param numInRow
     * @param top
     * @return
     */
private Control addButton(Composite subComposite, final IElementParameter param, Control lastControl, int numInRow, int top) {
    Button button;
    Button resetBtn = null;
    Control lastControlUsed = lastControl;
    Point buttonSize;
    FormData data;
    // if (!createFile) {
    //$NON-NLS-1$
    button = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    buttonSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    button.setImage(ImageProvider.getImage(EImage.SAVE_ICON));
    //$NON-NLS-1$
    button.setToolTipText(Messages.getString("PropertyTypeController.saveToMetadata"));
    button.setData(PARAMETER_NAME, param.getName());
    button.setEnabled(!param.isReadOnly());
    if (!param.isReadOnly()) {
        if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
            button.setEnabled(ExtractMetaDataUtils.getInstance().haveLoadMetadataNode());
        }
    }
    lastControlUsed = button;
    button.addSelectionListener(listenerSelection);
    //$NON-NLS-1$
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, "");
    data = new FormData();
    data.left = new FormAttachment(lastControl, 0);
    data.right = new FormAttachment(lastControl, labelLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x + (ITabbedPropertyConstants.HSPACE * 2), SWT.RIGHT);
    if (resetBtn != null) {
        data.top = new FormAttachment(resetBtn, 0, SWT.CENTER);
    } else {
        data.top = new FormAttachment(0, top);
    }
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    data = new FormData();
    data.left = new FormAttachment(labelLabel, -1);
    data.right = new FormAttachment(labelLabel, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
    if (resetBtn != null) {
        data.top = new FormAttachment(resetBtn, 0, SWT.CENTER);
    } else {
        data.top = new FormAttachment(0, top);
    }
    data.height = STANDARD_HEIGHT - 2;
    button.setLayoutData(data);
    int buttonHeight = buttonSize.y + ITabbedPropertyConstants.VSPACE;
    if (dynamicProperty.getCurRowSize() < buttonHeight) {
        dynamicProperty.setCurRowSize(buttonHeight);
    }
    // }
    return lastControlUsed;
}
Also used : FormData(org.eclipse.swt.layout.FormData) CLabel(org.eclipse.swt.custom.CLabel) 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 87 with FormAttachment

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

Example 88 with FormAttachment

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

the class PasswordController 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, PASSWORD);
    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 89 with FormAttachment

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

the class ProcessController method addContextCombo.

private Control addContextCombo(Composite subComposite, IElementParameter param, Control lastControl, int numInRow, int nbInRow, int top) {
    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.setItems(getListToDisplay(param));
    combo.setEditable(false);
    cLayout.setBackground(subComposite.getBackground());
    combo.setEnabled(!param.isReadOnly());
    combo.addSelectionListener(listenerSelection);
    combo.setData(PARAMETER_NAME, param.getName());
    if (elem instanceof Node) {
        combo.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    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.top = new FormAttachment(0, top);
    cLayout.setLayoutData(data);
    // **********************
    hashCurControls.put(param.getName(), combo);
    return cLayout;
}
Also used : FormData(org.eclipse.swt.layout.FormData) CLabel(org.eclipse.swt.custom.CLabel) Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) Node(org.talend.designer.core.ui.editor.nodes.Node) RepositoryNode(org.talend.repository.model.RepositoryNode) DecoratedField(org.eclipse.jface.fieldassist.DecoratedField) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment) Point(org.eclipse.swt.graphics.Point)

Example 90 with FormAttachment

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

the class JavaCommandController 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, final IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    Button btnEdit;
    //$NON-NLS-1$
    btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    FormData data;
    btnEdit.setData(NAME, JAVA_COMMAND);
    btnEdit.setData(PARAMETER_NAME, param.getName());
    btnEdit.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            // execute Java Command
            ElementParameter fullParam = (ElementParameter) param;
            File jar;
            URL url;
            try {
                List<URL> listURL = new ArrayList<URL>();
                ILibraryManagerService libManager = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
                IFolder javaLibFolder = null;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
                    IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
                    ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
                    if (talendProcessJavaProject != null) {
                        javaLibFolder = talendProcessJavaProject.getLibFolder();
                    }
                }
                if (javaLibFolder == null) {
                    return;
                }
                for (String jarString : fullParam.getJar().split(";")) {
                    IPath libPath = javaLibFolder.getLocation();
                    libManager.retrieve(jarString, libPath.toPortableString(), new NullProgressMonitor());
                    jar = libPath.append(jarString).toFile();
                    url = jar.toURL();
                    listURL.add(url);
                }
                URLClassLoader urlClassLoader = new URLClassLoader(listURL.toArray(new URL[0]));
                Class<?> classLoaded = Class.forName(fullParam.getJavaClass(), true, urlClassLoader);
                Object object = classLoaded.newInstance();
                List<String> args = new ArrayList<String>();
                for (String arg : fullParam.getArgs()) {
                    args.add(ElementParameterParser.parse(elem, arg));
                }
                for (Method method : classLoaded.getDeclaredMethods()) {
                    if (method.getName().equals(fullParam.getJavaFunction())) {
                        Object[] arglist = new Object[1];
                        arglist[0] = args.toArray(new String[0]);
                        method.invoke(object, arglist);
                    }
                }
            } catch (Exception e1) {
                MessageBoxExceptionHandler.process(e1);
            }
        }
    });
    if (elem instanceof Node) {
        btnEdit.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    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);
            data.right = new FormAttachment(lastControl, currentLabelWidth + STANDARD_BUTTON_WIDTH);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
            data.right = new FormAttachment(0, currentLabelWidth + STANDARD_BUTTON_WIDTH);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
        data.right = new FormAttachment(labelLabel, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
    }
    data.top = new FormAttachment(0, top);
    btnEdit.setLayoutData(data);
    // **************************
    hashCurControls.put(param.getName(), btnEdit);
    Point initialSize = btnEdit.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return btnEdit;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) Node(org.talend.designer.core.ui.editor.nodes.Node) URL(java.net.URL) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ILibraryManagerService(org.talend.core.ILibraryManagerService) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormData(org.eclipse.swt.layout.FormData) IPath(org.eclipse.core.runtime.IPath) Method(java.lang.reflect.Method) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) URLClassLoader(java.net.URLClassLoader) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener) IFolder(org.eclipse.core.resources.IFolder)

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