Search in sources :

Example 36 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class SapSchemaTypeController method estimateRowSize.

/*
     * (non-Javadoc)
     *
     * @see org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController#
     * estimateRowSize (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter)
     */
@Override
public int estimateRowSize(Composite subComposite, IElementParameter param) {
    int comboSize, buttonSize;
    CCombo combo = new CCombo(subComposite, SWT.BORDER);
    IElementParameter schemaTypeParameter = param.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
    // elem.getElementParameter(EParameterName.SCHEMA_TYPE.getName());
    String[] originalList = schemaTypeParameter.getListItemsDisplayName();
    combo.setItems(originalList);
    comboSize = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    combo.dispose();
    //$NON-NLS-1$
    Button btn = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    buttonSize = btn.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
    btn.dispose();
    return Math.max(comboSize, buttonSize) + ITabbedPropertyConstants.VSPACE;
}
Also used : CCombo(org.eclipse.swt.custom.CCombo) Button(org.eclipse.swt.widgets.Button) IElementParameter(org.talend.core.model.process.IElementParameter) Point(org.eclipse.swt.graphics.Point)

Example 37 with IElementParameter

use of org.talend.core.model.process.IElementParameter 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)

Example 38 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class ProcessController method refreshCombo.

/**
     * 
     * ggu Comment method "refreshCombo".
     * 
     */
private void refreshCombo(IElementParameter parentParam, final String childParamName) {
    if (parentParam == null || childParamName == null) {
        return;
    }
    IElementParameter childParameter = parentParam.getChildParameters().get(childParamName);
    CCombo combo = (CCombo) hashCurControls.get(childParameter.getName());
    if (combo == null || combo.isDisposed()) {
        return;
    }
    Object value = childParameter.getValue();
    if (value instanceof String) {
        //$NON-NLS-1$
        String strValue = "";
        int nbInList = 0, nbMax = childParameter.getListItemsValue().length;
        String name = (String) value;
        while (strValue.equals(new String("")) && nbInList < nbMax) {
            //$NON-NLS-1$
            if (name.equals(childParameter.getListItemsValue()[nbInList])) {
                strValue = childParameter.getListItemsDisplayName()[nbInList];
            }
            nbInList++;
        }
        String[] paramItems = getListToDisplay(childParameter);
        String[] comboItems = combo.getItems();
        if (!Arrays.equals(paramItems, comboItems)) {
            combo.setItems(paramItems);
        }
        combo.setText(strValue);
        combo.setVisible(true);
    }
}
Also used : CCombo(org.eclipse.swt.custom.CCombo) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Point(org.eclipse.swt.graphics.Point)

Example 39 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class ModuleListController method createCommand.

public Command createCommand(SelectionEvent selectionEvent) {
    Set<String> elementsName;
    Control ctrl;
    elementsName = hashCurControls.keySet();
    for (String name : elementsName) {
        Object o = hashCurControls.get(name);
        if (o instanceof Control) {
            ctrl = (Control) o;
            if (ctrl == null) {
                hashCurControls.remove(name);
                return null;
            }
            if (ctrl.equals(selectionEvent.getSource()) && ctrl instanceof CCombo) {
                boolean isDisposed = ((CCombo) ctrl).isDisposed();
                if (!isDisposed && (!elem.getPropertyValue(name).equals(((CCombo) ctrl).getText()))) {
                    //$NON-NLS-1$
                    String value = new String("");
                    for (int i = 0; i < elem.getElementParameters().size(); i++) {
                        IElementParameter param = elem.getElementParameters().get(i);
                        if (param.getName().equals(name)) {
                            for (int j = 0; j < param.getListItemsValue().length; j++) {
                                if (((CCombo) ctrl).getText().equals(param.getListItemsDisplayName()[j])) {
                                    value = (String) param.getListItemsValue()[j];
                                }
                            }
                        }
                    }
                    if (value.equals(elem.getPropertyValue(name))) {
                        // anything
                        return null;
                    }
                    CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
                    return new PropertyChangeCommand(elem, name, value);
                }
            }
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IElementParameter(org.talend.core.model.process.IElementParameter) Point(org.eclipse.swt.graphics.Point)

Example 40 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class OpenedListController method modifyCommand.

/**
     * DOC zli Comment method "modifyCommand".
     * 
     * @param event
     * @return
     */
private Command modifyCommand(ModifyEvent event) {
    Set<String> elementsName;
    Control ctrl;
    elementsName = hashCurControls.keySet();
    for (String name : elementsName) {
        Object o = hashCurControls.get(name);
        if (o instanceof Control) {
            ctrl = (Control) o;
            if (ctrl == null) {
                hashCurControls.remove(name);
                return null;
            }
            CCombo combo = (CCombo) event.getSource();
            Object data = ctrl.getData(PARAMETER_NAME);
            if (!(ctrl instanceof CCombo)) {
                continue;
            }
            boolean isDisposed = ((CCombo) ctrl).isDisposed() || combo.isDisposed();
            if (isDisposed) {
                continue;
            }
            String paramName = "";
            if (data != null) {
                paramName = data.toString();
            }
            String value = "";
            if (data != null && data.equals(combo.getData(PARAMETER_NAME))) {
                for (int i = 0; i < elem.getElementParameters().size(); i++) {
                    IElementParameter param = elem.getElementParameters().get(i);
                    if (param.getFieldType().equals(EParameterFieldType.OPENED_LIST) && paramName.equals(param.getName())) {
                        String text = ((CCombo) ctrl).getText();
                        String[] listItemsDisplayName = param.getListItemsDisplayName();
                        boolean valueSet = false;
                        Object[] listItemsValue = param.getListItemsValue();
                        for (int j = 0; j < listItemsValue.length; j++) {
                            if (j < listItemsDisplayName.length && text.equals(listItemsDisplayName[j])) {
                                value = (String) listItemsValue[j];
                                valueSet = true;
                                break;
                            }
                        }
                        if (!valueSet) {
                            value = text;
                        }
                        // TDI-21313
                        if (value != null && value.equals(param.getValue())) {
                            return null;
                        }
                        param.setValue(value);
                    }
                }
                return new PropertyChangeCommand(elem, paramName, value);
            }
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IElementParameter(org.talend.core.model.process.IElementParameter) Point(org.eclipse.swt.graphics.Point)

Aggregations

IElementParameter (org.talend.core.model.process.IElementParameter)426 ArrayList (java.util.ArrayList)161 List (java.util.List)108 Node (org.talend.designer.core.ui.editor.nodes.Node)108 Map (java.util.Map)95 INode (org.talend.core.model.process.INode)92 HashMap (java.util.HashMap)82 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)73 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)69 Point (org.eclipse.swt.graphics.Point)57 ElementParameter (org.talend.designer.core.model.components.ElementParameter)48 ConnectionItem (org.talend.core.model.properties.ConnectionItem)45 IConnection (org.talend.core.model.process.IConnection)40 PersistenceException (org.talend.commons.exception.PersistenceException)39 Item (org.talend.core.model.properties.Item)37 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)37 IComponent (org.talend.core.model.components.IComponent)35 CCombo (org.eclipse.swt.custom.CCombo)33 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)29 Connection (org.talend.core.model.metadata.builder.connection.Connection)28