Search in sources :

Example 1 with ConnectionContainerUI

use of org.knime.core.ui.node.workflow.ConnectionContainerUI in project knime-core by knime.

the class HorizAlignManager method adjustBendPoints.

private void adjustBendPoints(final NodeContainerEditPart node, final int offset) {
    NodeContainerUI nc = node.getNodeContainer();
    Set<ConnectionContainerUI> inConns = m_wfm.getIncomingConnectionsFor(nc.getID());
    for (ConnectionContainerUI conn : inConns) {
        ConnectionUIInformation ui = conn.getUIInfo();
        if (ui == null) {
            // easy: no bend points
            continue;
        }
        // incoming connections: look at the last bend point
        int bendPointIdx = ui.getAllBendpoints().length - 1;
        if (bendPointIdx < 0) {
            continue;
        }
        int[] bendPnt = ui.getBendpoint(bendPointIdx);
        int portY = getPortMiddle(getInPortFig(node, conn.getDestPort()));
        if (portY < 0) {
            // port not found.
            continue;
        }
        if (portY + 1 < bendPnt[1] || portY - 1 > bendPnt[1]) {
            // only move bendpoints (nearly) at the same line as the port
            continue;
        }
        int[] newBendPnt = new int[] { bendPnt[0], bendPnt[1] + offset };
        // see if this connection was already moved
        if (m_oldBendpoints.get(conn.getID()) == null) {
            m_oldBendpoints.put(conn.getID(), ui);
        }
        ConnectionUIInformation.Builder newUIBuilder = ConnectionUIInformation.builder(ui);
        newUIBuilder.removeBendpoint(bendPointIdx);
        newUIBuilder.addBendpoint(newBendPnt[0], newBendPnt[1], bendPointIdx);
        LOGGER.debug("Node: " + nc + ", replacing bendpoint " + bendPointIdx + " " + bendPnt[0] + "," + bendPnt[1] + " with " + newBendPnt[0] + "," + newBendPnt[1]);
        conn.setUIInfo(newUIBuilder.build());
    }
    Set<ConnectionContainerUI> outConns = m_wfm.getOutgoingConnectionsFor(nc.getID());
    for (ConnectionContainerUI conn : outConns) {
        ConnectionUIInformation ui = conn.getUIInfo();
        if (ui == null || ui.getAllBendpoints().length == 0) {
            // easy: no bend points
            continue;
        }
        // outgoing connections: look at the first bend point
        int bendPointIdx = 0;
        int[] bendPnt = ui.getBendpoint(bendPointIdx);
        int portY = getPortMiddle(getOutPortFig(node, conn.getSourcePort()));
        if (portY < 0) {
            // port not found.
            continue;
        }
        if (portY + 1 < bendPnt[1] || portY - 1 > bendPnt[1]) {
            // only move bendpoints (nearly) at the same line as the port
            continue;
        }
        int[] newBendPnt = new int[] { bendPnt[0], bendPnt[1] + offset };
        // see if this connection was already moved
        if (m_oldBendpoints.get(conn.getID()) == null) {
            m_oldBendpoints.put(conn.getID(), ui);
        }
        ConnectionUIInformation.Builder newUIBuilder = ConnectionUIInformation.builder(ui);
        newUIBuilder.removeBendpoint(bendPointIdx);
        newUIBuilder.addBendpoint(newBendPnt[0], newBendPnt[1], bendPointIdx);
        LOGGER.debug("Node: " + nc + ", replacing bendpoint " + bendPointIdx + " " + bendPnt[0] + "," + bendPnt[1] + " with " + newBendPnt[0] + "," + newBendPnt[1]);
        conn.setUIInfo(newUIBuilder.build());
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI)

Example 2 with ConnectionContainerUI

use of org.knime.core.ui.node.workflow.ConnectionContainerUI in project knime-core by knime.

the class WorkflowEditPartFactory method createEditPart.

/**
 * Creates the referring edit parts for the following parts of the model.
 * <ul>
 * <li>{@link WorkflowManager}: either {@link WorkflowRootEditPart} or {@link NodeContainerEditPart} (depending on
 * the currently displayed level)</li>
 * <li>{@link SingleNodeContainer}: {@link NodeContainerEditPart}</li>
 * <li>{@link NodeInPort}: {@link NodeInPortEditPart}</li>
 * <li>{@link NodeOutPort}: {@link NodeOutPortEditPart}</li>
 * <li>{@link ConnectionContainer}: {@link ConnectionContainerEditPart}</li>
 * <li>{@link WorkflowInPort}: {@link WorkflowInPortEditPart}</li>
 * <li>{@link WorkflowOutPort}: {@link WorkflowOutPortEditPart}</li>
 * </ul>
 *
 * The {@link WorkflowRootEditPart} has its {@link NodeContainer}s and its {@link WorkflowInPort}s and
 * {@link WorkflowOutPort}s as model children. The {@link NodeContainerEditPart} has its {@link NodePort}s as its
 * children.
 *
 * @see WorkflowRootEditPart#getModelChildren()
 * @see NodeContainerEditPart#getModelChildren()
 *
 * @throws IllegalArgumentException if any other object is passed
 *
 *             {@inheritDoc}
 */
@Override
public EditPart createEditPart(final EditPart context, final Object model) {
    // instantiated here
    // correct type in the if statement
    // model at the end of method
    EditPart part = null;
    if (model instanceof WorkflowManagerUI) {
        // this is out "root" workflow manager
        if (m_isTop) {
            // all following objects of type WorkflowManager are treated as
            // metanodes and displayed as NodeContainers
            m_isTop = false;
            part = new WorkflowRootEditPart();
        } else {
            // we already have a "root" workflow manager
            // must be a metanode
            part = new SubworkflowEditPart();
        }
    } else if (model instanceof NodeAnnotation) {
        /* IMPORTANT: first test NodeAnnotation then Annotation (as the
             * first derives from the latter! */
        part = new NodeAnnotationEditPart();
    } else if (model instanceof Annotation) {
        /* IMPORTANT: first test NodeAnnotation then Annotation (as the
             * first derives from the latter! */
        /* workflow annotations hang off the workflow manager */
        part = new AnnotationEditPart();
    } else if (model instanceof WorkflowPortBar) {
        WorkflowPortBar bar = (WorkflowPortBar) model;
        if (bar.isInPortBar()) {
            part = new WorkflowInPortBarEditPart();
        } else {
            part = new WorkflowOutPortBarEditPart();
        }
    } else if (model instanceof SingleNodeContainerUI) {
        // SingleNodeContainer -> NodeContainerEditPart
        part = new NodeContainerEditPart();
    // we have to test for WorkflowInPort first because it's a
    // subclass of NodeInPort (same holds for WorkflowOutPort and
    // NodeOutPort)
    } else if (model instanceof WorkflowInPortUI && context instanceof WorkflowInPortBarEditPart) {
        // WorkflowInPort and context WorkflowRootEditPart ->
        // WorkflowInPortEditPart
        /*
             * if the context is a WorkflowRootEditPart it indicates that the
             * WorkflowInPort is a model child of the WorkflowRootEditPart, i.e.
             * we look at it as a workflow in port. If the context is a
             * NodeContainerEditPart the WorkflowInPort is a model child of a
             * NodeContainerEditPart and we look at it as a node in port.
             */
        WorkflowInPortUI inport = (WorkflowInPortUI) model;
        part = new WorkflowInPortEditPart(inport.getPortType(), inport.getPortIndex());
    } else if (model instanceof WorkflowOutPortUI && context instanceof WorkflowOutPortBarEditPart) {
        // WorkflowOutPort and context WorkflowRootEditPart ->
        // WorkflowOutPortEditPart
        /*
             * if the context is a WorkflowRootEditPart it indicates that the
             * WorkflowOutPort is a model child of the WorkflowRootEditPart,
             * i.e. we look at it as a workflow out port. If the context is a
             * NodeContainerEditPart the WorkflowOutPort is a model child of a
             * NodeContainerEditPart and we look at it as a node out port.
             */
        // TODO: return SubWorkFlowOutPortEditPart
        WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
        part = new WorkflowOutPortEditPart(outport.getPortType(), outport.getPortIndex());
    } else if (model instanceof WorkflowOutPortUI) {
        // TODO: return SubWorkFlowOutPortEditPart
        WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
        part = new MetaNodeOutPortEditPart(outport.getPortType(), outport.getPortIndex());
    } else if (model instanceof NodeInPortUI) {
        // NodeInPort -> NodeInPortEditPart
        NodePortUI port = (NodeInPortUI) model;
        part = new NodeInPortEditPart(port.getPortType(), port.getPortIndex());
    } else if (model instanceof NodeOutPortUI) {
        // NodeOutPort -> NodeOutPortEditPart
        NodePortUI port = (NodeOutPortUI) model;
        part = new NodeOutPortEditPart(port.getPortType(), port.getPortIndex());
    } else if (model instanceof ConnectionContainerUI) {
        // ConnectionContainer -> ConnectionContainerEditPart
        part = new ConnectionContainerEditPart();
    } else {
        throw new IllegalArgumentException("unknown model obj: " + model);
    }
    // associate the model with the part (= the controller)
    part.setModel(model);
    return part;
}
Also used : SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) WorkflowOutPortUI(org.knime.core.ui.node.workflow.WorkflowOutPortUI) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation) NodeInPortUI(org.knime.core.ui.node.workflow.NodeInPortUI) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) NodeOutPortUI(org.knime.core.ui.node.workflow.NodeOutPortUI) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) WorkflowInPortUI(org.knime.core.ui.node.workflow.WorkflowInPortUI) NodePortUI(org.knime.core.ui.node.workflow.NodePortUI)

