Search in sources :

Example 26 with NodeContainer

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

the class JobletContainer method changeWidth.

private void changeWidth(Rectangle totalRectangle) {
    if (!this.node.isMapReduce()) {
        return;
    }
    Rectangle oracleRec = totalRectangle.getCopy();
    boolean subjobCollapsed = false;
    if (this.node.getNodeContainer().getSubjobContainer() != null) {
        subjobCollapsed = this.node.getNodeContainer().getSubjobContainer().isCollapsed();
    }
    int temWidth = 114;
    if (isMRGroupContainesReduce() && !subjobCollapsed) {
        temWidth = 240;
    }
    if (totalRectangle.width < temWidth && this.getNode().isMapReduceStart()) {
        Integer distance = null;
        for (NodeContainer nc : this.getSubjobContainer().getNodeContainers()) {
            if (nc.getNode().getUniqueName().equals(this.getNode().getUniqueName())) {
                continue;
            }
            if (this.getNode().getMrGroupId() != null && nc.getNode().getMrGroupId() != null && this.getNode().getMrGroupId().equals(nc.getNode().getMrGroupId())) {
                continue;
            }
            int w = nc.getNodeContainerRectangle().x - totalRectangle.x;
            if (w <= 0) {
                continue;
            }
            if (totalRectangle.y + totalRectangle.height < nc.getNodeContainerRectangle().y) {
                continue;
            }
            if (totalRectangle.y > nc.getNodeContainerRectangle().y + nc.getNodeContainerRectangle().height) {
                continue;
            }
            if (distance == null) {
                distance = w;
            } else if (w < distance) {
                distance = w;
            }
            if (totalRectangle.contains(nc.getNodeContainerRectangle().getLocation())) {
                distance = w;
            }
        }
        // } else
        if (temWidth == 240 && (temWidth > this.getNodeContainerRectangle().width)) {
            int dis = temWidth - oracleRec.width;
            if (totalRectangle.x > dis / 2) {
                totalRectangle.x = totalRectangle.x - dis / 2;
                if (distance != null) {
                    if (distance < this.getNodeContainerRectangle().width) {
                        distance = this.getNodeContainerRectangle().width;
                    }
                    distance = distance + dis / 2;
                }
            }
        }
        // if (distance == null) {
        totalRectangle.width = temWidth;
    // } else if (distance >= temWidth) {
    // totalRectangle.width = temWidth;
    // } else if (distance < totalRectangle.width) {
    // return;
    // } else {
    // totalRectangle.width = distance;
    // }
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Point(org.eclipse.draw2d.geometry.Point)

Example 27 with NodeContainer

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

the class JobletContainer method refreshJobletNodes.

public void refreshJobletNodes(boolean update, boolean coll) {
    if (this.node.isJoblet()) {
        if (!coll || update) {
            boolean componentUpdated = false;
            IComponent oldComponent = node.getComponent();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IJobletProviderService.class)) {
                IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                IComponent newComponent = service.getUpdatedJobletComponent(oldComponent);
                if (oldComponent != newComponent) {
                    node.setComponent(newComponent);
                    componentUpdated = true;
                }
            }
            JobletUtil util = new JobletUtil();
            IProcess jobletProcess = this.getNode().getComponent().getProcess();
            Set<IConnection> conns = new HashSet<IConnection>();
            List<? extends INode> jobletNodes = jobletProcess.getGraphicalNodes();
            boolean lockByOther = false;
            if (jobletProcess instanceof IProcess2) {
                lockByOther = util.lockByOthers(((IProcess2) jobletProcess).getProperty().getItem());
            }
            Map<String, List<? extends IElementParameter>> paraMap = new HashMap<String, List<? extends IElementParameter>>();
            // List<NodeContainer> temList = new ArrayList<NodeContainer>(nodeContainers);
            if (!componentUpdated) {
                for (NodeContainer nc : nodeContainers) {
                    if (this.node.getProcess() instanceof IProcess2) {
                        if (!update) {
                            paraMap.put(nc.getNode().getJoblet_unique_name(), nc.getNode().getElementParameters());
                        }
                        ((IProcess2) this.node.getProcess()).removeUniqueNodeName(nc.getNode().getUniqueName());
                    }
                }
            }
            nodeContainers.clear();
            jobletElements.clear();
            // boolean canRemove = false;
            for (INode inode : jobletNodes) {
                // canAdd = util.canAdd(temList, inode);
                if ((inode instanceof Node)) {
                    Node temNode = (Node) inode;
                    // if (canAdd) {
                    conns.addAll(temNode.getIncomingConnections());
                    conns.addAll(temNode.getOutgoingConnections());
                    Node jnode = util.cloneNode(temNode, this.node.getProcess(), paraMap, lockByOther);
                    if (!this.node.isActivate()) {
                        jnode.setActivate(this.node.isActivate());
                    }
                    NodeContainer nodeContainer = util.cloneNodeContainer(temNode.getNodeContainer(), jnode);
                    jnode.setJobletnode(this.node);
                    jnode.setJoblet_unique_name(temNode.getUniqueName());
                    this.nodeContainers.add(nodeContainer);
                    this.jobletElements.add(jnode);
                    this.jobletElements.add(jnode.getNodeLabel());
                    this.jobletElements.add(jnode.getNodeError());
                    this.jobletElements.add(jnode.getNodeProgressBar());
                // } else if (update) {
                // for (NodeContainer nodeC : nodeContainers) {
                // if (nodeC.getNode().getJoblet_unique_name().equals(temNode.getUniqueName())) {
                // util.updateNode(nodeC.getNode(), temNode);
                // break;
                // }
                // }
                // }
                }
            }
            // }
            for (IConnection con : conns) {
                String sourceName = con.getSource().getUniqueName();
                String targetName = con.getTarget().getUniqueName();
                Node sourceNode = null;
                Node targetNode = null;
                for (NodeContainer nodeC : nodeContainers) {
                    Node connNode = nodeC.getNode();
                    if (connNode.getJoblet_unique_name().equals(sourceName)) {
                        sourceNode = connNode;
                    }
                    if (connNode.getJoblet_unique_name().equals(targetName)) {
                        targetNode = connNode;
                    }
                    if (sourceNode != null && targetNode != null) {
                        util.cloneConnection(con, sourceNode, targetNode);
                        break;
                    }
                }
            }
        }
    } else if (this.node.isMapReduceStart()) {
        Integer mrGroupId = node.getMrGroupId();
        List<? extends INode> mapReduceNodes = this.node.getProcess().getGraphicalNodes();
        List<Node> nodeList = new ArrayList<Node>();
        if (node.getNodeContainer().getSubjobContainer() != null && node.getNodeContainer().getSubjobContainer().isCollapsed()) {
            nodeList.add(node);
        } else {
            for (INode inode : mapReduceNodes) {
                if ((inode instanceof Node)) {
                    Node temNode = (Node) inode;
                    if (temNode.getMrGroupId() != null && mrGroupId != null && temNode.getMrGroupId().equals(mrGroupId)) {
                        nodeList.add(temNode);
                    }
                }
            }
        }
        nodeContainers.clear();
        jobletElements.clear();
        for (Node inode : nodeList) {
            if (!inode.isActivate()) {
                continue;
            }
            NodeContainer nodeContainer = inode.getNodeContainer();
            // inode.setJoblet_unique_name(inode.getUniqueName());
            if (nodeContainer instanceof JobletContainer) {
                ((JobletContainer) nodeContainer).setMrStartContainer(this);
            }
            this.nodeContainers.add(nodeContainer);
            this.jobletElements.add(inode);
            this.jobletElements.add(inode.getNodeLabel());
            this.jobletElements.add(inode.getNodeError());
            this.jobletElements.add(inode.getNodeProgressBar());
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IProcess2(org.talend.core.model.process.IProcess2) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IProcess(org.talend.core.model.process.IProcess) HashSet(java.util.HashSet)

Example 28 with NodeContainer

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

the class JobletContainer method transferLocation.

private void transferLocation(boolean update) {
    this.update = update;
    if (update) {
    // do nothing
    }
    if ((this.isCollapsed() == true)) {
        // && !this.getNode().isMapReduceStart()
        return;
    }
    if (this.getNode().isMapReduce()) {
        return;
    }
    if (this.nodeContainers.size() <= 0) {
        return;
    }
    Point oragPoint = this.getNode().getLocation();
    Node startNode = getJobletStartNode();
    if (startNode == null) {
        return;
    }
    Point stratPoint = startNode.getLocation();
    int withe_x = oragPoint.x - stratPoint.x;
    int hight_y = oragPoint.y - stratPoint.y;
    for (NodeContainer nodeCon : this.nodeContainers) {
        Node jobNode = nodeCon.getNode();
        if (jobNode.getJoblet_unique_name() != null && jobNode.getJoblet_unique_name().equals(startNode.getUniqueName())) {
            jobNode.setLocation(oragPoint);
        } else {
            Point nodePoint = jobNode.getLocation();
            jobNode.setLocation(new Point(nodePoint.x + withe_x, nodePoint.y + hight_y));
            hasChange = true;
        }
    }
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 29 with NodeContainer

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

the class JobletContainer method transferLocation.

public void transferLocation(Point oldPos) {
    this.update = false;
    if ((this.isCollapsed() == true)) {
        // && !this.getNode().isMapReduceStart()
        return;
    }
    if (this.getNode().isMapReduce()) {
        return;
    }
    if (this.nodeContainers.size() <= 0) {
        return;
    }
    Point oragPoint = this.getNode().getLocation();
    Node startNode = getJobletStartNode();
    if (startNode == null) {
        return;
    }
    // Point stratPoint = startNode.getLocation();
    int withe_x = oragPoint.x - oldPos.x;
    int hight_y = oragPoint.y - oldPos.y;
    for (NodeContainer nodeCon : this.nodeContainers) {
        Node jobNode = nodeCon.getNode();
        if (jobNode.getJoblet_unique_name().equals(startNode.getUniqueName())) {
            jobNode.setLocation(oragPoint);
        } else {
            Point nodePoint = jobNode.getLocation();
            jobNode.setLocation(new Point(nodePoint.x + withe_x, nodePoint.y + hight_y));
        }
    }
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 30 with NodeContainer

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

the class JobletContainer method canCollapse.

public boolean canCollapse() {
    List<String> connList = new ArrayList<String>();
    List<String> triConnList = new ArrayList<String>();
    List<String> metaList = new ArrayList<String>();
    if (node.getIncomingConnections().size() > 1) {
        for (IConnection conn : node.getIncomingConnections()) {
            if (conn.getConnectorName().startsWith("TRIGGER")) {
                metaList.add(conn.getMetaName());
            }
        }
        for (NodeContainer nodeContainer : this.nodeContainers) {
            Node connNode = nodeContainer.getNode();
            IElementParameter elePa = this.node.getElementParameter(connNode.getJoblet_unique_name());
            if (elePa != null) {
                boolean isTri = false;
                IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                if (service != null) {
                    isTri = service.isTriggerNode(connNode);
                }
                if (isTri) {
                    IElementParameter elechild = elePa.getChildParameters().get("COMPONENT_LIST");
                    if (elechild != null) {
                        if (elechild.getValue() == null || ((String) elechild.getValue()).length() <= 0) {
                            return false;
                        } else {
                            if (triConnList.contains(elechild.getValue())) {
                                return false;
                            } else {
                                triConnList.add((String) elechild.getValue());
                            }
                        }
                        if (elechild.getValue() != null && (elechild.getValue() instanceof String)) {
                            metaList.remove(elechild.getValue());
                        }
                    }
                } else {
                    IElementParameter elechild = elePa.getChildParameters().get("CONNECTION");
                    if (elechild != null) {
                        if ((elechild.getValue() == null || "".equals(elechild.getValue()))) {
                            return false;
                        } else {
                            if (elechild.getValue() instanceof String) {
                                if (connList.contains(elechild.getValue())) {
                                    return false;
                                } else {
                                    connList.add((String) elechild.getValue());
                                }
                            }
                        }
                    }
                }
            }
        }
        if (metaList.size() > 0) {
            return false;
        }
    }
    return true;
}
Also used : IJobletProviderService(org.talend.core.ui.IJobletProviderService) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) IConnection(org.talend.core.model.process.IConnection) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)

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