Search in sources :

Example 66 with IConnection

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

the class ChangeActivateStatusElementCommand method dummyMiddleElement.

private void dummyMiddleElement(boolean undo) {
    Map<List<INode>, List<IConnection>> middConnMap = getAllMiddleConnections();
    Set<Entry<List<INode>, List<IConnection>>> middSet = middConnMap.entrySet();
    Iterator<Entry<List<INode>, List<IConnection>>> middIte = middSet.iterator();
    List<IConnection> notSameForConn = new ArrayList<IConnection>();
    List<INode> notSameForNode = new ArrayList<INode>();
    List<Node> connNodeList = new ArrayList<Node>();
    while (middIte.hasNext()) {
        Entry<List<INode>, List<IConnection>> entry = middIte.next();
        List<INode> nodeList = entry.getKey();
        List<IConnection> connList = entry.getValue();
        if (nodeList.size() == 2) {
            INode firNode = nodeList.get(0);
            INode secNode = nodeList.get(1);
            if (!notSameForNode.contains(firNode)) {
                notSameForNode.add(firNode);
            }
            if (!notSameForNode.contains(secNode)) {
                notSameForNode.add(secNode);
            }
            for (IConnection conn : connList) {
                if (!notSameForConn.contains(conn)) {
                    notSameForConn.add(conn);
                } else {
                    continue;
                }
                Node source = (Node) conn.getSource();
                if (source.getUniqueName() != firNode.getUniqueName() && (source.getUniqueName() != secNode.getUniqueName())) {
                    if (isSameSchemaInputOutput(source)) {
                        conn.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
                        source.setPropertyValue(EParameterName.DUMMY.getName(), true);
                        // source.setPropertyValue(EParameterName.ACTIVATE.getName(), source.isActivate());
                        connNodeList.add(source);
                    }
                }
                Node target = (Node) conn.getTarget();
                if (target.getUniqueName() != firNode.getUniqueName() && (target.getUniqueName() != secNode.getUniqueName())) {
                    if (isSameSchemaInputOutput(target)) {
                        conn.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
                        target.setPropertyValue(EParameterName.DUMMY.getName(), true);
                        // target.setPropertyValue(EParameterName.ACTIVATE.getName(), target.isActivate());
                        connNodeList.add(target);
                    }
                }
            }
        }
    }
    for (Node node : connNodeList) {
        node.setPropertyValue(EParameterName.ACTIVATE.getName(), node.isActivate());
    }
    if (!value) {
        for (Node node : nodeList) {
            if (node.isActivate()) {
                continue;
            }
            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();
            while (outIte.hasNext()) {
                Entry<IConnection, Node> en = outIte.next();
                IConnection enConn = en.getKey();
                if (!notSameForConn.contains(enConn)) {
                    // if (enConn.isActivate()) {
                    enConn.setPropertyValue(EParameterName.ACTIVATE.getName(), value);
                    if (!notSameForNode.contains(enConn.getTarget()) && !hasActivateInputOutput((Node) enConn.getTarget())) {
                        enConn.getTarget().setPropertyValue(EParameterName.DUMMY.getName(), value);
                    }
                // }
                }
            }
            Set<Entry<IConnection, Node>> inSet = inMiddleNodes.entrySet();
            Iterator<Entry<IConnection, Node>> inIte = inSet.iterator();
            while (inIte.hasNext()) {
                Entry<IConnection, Node> en = inIte.next();
                IConnection enConn = en.getKey();
                if (!notSameForConn.contains(enConn)) {
                    // if (enConn.isActivate()) {
                    enConn.setPropertyValue(EParameterName.ACTIVATE.getName(), value);
                    if (!notSameForNode.contains(enConn.getSource()) && !hasActivateInputOutput((Node) enConn.getSource())) {
                        enConn.getSource().setPropertyValue(EParameterName.DUMMY.getName(), value);
                    }
                // }
                }
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) 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) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List)

Example 67 with IConnection

use of org.talend.core.model.process.IConnection 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 68 with IConnection

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

the class ChangeMergeOrderCommand method reOrder.

private List<Map<String, Object>> reOrder(List<Map<String, Object>> values) {
    List<Map<String, Object>> newValues = new ArrayList<Map<String, Object>>();
    if (values == null || values.isEmpty()) {
        return newValues;
    }
    List<? extends IConnection> incomingConnections = this.mergeNode.getIncomingConnections();
    for (IConnection conn : incomingConnections) {
        if (conn.getLineStyle().hasConnectionCategory(org.talend.core.model.process.IConnectionCategory.FLOW)) {
            String uniqueName = conn.getUniqueName();
            List<Map<String, Object>> findConnValue = findConnValue(values, uniqueName);
            if (findConnValue != null) {
                newValues.addAll(findConnValue);
            }
        }
    }
    return newValues;
}
Also used : ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Map(java.util.Map)

Example 69 with IConnection

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

the class CodeGenerator method getIncomingNameForMerge.

/**
     * get the incomingName matching with inputId. Purpose: It will generate different parts for the merge node
     * according the different incomingName.
     * 
     * @param branchStartNode
     * @param mergeNode
     * @return
     */
private String getIncomingNameForMerge(INode branchStartNode, INode mergeNode) {
    Map<INode, Integer> mergeInfo = branchStartNode.getLinkedMergeInfo();
    int inputId = ((Integer) mergeInfo.values().toArray()[0]).intValue();
    List<? extends IConnection> incomingConnections = mergeNode.getIncomingConnections();
    for (int i = 0; i < incomingConnections.size(); i++) {
        IConnection connec = incomingConnections.get(i);
        if (connec.isActivate()) {
            if (connec.getLineStyle().hasConnectionCategory(EConnectionType.MERGE)) {
                // if find, then return
                if (connec.getInputId() == inputId) {
                    return connec.getName();
                }
            }
        }
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection)

Example 70 with IConnection

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

the class NodeConnectionsHelper method initOutputConnections.

/**
	 * Inits the {@link #dataOutputs}, {@link #connResponse}, {@link #connFault}
	 * connections.
	 */
private void initOutputConnections() {
    List<? extends IConnection> conns = node.getOutgoingSortedConnections();
    dataOutputs = new ArrayList<IConnection>();
    if (conns != null) {
        for (IConnection conn : conns) {
            if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
                dataOutputs.add(conn);
            }
        }
    }
    List<? extends IConnection> connsResponse = node.getOutgoingConnections("RESPONSE");
    List<? extends IConnection> connsFault = node.getOutgoingConnections("FAULT");
    if (connsResponse.size() == 1) {
        connResponse = connsResponse.get(0);
    }
    if (connsFault.size() == 1) {
        connFault = connsFault.get(0);
    }
}
Also used : IConnection(org.talend.core.model.process.IConnection)

Aggregations

IConnection (org.talend.core.model.process.IConnection)149 ArrayList (java.util.ArrayList)79 INode (org.talend.core.model.process.INode)63 List (java.util.List)60 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)57 Node (org.talend.designer.core.ui.editor.nodes.Node)47 HashMap (java.util.HashMap)36 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)33 IElementParameter (org.talend.core.model.process.IElementParameter)31 Map (java.util.Map)25 Connection (org.talend.designer.core.ui.editor.connections.Connection)25 INodeConnector (org.talend.core.model.process.INodeConnector)24 Point (org.eclipse.swt.graphics.Point)13 Process (org.talend.designer.core.ui.editor.process.Process)13 IJobletProviderService (org.talend.core.ui.IJobletProviderService)12 HashSet (java.util.HashSet)11 MetadataTable (org.talend.core.model.metadata.MetadataTable)10 IProcess (org.talend.core.model.process.IProcess)10 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)9 IExternalNode (org.talend.core.model.process.IExternalNode)8