Search in sources :

Example 6 with IElementParameter

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

the class NodeContainerPart method createFigure.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
     */
@Override
protected IFigure createFigure() {
    NodeContainerFigure nodeContainerFigure = new NodeContainerFigure((NodeContainer) this.getModel());
    Node node = ((NodeContainer) getModel()).getNode();
    if (node.isActivate()) {
        nodeContainerFigure.setAlpha(-1);
    } else {
        nodeContainerFigure.setAlpha(Node.ALPHA_VALUE);
    }
    IElementParameter param = node.getElementParameter(EParameterName.INFORMATION.getName());
    if (param != null) {
        boolean showInfoFlag = Boolean.TRUE.equals(param.getValue());
        nodeContainerFigure.updateStatus(node.getStatus(), showInfoFlag);
        nodeContainerFigure.setInfoHint(node.getShowHintText());
    }
    return nodeContainerFigure;
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 7 with IElementParameter

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

the class NodeContainerFigure method updateParallelFigure.

/**
     * DOC YeXiaowei Comment method "updateParallelFigure".
     * 
     * @param status
     */
private void updateParallelFigure(int status) {
    if (!PluginChecker.isTeamEdition() || parallelFigure == null) {
        return;
    }
    //$NON-NLS-1$
    String numberParallel = "0";
    if ((status & Process.PARALLEL_STATUS) != 0) {
        IElementParameter numberParallelizeParameter = nodeContainer.getNode().getElementParameter(EParameterName.PARALLELIZE_NUMBER.getName());
        if (numberParallelizeParameter != null) {
            numberParallel = (String) numberParallelizeParameter.getValue();
        }
        //$NON-NLS-1$
        String paralString = "x" + numberParallel;
        parallelFigure.setText(paralString);
        parallelFigure.setToolTip(new Label(paralString));
        parallelFigure.setVisible(true);
    } else {
        parallelFigure.setVisible(false);
    }
}
Also used : Label(org.eclipse.draw2d.Label) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 8 with IElementParameter

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

the class JobletUtil method cloneNode.

public Node cloneNode(Node node, IProcess process, Map<String, List<? extends IElementParameter>> paraMap, boolean lockByOther) {
    NodePart nodePart = new NodePart();
    IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
    boolean isInOut = false;
    if (service != null) {
        isInOut = service.isJobletInOutComponent(node);
    }
    Node cloneNode = new Node(node.getComponent(), (IProcess2) process, node.getUniqueName());
    nodePart.setModel(cloneNode);
    if (lockByOther) {
        cloneNode.setReadOnly(true);
    } else {
        cloneNode.setReadOnly(false);
    }
    cloneNode.setDummy(node.isDummy());
    cloneNode.setActivate(node.isActivate());
    List<? extends IElementParameter> elementParas = null;
    if (paraMap.containsKey(node.getUniqueName())) {
        elementParas = paraMap.get(node.getUniqueName());
    } else {
        elementParas = node.getElementParameters();
    }
    for (IElementParameter elementPara : elementParas) {
        if (elementPara.getName() != null && !elementPara.getName().equals("UNIQUE_NAME")) {
            IElementParameter cloneElement = cloneNode.getElementParameter(elementPara.getName());
            Object paValue = elementPara.getValue();
            if (paValue instanceof List) {
                List list = new ArrayList();
                list.addAll((List) paValue);
                cloneElement.setValue(list);
            } else {
                // TDI-25599
                cloneElement.setContextMode(elementPara.isContextMode());
                cloneElement.setValue(elementPara.getValue());
            }
            if (lockByOther) {
                cloneElement.setReadOnly(true);
            } else {
                cloneElement.setReadOnly(elementPara.isReadOnly());
            }
            if (elementPara.getChildParameters() != null) {
                Map<String, IElementParameter> elementParaChild = elementPara.getChildParameters();
                Map<String, IElementParameter> cloneElementChild = cloneElement.getChildParameters();
                Iterator<Entry<String, IElementParameter>> ite = elementParaChild.entrySet().iterator();
                while (ite.hasNext()) {
                    Entry<String, IElementParameter> entry = ite.next();
                    String key = entry.getKey();
                    IElementParameter c = entry.getValue();
                    if (key != null && c != null) {
                        IElementParameter cloneC = cloneElementChild.get(key);
                        if (cloneC != null) {
                            cloneC.setValue(c.getValue());
                            if (lockByOther) {
                                cloneC.setReadOnly(true);
                            } else {
                                cloneC.setReadOnly(c.isReadOnly());
                            }
                        }
                    }
                }
            }
        }
    }
    for (IElementParameter param : cloneNode.getElementParameters()) {
        String repositoryValue = param.getRepositoryValue();
        if (param.isShow(cloneNode.getElementParameters()) && (repositoryValue != null) && (!param.getName().equals(EParameterName.PROPERTY_TYPE.getName())) && param.getFieldType() != EParameterFieldType.MEMO_SQL) {
            param.setRepositoryValueUsed(true);
            param.setReadOnly(true);
        }
    }
    cloneNode.setMetadataList(node.getMetadataList());
    cloneNode.setListConnector(node.getListConnector());
    cloneNode.setConnectionName(node.getConnectionName());
    cloneNode.setLocation(node.getLocation());
    IExternalNode externalNode = cloneNode.getExternalNode();
    if (externalNode != null) {
        if (node.getExternalData() != null) {
            try {
                externalNode.setExternalData(node.getExternalData().clone());
            } catch (CloneNotSupportedException e) {
                ExceptionHandler.process(e);
            }
            cloneNode.setExternalData(externalNode.getExternalData());
        }
        if (node.getExternalNode().getExternalEmfData() != null) {
            externalNode.setExternalEmfData(EcoreUtil.copy(node.getExternalNode().getExternalEmfData()));
        }
        // when copy a external node, should also copy screeshot
        if (node.getExternalNode() != null) {
            ImageDescriptor screenshot = node.getExternalNode().getScreenshot();
            if (screenshot != null) {
                externalNode.setScreenshot(screenshot);
            }
        }
    }
    if (node.getElementParameter(EParameterName.LABEL.getName()) != null) {
        cloneNode.setPropertyValue(EParameterName.LABEL.getName(), node.getElementParameter(EParameterName.LABEL.getName()).getValue());
    } else {
        cloneNode.setPropertyValue(EParameterName.LABEL.getName(), node.getLabel());
    }
    boolean found = false;
    for (INode inode : process.getGraphicalNodes()) {
        if (inode.getUniqueName().equals(cloneNode.getUniqueName())) {
            found = true;
        }
    }
    if (!found) {
        ((IProcess2) process).removeUniqueNodeName(cloneNode.getUniqueName());
    }
    return cloneNode;
}
Also used : INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) JobletNode(org.talend.designer.joblet.model.JobletNode) ArrayList(java.util.ArrayList) IJobletProviderService(org.talend.core.ui.IJobletProviderService) Entry(java.util.Map.Entry) IProcess2(org.talend.core.model.process.IProcess2) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) IExternalNode(org.talend.core.model.process.IExternalNode)

