Search in sources :

Example 6 with NodeContainer

use of org.talend.designer.core.ui.editor.nodecontainer.NodeContainer 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 7 with NodeContainer

use of org.talend.designer.core.ui.editor.nodecontainer.NodeContainer in project tdi-studio-se by Talend.

the class ChangeActivateStatusElementCommand method getAllMiddleConnections.

private Map<List<INode>, List<IConnection>> getAllMiddleConnections() {
    Map<List<INode>, List<IConnection>> middConnMap = new HashMap<List<INode>, List<IConnection>>();
    Process process;
    if (nodeList.size() > 0) {
        process = (Process) nodeList.get(0).getProcess();
    } else {
        process = (Process) connectionList.get(0).getSource().getProcess();
    }
    List<? extends INode> nodes = process.getGraphicalNodes();
    List<INode> jobletandnodeList = new ArrayList<INode>();
    for (INode node : nodes) {
        if (((Node) node).isJoblet() && !((Node) node).getNodeContainer().isCollapsed() && (((Node) node).getNodeContainer() instanceof AbstractJobletContainer)) {
            for (NodeContainer nc : ((AbstractJobletContainer) ((Node) node).getNodeContainer()).getNodeContainers()) {
                jobletandnodeList.add(nc.getNode());
            }
        } else {
            jobletandnodeList.add(node);
        }
    }
    for (INode node : jobletandnodeList) {
        if (node.isActivate()) {
            Map<IConnection, Node> outMiddleNodes = getAllOutMiddleNodes(node);
            Map<IConnection, Node> inMiddleNodes = getAllInMiddleNodes(node);
            Set<Entry<IConnection, Node>> outSet = outMiddleNodes.entrySet();
            Iterator<Entry<IConnection, Node>> outIte = outSet.iterator();
            boolean haveActivateTarget = false;
            List<INode> nodeList = new ArrayList<INode>();
            List<IConnection> connList = new ArrayList<IConnection>();
            while (outIte.hasNext()) {
                Entry<IConnection, Node> en = outIte.next();
                Node enNode = en.getValue();
                IConnection enConn = en.getKey();
                if (enNode != null) {
                    haveActivateTarget = true;
                    if (!nodeList.contains(node)) {
                        nodeList.add(node);
                    }
                    if (!nodeList.contains(enNode)) {
                        nodeList.add(enNode);
                    }
                }
                if (enConn != null && !connList.contains(enConn)) {
                    connList.add(enConn);
                }
            }
            if (!haveActivateTarget) {
                outMiddleNodes.clear();
            }
            if (!nodeList.isEmpty() && !connList.isEmpty()) {
                Set<Entry<List<INode>, List<IConnection>>> middSet = middConnMap.entrySet();
                Iterator<Entry<List<INode>, List<IConnection>>> middIte = middSet.iterator();
                boolean exist = false;
                while (middIte.hasNext()) {
                    Entry<List<INode>, List<IConnection>> entry = middIte.next();
                    List<INode> enNodeList = entry.getKey();
                    if (enNodeList.size() == 2 && nodeList.size() == 2) {
                        if (enNodeList.get(0).getUniqueName().equals(nodeList.get(1).getUniqueName()) && enNodeList.get(1).getUniqueName().equals(nodeList.get(0).getUniqueName())) {
                            exist = true;
                        } else if (enNodeList.get(0).getUniqueName().equals(nodeList.get(0).getUniqueName()) && enNodeList.get(1).getUniqueName().equals(nodeList.get(1).getUniqueName())) {
                            exist = true;
                        }
                    }
                }
                if (!exist) {
                    middConnMap.put(nodeList, connList);
                }
            }
            Set<Entry<IConnection, Node>> inSet = inMiddleNodes.entrySet();
            Iterator<Entry<IConnection, Node>> inIte = inSet.iterator();
            boolean haveActivateSource = false;
            nodeList = new ArrayList<INode>();
            connList = new ArrayList<IConnection>();
            while (inIte.hasNext()) {
                Entry<IConnection, Node> en = inIte.next();
                Node enNode = en.getValue();
                IConnection enConn = en.getKey();
                if (enNode != null) {
                    haveActivateSource = true;
                    if (!nodeList.contains(node)) {
                        nodeList.add(node);
                    }
                    if (!nodeList.contains(enNode)) {
                        nodeList.add(enNode);
                    }
                }
                if (enConn != null && !connList.contains(enConn)) {
                    connList.add(enConn);
                }
            }
            if (!haveActivateSource) {
                inMiddleNodes.clear();
            }
            if (!nodeList.isEmpty() && !connList.isEmpty()) {
                Set<Entry<List<INode>, List<IConnection>>> middSet = middConnMap.entrySet();
                Iterator<Entry<List<INode>, List<IConnection>>> middIte = middSet.iterator();
                boolean exist = false;
                while (middIte.hasNext()) {
                    Entry<List<INode>, List<IConnection>> entry = middIte.next();
                    List<INode> enNodeList = entry.getKey();
                    if (enNodeList.size() == 2 && nodeList.size() == 2) {
                        if (enNodeList.get(0).getUniqueName().equals(nodeList.get(1).getUniqueName()) && enNodeList.get(1).getUniqueName().equals(nodeList.get(0).getUniqueName())) {
                            exist = true;
                        } else if (enNodeList.get(0).getUniqueName().equals(nodeList.get(0).getUniqueName()) && enNodeList.get(1).getUniqueName().equals(nodeList.get(1).getUniqueName())) {
                            exist = true;
                        }
                    }
                }
                if (!exist) {
                    middConnMap.put(nodeList, connList);
                }
            }
        }
    }
    return middConnMap;
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Process(org.talend.designer.core.ui.editor.process.Process) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with NodeContainer

use of org.talend.designer.core.ui.editor.nodecontainer.NodeContainer in project tdi-studio-se by Talend.

the class NodeProgressBarPart method refreshVisuals.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editparts.AbstractEditPart#refreshVisuals()
     */
@Override
protected void refreshVisuals() {
    Node node = ((NodeContainer) ((NodeContainerPart) getParent()).getModel()).getNode();
    NodeLabel nodeLabel = node.getNodeLabel();
    NodeProgressBarFigure progressFig = (NodeProgressBarFigure) this.getFigure();
    Point loc = node.getLocation().getCopy();
    NodeError nodeError = node.getNodeError();
    Dimension size = progressFig.getSize();
    loc.x = loc.x + (node.getSize().width - size.width) / 2 + size.width / 7;
    loc.y = loc.y + node.getSize().height + nodeLabel.getLabelSize().height + nodeError.getErrorSize().height;
    Rectangle rectangle = new Rectangle(loc, size);
    ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), rectangle);
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart)

