Search in sources :

Example 26 with NodeUIInformation

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

the class HorizAlignCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    Map<NodeID, NodeUIInformation> oldPositions = m_alignMgr.getOldNodeCoordinates();
    Map<ConnectionID, ConnectionUIInformation> oldBendpoints = m_alignMgr.getOldBendpoints();
    // re-position nodes
    for (Map.Entry<NodeID, NodeUIInformation> e : oldPositions.entrySet()) {
        NodeContainer nc = m_wfm.getNodeContainer(e.getKey());
        if (nc == null) {
            continue;
        }
        nc.setUIInformation(e.getValue());
    }
    // re-create bendpoints
    for (Map.Entry<ConnectionID, ConnectionUIInformation> e : oldBendpoints.entrySet()) {
        ConnectionContainer cc = m_wfm.getConnection(e.getKey());
        if (cc == null) {
            continue;
        }
        cc.setUIInfo(e.getValue());
    }
}
Also used : ConnectionID(org.knime.core.node.workflow.ConnectionID) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeID(org.knime.core.node.workflow.NodeID) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) NodeContainer(org.knime.core.node.workflow.NodeContainer) Map(java.util.Map)

Example 27 with NodeUIInformation

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

the class VerticAlignCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    Map<NodeID, NodeUIInformation> oldPositions = m_alignMgr.getOldNodeCoordinates();
    Map<ConnectionID, ConnectionUIInformation> oldBendpoints = m_alignMgr.getOldBendpoints();
    // re-position nodes
    for (Map.Entry<NodeID, NodeUIInformation> e : oldPositions.entrySet()) {
        NodeContainer nc = m_wfm.getNodeContainer(e.getKey());
        if (nc == null) {
            continue;
        }
        nc.setUIInformation(e.getValue());
    }
    // re-create bendpoints
    for (Map.Entry<ConnectionID, ConnectionUIInformation> e : oldBendpoints.entrySet()) {
        ConnectionContainer cc = m_wfm.getConnection(e.getKey());
        if (cc == null) {
            continue;
        }
        cc.setUIInfo(e.getValue());
    }
}
Also used : ConnectionID(org.knime.core.node.workflow.ConnectionID) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeID(org.knime.core.node.workflow.NodeID) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) NodeContainer(org.knime.core.node.workflow.NodeContainer) Map(java.util.Map)

Example 28 with NodeUIInformation

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

the class ReplaceHelper method reconnect.

/**
 * Connects new node with connection of the old node.
 *
 * @param container new node container
 */
public void reconnect(final NodeContainer container) {
    // reset node location
    NodeUIInformation uiInformation = m_oldNode.getUIInformation();
    int[] bounds = uiInformation.getBounds();
    NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(bounds[0], bounds[1], -1, -1).setHasAbsoluteCoordinates(true).setSnapToGrid(uiInformation.getSnapToGrid()).setIsDropLocation(false).build();
    container.setUIInformation(info);
    int inShift;
    int outShift;
    if (m_oldNode instanceof WorkflowManager && !(container instanceof WorkflowManager)) {
        inShift = 0;
        // replacing a metanode (no opt. flow var ports) with a "normal" node (that has optional flow var ports)
        if (m_oldNode.getNrInPorts() > 0 && container.getNrInPorts() > 1) {
            // shift ports one index - unless we need to use the invisible optional flow var port of new node
            if (!m_oldNode.getInPort(0).getPortType().equals(FlowVariablePortObject.TYPE)) {
                inShift = 1;
            } else if (container.getInPort(1).getPortType().equals(FlowVariablePortObject.TYPE)) {
                inShift = 1;
            }
        }
        outShift = 0;
        if (m_oldNode.getNrOutPorts() > 0 && container.getNrOutPorts() > 1) {
            if (!m_oldNode.getOutPort(0).getPortType().equals(FlowVariablePortObject.TYPE)) {
                outShift = 1;
            } else if (container.getOutPort(1).getPortType().equals(FlowVariablePortObject.TYPE)) {
                outShift = 1;
            }
        }
    } else if (!(m_oldNode instanceof WorkflowManager) && container instanceof WorkflowManager) {
        // replacing a "normal" node with a metanode
        inShift = -1;
        for (ConnectionContainer cc : m_incomingConnections) {
            if (cc.getDestPort() == 0) {
                inShift = 0;
                break;
            }
        }
        outShift = -1;
        for (ConnectionContainer cc : m_outgoingConnections) {
            if (cc.getSourcePort() == 0) {
                outShift = 0;
                break;
            }
        }
    } else {
        inShift = 0;
        outShift = 0;
    }
    // set incoming connections
    NodeID newId = container.getID();
    for (ConnectionContainer c : m_incomingConnections) {
        if (m_wfm.canAddConnection(c.getSource(), c.getSourcePort(), newId, c.getDestPort() + inShift)) {
            m_wfm.addConnection(c.getSource(), c.getSourcePort(), newId, c.getDestPort() + inShift);
        } else {
            break;
        }
    }
    // set outgoing connections
    for (ConnectionContainer c : m_outgoingConnections) {
        if (m_wfm.canAddConnection(newId, c.getSourcePort() + outShift, c.getDest(), c.getDestPort())) {
            m_wfm.addConnection(newId, c.getSourcePort() + outShift, c.getDest(), c.getDestPort());
        } else {
            break;
        }
    }
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID)

Example 29 with NodeUIInformation

use of org.knime.core.node.workflow.NodeUIInformation 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)

Example 30 with NodeUIInformation

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

the class AbstractWorkflowPortBarEditPart method refreshVisuals.

/**
 * {@inheritDoc}
 */
@Override
protected void refreshVisuals() {
    NodeUIInformation uiInfo = ((WorkflowPortBar) getModel()).getUIInfo();
    if (uiInfo != null && !((AbstractWorkflowPortBarFigure) getFigure()).isInitialized()) {
        int[] bounds = uiInfo.getBounds();
        ((AbstractWorkflowPortBarFigure) getFigure()).setBounds(new Rectangle(bounds[0], bounds[1], bounds[2], bounds[3]));
    }
    super.refreshVisuals();
}
Also used : WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) AbstractWorkflowPortBarFigure(org.knime.workbench.editor2.figures.AbstractWorkflowPortBarFigure) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Aggregations

NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)31 NodeID (org.knime.core.node.workflow.NodeID)11 ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)8 NodeContainer (org.knime.core.node.workflow.NodeContainer)7 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)7 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)7 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)7 ConnectionID (org.knime.core.node.workflow.ConnectionID)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)5 Point (org.eclipse.draw2d.geometry.Point)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)4 MessageBox (org.eclipse.swt.widgets.MessageBox)3 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)3 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)3 ArrayList (java.util.ArrayList)2 IFigure (org.eclipse.draw2d.IFigure)2 Test (org.junit.Test)2