Example 9 with IElementParameter

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

the class GuessSchemaProcess method buildProcess.

private void buildProcess() {
    process = new Process(property);
    process.getContextManager().getListContext().addAll(node.getProcess().getContextManager().getListContext());
    process.getContextManager().setDefaultContext(this.selectContext);
    outputComponent = ComponentsFactoryProvider.getInstance().get(EDatabaseComponentName.FILEDELIMITED.getOutPutComponentName(), ComponentCategory.CATEGORY_4_DI.getName());
    if (node.getModulesNeeded().size() > 0 && !node.getComponent().getName().equals("tRedshiftInput")) {
        //$NON-NLS-1$
        for (ModuleNeeded module : node.getModulesNeeded()) {
            if (module.isRequired(node.getElementParameters())) {
                Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
                NodeContainer nc = process.loadNodeContainer(libNode1, false);
                process.addNodeContainer(nc);
            }
        }
    } else {
        // hywang add for 9594
        if (node.getComponent().getName().equals("tJDBCInput") || node.getComponent().getName().equals("tRedshiftInput")) {
            List<String> drivers = EDatabaseVersion4Drivers.getDrivers(info.getTrueDBTypeForJDBC(), info.getDbVersion());
            String moduleNeedName = "";
            Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE, ComponentCategory.CATEGORY_4_DI.getName()), process);
            if (drivers.size() > 0) {
                // use the first driver as defalult.
                // added for bug 13592
                moduleNeedName = drivers.get(0).toString();
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                libNode1.setPropertyValue("LIBRARY", "\"" + moduleNeedName + "\"");
            }
            process.addNodeContainer(new NodeContainer(libNode1));
        }
    }
    INode connectionNode = null;
    IElementParameter existConnection = node.getElementParameter("USE_EXISTING_CONNECTION");
    boolean useExistConnection = (existConnection == null ? false : (Boolean) existConnection.getValue());
    if (useExistConnection) {
        IElementParameter connector = node.getElementParameter("CONNECTION");
        if (connector != null) {
            String connectorValue = connector.getValue().toString();
            List<? extends INode> generatingNodes = originalProcess.getGeneratingNodes();
            for (INode node : generatingNodes) {
                if (node.getUniqueName().equals(connectorValue)) {
                    connectionNode = node;
                    break;
                }
            }
        }
    }
    List<ModuleNeeded> neededLibraries = new ArrayList<ModuleNeeded>();
    JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, node);
    for (ModuleNeeded module : neededLibraries) {
        Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
        //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
        process.addNodeContainer(new NodeContainer(libNode1));
    }
    if (connectionNode != null) {
        neededLibraries = new ArrayList<ModuleNeeded>();
        JavaProcessUtil.addNodeRelatedModules(process, neededLibraries, connectionNode);
        for (ModuleNeeded module : neededLibraries) {
            Node libNode1 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            libNode1.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
            process.addNodeContainer(new NodeContainer(libNode1));
        }
    }
    // create the tLibraryLoad for the output component which is "tFileOutputDelimited"
    for (ModuleNeeded module : outputComponent.getModulesNeeded()) {
        Node libNode2 = new Node(ComponentsFactoryProvider.getInstance().get(LIB_NODE), process);
        //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        libNode2.setPropertyValue("LIBRARY", "\"" + module.getModuleName() + "\"");
        process.addNodeContainer(new NodeContainer(libNode2));
    }
    // for sql statement, feature 6622.
    int fetchSize = maximumRowsToPreview;
    if (maximumRowsToPreview > 1000) {
        fetchSize = 1000;
    }
    String codeStart, codeMain, codeEnd;
    temppath = buildTempCSVFilename();
    // Should also replace "/r". NMa.
    // ISO-8859-15
    memoSQL = memoSQL.replace("\r", " ");
    // fix for TDI-26285
    //$NON-NLS-1$
    String createStatament = "conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY)";
    //$NON-NLS-1$ 
    String systemProperty = "";
    if (info.isHive()) {
        //$NON-NLS-1$ 
        createStatament = "conn.createStatement()";
        systemProperty = //$NON-NLS-1$ //$NON-NLS-2$ 
        "System.setProperty(\"mapred.job.tracker\",\"" + info.getJobTracker() + "\");\r\n" + "System.setProperty(\"fs.default.name\", \"" + info.getNameNode() + //$NON-NLS-1$ //$NON-NLS-2$ 
        "\");\r\n";
        // only embeded hive need the following params
        if (info.getThrifturi() != null) {
            systemProperty = //$NON-NLS-1$ 
            systemProperty + " System.setProperty(\"hive.metastore.local\", \"false\");\r\n" + " System.setProperty(\"hive.metastore.uris\", \"" + info.getThrifturi() + //$NON-NLS-1$ //$NON-NLS-2$ 
            "\");\r\n" + //$NON-NLS-1$ 
            "System.setProperty(\"hive.metastore.execute.setugi\", \"true\");\r\n";
        }
    }
    // add for bug TDI-27137 by fwang on 27 August, 2013.
    EDatabaseTypeName dbType = EDatabaseTypeName.JAVADB_EMBEDED.getTypeFromDbType(info.getDbType());
    if (EDatabaseTypeName.JAVADB_EMBEDED.equals(dbType)) {
        IElementParameter dbPathElement = node.getElementParameter("DBPATH");
        if (dbPathElement != null) {
            String derbyPath = dbPathElement.getValue().toString().replace("\"", "").trim();
            systemProperty = systemProperty + "System.setProperty(\"derby.system.home\",\"" + derbyPath + "\");\r\n";
        }
    }
    // the Sqlite
    if (EDatabaseTypeName.SQLITE.getXmlName().equals(info.getDbType())) {
        createStatament = "conn.createStatement()";
    }
    // the VERTICA
    if (ConnectionUtils.isVertica(info.getUrl())) {
        createStatament = "conn.createStatement()";
    }
    if (EDatabaseTypeName.GENERAL_JDBC.getXmlName().equals(info.getDbType()) && "com.sap.db.jdbc.Driver".equals(info.getDriverClassName()) || EDatabaseTypeName.SAPHana.getXmlName().equals(info.getDbType())) {
        createStatament = "conn.createStatement()";
    }
    codeStart = systemProperty + getCodeStart(connectionNode, createStatament, fetchSize);
    codeMain = //$NON-NLS-1$ //$NON-NLS-2$
    "String[] dataOneRow = new String[numbOfColumn];\r\n" + "for (int i = 1; i <= numbOfColumn; i++) {\r\n" + "    \r\n" + " try{\r\n" + "    String tempStr = rs.getString(i);\r\n" + "    dataOneRow[i-1] = tempStr;\r\n" + "      } catch (java.sql.SQLException e) {\r\n" + "}\r\n" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "}\r\n" + //$NON-NLS-1$
    "csvWriter.writeNext(dataOneRow);";
    if (EDatabaseTypeName.REDSHIFT.getXmlName().equals(info.getDbType())) {
        codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "nbRows++;\r\n" + "    if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
        "csvWriter.close();\r\n";
    } else {
        codeEnd = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "nbRows++;\r\n" + "    if (nbRows > " + maximumRowsToPreview + ") break;\r\n" + "}\r\n" + "conn.close();\r\n" + //$NON-NLS-1$ //$NON-NLS-2$
        "csvWriter.close();\r\n";
    }
    IComponent component = null;
    switch(LanguageManager.getCurrentLanguage()) {
        case JAVA:
            //$NON-NLS-1$
            component = ComponentsFactoryProvider.getInstance().get("tJavaFlex");
            break;
        case PERL:
        default:
            //$NON-NLS-1$
            component = ComponentsFactoryProvider.getInstance().get("tPerlFlex");
            break;
    }
    Node flexNode = new Node(component, process);
    //$NON-NLS-1$
    flexNode.setPropertyValue("CODE_START", codeStart);
    //$NON-NLS-1$
    flexNode.setPropertyValue("CODE_MAIN", codeMain);
    //$NON-NLS-1$
    flexNode.setPropertyValue("CODE_END", codeEnd);
    process.addNodeContainer(new NodeContainer(flexNode));
}
Also used : INode(org.talend.core.model.process.INode) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IElementParameter(org.talend.core.model.process.IElementParameter) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 10 with IElementParameter

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