Example 3 with ConnectionContainerUI

use of org.knime.core.ui.node.workflow.ConnectionContainerUI in project knime-core by knime.

the class LayoutManager method doLayout.

/**
 * @param nodes the nodes that should be laid out. If null, all nodes of the
 *            workflow manager passed to the constructor are laid out.
 */
public void doLayout(final Collection<NodeContainerUI> nodes) {
    int X_STRETCH = 100;
    int Y_STRETCH = 120;
    if (WorkflowEditor.getActiveEditorSnapToGrid()) {
        if (WorkflowEditor.getActiveEditorGridX() >= 70) {
            X_STRETCH = WorkflowEditor.getActiveEditorGridX();
        } else {
            X_STRETCH = WorkflowEditor.getActiveEditorGridXOffset(X_STRETCH);
        }
        Y_STRETCH = WorkflowEditor.getActiveEditorGridYOffset(Y_STRETCH);
    }
    // add all nodes that should be laid out to the graph
    Collection<NodeContainerUI> allNodes = nodes;
    if (allNodes == null || allNodes.size() <= 1) {
        allNodes = m_wfm.getNodeContainers();
    }
    // keep the left upper corner of the node cluster.
    // Nodes laid out are placed right and below
    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    // add all nodes that are to be laid out
    for (NodeContainerUI nc : allNodes) {
        Node gNode = createGraphNodeForNC(nc);
        m_workbenchToGraphNodes.put(nc, gNode);
        NodeUIInformation ui = nc.getUIInformation();
        minX = (ui.getBounds()[0] < minX) ? ui.getBounds()[0] : minX;
        minY = (ui.getBounds()[1] < minY) ? ui.getBounds()[1] : minY;
        if (WorkflowEditor.getActiveEditorSnapToGrid()) {
            Point nextGridLocation = WorkflowEditor.getActiveEditorNextGridLocation(new Point(minX, minY));
            minX = nextGridLocation.x;
            minY = nextGridLocation.y;
        }
    }
    // find all connections that connect from/to our nodes,
    // keep a flag that states: isClusterInternal
    HashMap<ConnectionContainerUI, Boolean> allConns = new HashMap<ConnectionContainerUI, Boolean>();
    for (ConnectionContainerUI conn : m_wfm.getConnectionContainers()) {
        Node src = null;
        if (!conn.getSource().equals(m_wfm.getID())) {
            // if it's not a meta node incoming connection
            src = m_workbenchToGraphNodes.get(m_wfm.getNodeContainer(conn.getSource()));
        }
        Node dest = null;
        if (!conn.getDest().equals(m_wfm.getID())) {
            // if it is not a meta node outgoing connection
            dest = m_workbenchToGraphNodes.get(m_wfm.getNodeContainer(conn.getDest()));
        }
        boolean isInternal = (src != null && dest != null);
        // if at least one node is auto laid out we need the connection
        if (src != null || dest != null) {
            allConns.put(conn, isInternal);
        }
    }
    // Add all connections (internal and leading in/out the cluster)
    // to the graph
    Edge gEdge;
    for (ConnectionContainerUI conn : allConns.keySet()) {
        Node srcGraphNode;
        Node destGraphNode;
        if (conn.getSource().equals(m_wfm.getID())) {
            // it connects to a meta node input port:
            int portIdx = conn.getSourcePort();
            srcGraphNode = m_workbenchWFMInports.get(portIdx);
            if (srcGraphNode == null) {
                srcGraphNode = m_g.createNode("Incoming " + portIdx, 0, portIdx * Y_STRETCH);
                m_workbenchWFMInports.put(portIdx, srcGraphNode);
            }
        } else {
            NodeContainerUI s = m_wfm.getNodeContainer(conn.getSource());
            srcGraphNode = m_workbenchToGraphNodes.get(s);
            if (srcGraphNode == null) {
                // then it connects to an "outside" node
                srcGraphNode = m_workbenchIncomingNodes.get(s);
                if (srcGraphNode == null) {
                    srcGraphNode = createGraphNodeForNC(s);
                    m_workbenchIncomingNodes.put(s, srcGraphNode);
                }
            }
        // else it is a connection inside the layout cluster
        }
        if (conn.getDest().equals(m_wfm.getID())) {
            // it connects to a meta node output port
            int portIdx = conn.getDestPort();
            destGraphNode = m_workbenchWFMOutports.get(portIdx);
            if (destGraphNode == null) {
                destGraphNode = m_g.createNode("Outgoing " + portIdx, 250, portIdx * Y_STRETCH);
                m_workbenchWFMOutports.put(portIdx, destGraphNode);
            }
        } else {
            NodeContainerUI d = m_wfm.getNodeContainer(conn.getDest());
            destGraphNode = m_workbenchToGraphNodes.get(d);
            if (destGraphNode == null) {
                // then it connects to an "outside" node
                destGraphNode = m_workbenchOutgoingNodes.get(d);
                if (destGraphNode == null) {
                    destGraphNode = createGraphNodeForNC(d);
                    m_workbenchOutgoingNodes.put(d, destGraphNode);
                }
            }
        // else it is a connection within the layout cluster
        }
        gEdge = m_g.createEdge(srcGraphNode, destGraphNode);
        if (gEdge != null) {
            m_workbenchToGraphEdges.put(conn, gEdge);
            m_parallelConns.put(gEdge, new LinkedList<ConnectionContainerUI>(Collections.singletonList(conn)));
        } else {
            // a connection between these node already exists in the graph
            Edge graphEdge = srcGraphNode.getEdge(destGraphNode);
            assert graphEdge != null;
            // add the connection to list of parallel connections.
            m_parallelConns.get(graphEdge).add(conn);
        }
    }
    // AFTER creating all nodes, mark the incoming/outgoing nodes as fixed
    boolean anchorsExist = false;
    Map<Node, Boolean> anchorNodes = m_g.createBoolNodeMap();
    for (Node n : m_workbenchIncomingNodes.values()) {
        anchorsExist = true;
        anchorNodes.put(n, Boolean.TRUE);
    }
    for (Node n : m_workbenchOutgoingNodes.values()) {
        anchorsExist = true;
        anchorNodes.put(n, Boolean.TRUE);
    }
    for (Node n : m_workbenchWFMInports.values()) {
        anchorsExist = true;
        anchorNodes.put(n, Boolean.TRUE);
    }
    for (Node n : m_workbenchWFMOutports.values()) {
        anchorsExist = true;
        anchorNodes.put(n, Boolean.TRUE);
    }
    SimpleLayeredLayouter layouter = new SimpleLayeredLayouter(m_initPlacementSeed);
    layouter.setBalanceBranchings(!WorkflowEditor.getActiveEditorSnapToGrid());
    if (anchorsExist) {
        layouter.doLayout(m_g, anchorNodes);
    } else {
        layouter.doLayout(m_g, null);
    }
    // preserver the old stuff for undoers
    m_oldBendpoints = new HashMap<ConnectionID, ConnectionUIInformation>();
    m_oldCoordinates = new HashMap<NodeID, NodeUIInformation>();
    // transfer new coordinates back to nodes
    // with fixed nodes (lots of) the new coordinates of the nodes may not
    // start at 0.
    double coordOffsetX = Integer.MAX_VALUE;
    double coordOffsetY = Integer.MAX_VALUE;
    for (NodeContainerUI nc : allNodes) {
        Node gNode = m_workbenchToGraphNodes.get(nc);
        coordOffsetX = Math.min(coordOffsetX, m_g.getX(gNode));
        coordOffsetY = Math.min(coordOffsetY, m_g.getY(gNode));
    }
    for (NodeContainerUI nc : allNodes) {
        NodeUIInformation uiInfo = nc.getUIInformation();
        if (uiInfo != null) {
            Node gNode = m_workbenchToGraphNodes.get(nc);
            int[] b = uiInfo.getBounds();
            int x = (int) Math.round((m_g.getX(gNode) - coordOffsetX) * X_STRETCH) + minX;
            int y = (int) Math.round((m_g.getY(gNode) - coordOffsetY) * Y_STRETCH) + minY;
            NodeUIInformation newCoord = NodeUIInformation.builder().setNodeLocation(x, y, b[2], b[3]).setHasAbsoluteCoordinates(uiInfo.hasAbsoluteCoordinates()).setSnapToGrid(WorkflowEditor.getActiveEditorSnapToGrid()).build();
            LOGGER.debug("Node " + nc + " gets auto-layout coordinates " + newCoord);
            // save old coordinates for undo
            m_oldCoordinates.put(nc.getID(), uiInfo);
            // triggers gui update
            nc.setUIInformation(newCoord);
        }
    }
    // delete old bendpoints - transfer new ones
    for (ConnectionContainerUI conn : allConns.keySet()) {
        // store old bendpoint for undo
        ConnectionUIInformation ui = conn.getUIInfo();
        if (ui != null) {
            m_oldBendpoints.put(conn.getID(), ui);
        } else {
            m_oldBendpoints.put(conn.getID(), null);
        }
        ConnectionUIInformation.Builder newUIBuilder = ConnectionUIInformation.builder();
        Edge e = m_workbenchToGraphEdges.get(conn);
        if (e == null) {
            // a parallel connection not represented by the edge
            continue;
        }
        List<ConnectionContainerUI> conns = m_parallelConns.get(e);
        assert conns.size() > 0;
        // that is how we created it!
        assert conns.get(0) == conn;
        ArrayList<Point2D> newBends = m_g.bends(e);
        if (newBends != null && !newBends.isEmpty()) {
            // half the node icon size...
            int extraX = 16;
            int extraY = 24;
            for (int i = 0; i < newBends.size(); i++) {
                Point2D b = newBends.get(i);
                newUIBuilder.addBendpoint((int) Math.round((b.getX() - coordOffsetX) * X_STRETCH) + extraX + minX, (int) Math.round((b.getY() - coordOffsetY) * Y_STRETCH) + extraY + minY, i);
            }
        }
        ConnectionUIInformation newUI = newUIBuilder.build();
        conn.setUIInfo(newUI);
        // compute bendpoints for parallel connections (slightly offset)
        for (int i = 1; i < conns.size(); i++) {
            // idx 0 == conn!
            ConnectionContainerUI parConn = conns.get(i);
            // destination port determines offset
            int yOffset = (parConn.getDestPort() - conn.getDestPort()) * 10;
            ConnectionUIInformation parUI = ConnectionUIInformation.builder(newUI).translate(new int[] { 0, yOffset }).build();
            parConn.setUIInfo(parUI);
        }
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) HashMap(java.util.HashMap) Node(org.knime.workbench.ui.layout.Graph.Node) Point2D(java.awt.geom.Point2D) NodeID(org.knime.core.node.workflow.NodeID) SimpleLayeredLayouter(org.knime.workbench.ui.layout.layeredlayout.SimpleLayeredLayouter) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI) ConnectionID(org.knime.core.node.workflow.ConnectionID) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) Edge(org.knime.workbench.ui.layout.Graph.Edge)