Example 9 with NodeContainer

use of org.talend.designer.core.ui.editor.nodecontainer.NodeContainer in project tdi-studio-se by Talend.

the class NodeResizableEditPolicy method getResizeCommand.

@Override
protected Command getResizeCommand(ChangeBoundsRequest request) {
    Object parent = getHost().getParent().getModel();
    if (!(parent instanceof NodeContainer)) {
        return null;
    }
    Node node = (Node) getHost().getModel();
    if (node.isReadOnly()) {
        return null;
    }
    TalendScalableFreeformRootEditPart rootEditPart = (TalendScalableFreeformRootEditPart) getHost().getRoot();
    double scale = 1 / rootEditPart.getZoomManager().getZoom();
    return new ResizeNodeCommand(node, new Dimension(node.getSize().width + request.getSizeDelta().getScaled(scale).width, node.getSize().height + request.getSizeDelta().getScaled(scale).height));
}
Also used : TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ResizeNodeCommand(org.talend.designer.core.ui.editor.cmd.ResizeNodeCommand) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 10 with NodeContainer

use of org.talend.designer.core.ui.editor.nodecontainer.NodeContainer in project tdi-studio-se by Talend.

the class NodesMoveCommond method execute.

@SuppressWarnings("unchecked")
@Override
public void execute() {
    // create the node container list to paste
    createNodeContainerList();
    AbstractMultiPageTalendEditor multiPageTalendEditor = (AbstractMultiPageTalendEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    GraphicalViewer viewer = multiPageTalendEditor.getTalendEditor().getViewer();
    // save old selection
    if (!multipleCommand) {
        oldSelection = new ArrayList<EditPart>();
        for (EditPart editPart : (List<EditPart>) viewer.getSelectedEditParts()) {
            oldSelection.add(editPart);
        }
        // remove the old selection
        viewer.deselectAll();
    }
    // creates the different nodes
    for (NodeContainer nodeContainer : nodeContainerList) {
        ((Process) process).addNodeContainer(nodeContainer);
    }
    // check that the created connections exists now, or create them if needed
    for (String newConnectionName : createdNames) {
        if (process.checkValidConnectionName(newConnectionName, true)) {
            process.addUniqueConnectionName(newConnectionName);
        }
    }
    process.checkStartNodes();
    process.checkProcess();
    // set the new node as the current selection
    if (!multipleCommand) {
        EditPart processPart = (EditPart) viewer.getRootEditPart().getChildren().get(0);
        if (processPart instanceof ProcessPart) {
            // can only be
            // ProcessPart but still
            // test
            List<EditPart> sel = new ArrayList<EditPart>();
            for (EditPart editPart : (List<EditPart>) processPart.getChildren()) {
                if (editPart instanceof SubjobContainerPart) {
                    for (EditPart subjobChildsPart : (List<EditPart>) editPart.getChildren()) {
                        if (subjobChildsPart instanceof NodeContainerPart) {
                            if (nodeContainerList.contains(((NodeContainerPart) subjobChildsPart).getModel())) {
                                NodePart nodePart = ((NodeContainerPart) subjobChildsPart).getNodePart();
                                if (nodePart != null) {
                                    sel.add(nodePart);
                                }
                            }
                        }
                    }
                }
                if (editPart instanceof NodePart) {
                    Node currentNode = (Node) editPart.getModel();
                    if (nodeContainerList.contains(currentNode.getNodeContainer())) {
                        sel.add(editPart);
                    }
                }
            }
            StructuredSelection s = new StructuredSelection(sel);
            viewer.setSelection(s);
        }
    }
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) EditPart(org.eclipse.gef.EditPart) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) List(java.util.List) ArrayList(java.util.ArrayList) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart)

Aggregations

NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)60 Node (org.talend.designer.core.ui.editor.nodes.Node)43 ArrayList (java.util.ArrayList)23 INode (org.talend.core.model.process.INode)23 List (java.util.List)20 Process (org.talend.designer.core.ui.editor.process.Process)20 Point (org.eclipse.draw2d.geometry.Point)17 IComponent (org.talend.core.model.components.IComponent)13 IConnection (org.talend.core.model.process.IConnection)12 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)12 Rectangle (org.eclipse.draw2d.geometry.Rectangle)11 IProcess (org.talend.core.model.process.IProcess)11 Connection (org.talend.designer.core.ui.editor.connections.Connection)11 IElementParameter (org.talend.core.model.process.IElementParameter)10 EditPart (org.eclipse.gef.EditPart)9 IExternalNode (org.talend.core.model.process.IExternalNode)9 IGraphicalNode (org.talend.core.ui.process.IGraphicalNode)9 CreateNodeContainerCommand (org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand)9 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)9 HashMap (java.util.HashMap)8