Search in sources :

Example 36 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 37 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 38 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 39 with NodeContainer

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

the class ProcessLayoutEditPolicy method getCreateCommand.

// ------------------------------------------------------------------------
// Abstract methods from LayoutEditPolicy
/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest)
     */
@Override
protected Command getCreateCommand(final CreateRequest request) {
    if (((Process) getHost().getModel()).isReadOnly()) {
        return null;
    }
    Rectangle constraint = (Rectangle) getConstraintFor(request);
    Command command = null;
    if (Note.class.equals(request.getNewObjectType())) {
        command = new CreateNoteCommand((Process) getHost().getModel(), (Note) request.getNewObject(), constraint.getLocation());
    } else if (request.getNewObject() instanceof Node) {
        Node node = (Node) request.getNewObject();
        NodeContainer nodeContainer = ((Process) node.getProcess()).loadNodeContainer(node, false);
        command = new CreateNodeContainerCommand((Process) getHost().getModel(), nodeContainer, constraint.getLocation());
    }
    return command;
}
Also used : CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) CreateNoteCommand(org.talend.designer.core.ui.editor.cmd.CreateNoteCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) MoveNodeCommand(org.talend.designer.core.ui.editor.cmd.MoveNodeCommand) MoveNoteCommand(org.talend.designer.core.ui.editor.cmd.MoveNoteCommand) Command(org.eclipse.gef.commands.Command) Note(org.talend.designer.core.ui.editor.notes.Note) Node(org.talend.designer.core.ui.editor.nodes.Node) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) Rectangle(org.eclipse.draw2d.geometry.Rectangle) CreateNoteCommand(org.talend.designer.core.ui.editor.cmd.CreateNoteCommand) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)

Example 40 with NodeContainer

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

the class ProcessLayoutEditPolicy method createChangeConstraintCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChangeConstraintCommand(org.eclipse.gef.EditPart,
     * java.lang.Object)
     */
@Override
public Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
    // return a command to move the part to the location given by the constraint
    if (child instanceof NodePart) {
        if (((Node) child.getModel()).isReadOnly()) {
            return null;
        }
        MoveNodeCommand locationCommand = new MoveNodeCommand((Node) child.getModel(), ((Rectangle) constraint).getLocation());
        return locationCommand;
    }
    if (child instanceof NoteEditPart) {
        if (((Note) child.getModel()).isReadOnly()) {
            return null;
        }
        MoveNoteCommand locationCommand = new MoveNoteCommand((Note) child.getModel(), ((Rectangle) constraint).getLocation());
        return locationCommand;
    }
    if (child instanceof SubjobContainerPart) {
        SubjobContainer sjc = (SubjobContainer) child.getModel();
        Point sjcLocation = sjc.getSubjobContainerRectangle().getLocation();
        Point translationNeeded = new Point(((Rectangle) constraint).getLocation().x - sjcLocation.x, ((Rectangle) constraint).getLocation().y - sjcLocation.y);
        CompoundCommand cc = new CompoundCommand();
        for (NodeContainer nc : sjc.getNodeContainers()) {
            if (nc.isReadOnly()) {
                return null;
            }
            IGraphicalNode node = nc.getNode();
            Point nodeLocation = node.getLocation();
            MoveNodeCommand locationCommand = new MoveNodeCommand(nc.getNode(), nodeLocation.getTranslated(translationNeeded));
            cc.add(locationCommand);
        }
        return cc;
    }
    return null;
}
Also used : MoveNodeCommand(org.talend.designer.core.ui.editor.cmd.MoveNodeCommand) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) Node(org.talend.designer.core.ui.editor.nodes.Node) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) Note(org.talend.designer.core.ui.editor.notes.Note) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) MoveNoteCommand(org.talend.designer.core.ui.editor.cmd.MoveNoteCommand) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Point(org.eclipse.draw2d.geometry.Point) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

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