Example 4 with ConnectionContainerUI

use of org.knime.core.ui.node.workflow.ConnectionContainerUI in project knime-core by knime.

the class AbstractWorkflowPortBarEditPart method getMinMaxXcoordInWorkflow.

/**
 * returns the minX coordinate and the maxX coordinate of all nodes, annotations and bendpoints in the flow (taking
 * the size of the elements into account). Or Integer.MIN/MAX_value if no elements exist.
 * @return new int[] {minX, maxX};
 */
protected int[] getMinMaxXcoordInWorkflow() {
    int maxX = Integer.MIN_VALUE;
    int minX = Integer.MAX_VALUE;
    // find the smallest and the biggest X coordinate in all the UI infos in the flow
    WorkflowManagerUI manager = ((WorkflowPortBar) getModel()).getWorkflowManager();
    for (NodeContainerUI nc : manager.getNodeContainers()) {
        int nodeWidth = NodeContainerFigure.WIDTH;
        NodeAnnotation nodeAnno = nc.getNodeAnnotation();
        if ((nodeAnno != null) && (nodeAnno.getWidth() > nodeWidth)) {
            nodeWidth = nodeAnno.getWidth();
        }
        NodeUIInformation uiInfo = nc.getUIInformation();
        if (uiInfo != null) {
            int x = uiInfo.getBounds()[0];
            // right border of node
            x = x + (nodeWidth / 2);
            if (maxX < x) {
                maxX = x;
            }
            // left border of node
            x = x - nodeWidth;
            if (minX > x) {
                minX = x;
            }
        }
    }
    for (WorkflowAnnotation anno : manager.getWorkflowAnnotations()) {
        int x = anno.getX();
        if (minX > x) {
            minX = x;
        }
        x = x + anno.getWidth();
        if (maxX < x) {
            maxX = x;
        }
    }
    for (ConnectionContainerUI conn : manager.getConnectionContainers()) {
        ConnectionUIInformation uiInfo = conn.getUIInfo();
        if (uiInfo != null) {
            int[][] bendpoints = uiInfo.getAllBendpoints();
            if (bendpoints != null) {
                for (int[] b : bendpoints) {
                    if (maxX < b[0]) {
                        maxX = b[0];
                    }
                    if (minX > b[0]) {
                        minX = b[0];
                    }
                }
            }
        }
    }
    return new int[] { minX, maxX };
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Aggregations

ConnectionContainerUI (org.knime.core.ui.node.workflow.ConnectionContainerUI)4 ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)3 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)3 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)2 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)2 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)2 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)2 Point2D (java.awt.geom.Point2D)1 HashMap (java.util.HashMap)1 Point (org.eclipse.draw2d.geometry.Point)1 EditPart (org.eclipse.gef.EditPart)1 Annotation (org.knime.core.node.workflow.Annotation)1 ConnectionID (org.knime.core.node.workflow.ConnectionID)1 NodeID (org.knime.core.node.workflow.NodeID)1 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)1 NodeInPortUI (org.knime.core.ui.node.workflow.NodeInPortUI)1 NodeOutPortUI (org.knime.core.ui.node.workflow.NodeOutPortUI)1 NodePortUI (org.knime.core.ui.node.workflow.NodePortUI)1 SingleNodeContainerUI (org.knime.core.ui.node.workflow.SingleNodeContainerUI)1 WorkflowInPortUI (org.knime.core.ui.node.workflow.WorkflowInPortUI)1