the class HadoopJarSetupController 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) {
    final Composite container = subComposite;
    //$NON-NLS-1$
    Button subButton = getWidgetFactory().createButton(container, "", SWT.PUSH);
    subButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            initHadoopVersionType();
            boolean readonly = false;
            String readOnlyIfString = param.getReadOnlyIf();
            if (StringUtils.isNotEmpty(readOnlyIfString)) {
                if (param.isReadOnly(elem.getElementParameters())) {
                    readonly = true;
                }
            }
            // if readonly is true, then needn't to do this check, since it's aim is check readonly also
            if (readonly == false) {
                IElementParameter propertyParameter = elem.getElementParameter(EParameterName.PROPERTY_TYPE.getName());
                if (propertyParameter != null) {
                    if (EmfComponent.REPOSITORY.equals(propertyParameter.getValue())) {
                        readonly = true;
                    }
                }
            }
            HadoopCustomVersionDefineDialog customVersionDialog = new HadoopCustomVersionDefineDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), getCustomVersionMap()) {

                @Override
                protected ECustomVersionType[] getDisplayTypes() {
                    return new ECustomVersionType[] { versionType };
                }
            };
            IElementParameter sparkLocalParam = elem.getElementParameter(HadoopConstants.SPARK_LOCAL_MODE);
            IElementParameter sparkParam = elem.getElementParameter(HadoopConstants.SPARK_MODE);
            boolean isSparkLocalMode = false;
            if (sparkLocalParam != null) {
                isSparkLocalMode = (Boolean) sparkLocalParam.getValue();
            }
            if (sparkParam != null) {
                String sparkMode = null;
                if (isSparkLocalMode) {
                    //$NON-NLS-1$
                    sparkMode = "LOCAL";
                } else {
                    //$NON-NLS-1$
                    sparkMode = "" + sparkParam.getValue();
                }
                customVersionDialog.setSparkMode(sparkMode);
                customVersionDialog.setSparkStreamingMode(sparkMode);
            }
            customVersionDialog.setReadonly(readonly);
            Set<String> oldLibList = customVersionDialog.getLibList(versionType.getGroup());
            if (customVersionDialog.open() == Window.OK) {
                Set<String> newLibList = customVersionDialog.getLibList(versionType.getGroup());
                if (oldLibList != null && newLibList != null && oldLibList.size() == newLibList.size() && oldLibList.containsAll(newLibList)) {
                // means nothing changes, so nothing need to do
                } else {
                    // changed
                    String customJars = customVersionDialog.getLibListStr(versionType.getGroup());
                    executeCommand(new PropertyChangeCommand(elem, EParameterName.HADOOP_CUSTOM_JARS.getName(), StringUtils.trimToEmpty(customJars)));
                }
            }
        }
    });
    subButton.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    FormData data = new FormData();
    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;
    subButton.setLayoutData(data);
    return container;
}
Also used : FormData(org.eclipse.swt.layout.FormData) HashSet(java.util.HashSet) Set(java.util.Set) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) HadoopCustomVersionDefineDialog(org.talend.core.hadoop.version.custom.HadoopCustomVersionDefineDialog) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IElementParameter(org.talend.core.model.process.IElementParameter) FormAttachment(org.eclipse.swt.layout.FormAttachment)

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