Search in sources :

Example 6 with ConnectionUIInformation

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

the class HorizAlignManager method doLayout.

/**
 */
public void doLayout() {
    Map<NodeContainerEditPart, Integer> offsets = HorizAlignmentCenter.doLayout(m_wfm, m_nodeParts);
    // if emtpy - do some other alignement. May be port alignement?
    // preserver the old stuff for undoers
    m_oldBendpoints = new HashMap<ConnectionID, ConnectionUIInformation>();
    m_oldCoordinates = new HashMap<NodeID, NodeUIInformation>();
    if (offsets.isEmpty()) {
        LOGGER.debug("Nodes already aligned. Doing nothing.");
        return;
    }
    // transfer new coordinates into nodes
    for (Map.Entry<NodeContainerEditPart, Integer> e : offsets.entrySet()) {
        NodeContainerEditPart node = e.getKey();
        NodeContainerUI nc = node.getNodeContainer();
        NodeUIInformation uiInfo = nc.getUIInformation();
        int[] b = uiInfo.getBounds();
        NodeUIInformation newCoord = NodeUIInformation.builder().setNodeLocation(b[0], b[1] + e.getValue(), b[2], b[3]).setHasAbsoluteCoordinates(uiInfo.hasAbsoluteCoordinates()).build();
        LOGGER.debug("Node " + nc + " gets alignment coordinates " + newCoord);
        // save old coordinates for undo
        m_oldCoordinates.put(nc.getID(), uiInfo);
        // adjust first bendpoints at port position
        adjustBendPoints(node, e.getValue());
        // triggers gui update
        nc.setUIInformation(newCoord);
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionID(org.knime.core.node.workflow.ConnectionID) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeID(org.knime.core.node.workflow.NodeID) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ConnectionUIInformation

use of org.knime.core.node.workflow.ConnectionUIInformation 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 8 with ConnectionUIInformation

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

the class VerticAlignManager method doLayout.

/**
 */
public void doLayout() {
    Map<NodeContainerEditPart, Integer> offsets = VerticAlignmentCenter.doLayout(m_wfm, m_nodeParts);
    // preserver the old stuff for undoers
    m_oldBendpoints = new HashMap<ConnectionID, ConnectionUIInformation>();
    m_oldCoordinates = new HashMap<NodeID, NodeUIInformation>();
    if (offsets.isEmpty()) {
        LOGGER.debug("Nodes already aligned. Doing nothing.");
        return;
    }
    // transfer new coordinates into nodes
    for (Map.Entry<NodeContainerEditPart, Integer> e : offsets.entrySet()) {
        NodeContainerEditPart node = e.getKey();
        NodeContainerUI nc = node.getNodeContainer();
        NodeUIInformation uiInfo = nc.getUIInformation();
        int[] b = uiInfo.getBounds();
        NodeUIInformation newCoord = NodeUIInformation.builder().setNodeLocation(b[0] + e.getValue(), b[1], b[2], b[3]).setHasAbsoluteCoordinates(uiInfo.hasAbsoluteCoordinates()).build();
        LOGGER.debug("Node " + nc + " gets alignment coordinates " + newCoord);
        // save old coordinates for undo
        m_oldCoordinates.put(nc.getID(), uiInfo);
        // triggers gui update
        nc.setUIInformation(newCoord);
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionID(org.knime.core.node.workflow.ConnectionID) NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) NodeID(org.knime.core.node.workflow.NodeID) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with ConnectionUIInformation

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

the class AutoLayoutCommand method undo.

/**
 * {@inheritDoc}
 */
@Override
public void undo() {
    Map<NodeID, NodeUIInformation> oldPositions = m_layoutMgr.getOldNodeCoordinates();
    Map<ConnectionID, ConnectionUIInformation> oldBendpoints = m_layoutMgr.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 10 with ConnectionUIInformation

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

the class ChangeBendPointLocationCommand method changeBendpointsUIInfo.

private void changeBendpointsUIInfo(final boolean shiftBack) {
    ConnectionContainer cc = getConnectionContainer();
    ConnectionUIInformation ui = cc.getUIInfo();
    if (ui == null) {
        return;
    }
    int[][] bendpoints = ui.getAllBendpoints();
    Point locationShift = m_locationShift.getCopy();
    if (m_zoomManager != null) {
        WorkflowEditor.adaptZoom(m_zoomManager, locationShift, false);
    }
    int length = bendpoints.length;
    int shiftX = shiftBack ? locationShift.x * -1 : locationShift.x;
    int shiftY = shiftBack ? locationShift.y * -1 : locationShift.y;
    ConnectionUIInformation.Builder newUIBuilder = ConnectionUIInformation.builder();
    for (int i = 0; i < length; i++) {
        // get old
        int x = ui.getBendpoint(i)[0];
        int y = ui.getBendpoint(i)[1];
        // set the new point
        newUIBuilder.addBendpoint(x + shiftX, y + shiftY, i);
    }
    // must set explicitly so that event is fired by container
    cc.setUIInfo(newUIBuilder.build());
}
Also used : ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) ConnectionUIInformation(org.knime.core.node.workflow.ConnectionUIInformation) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)19 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)13 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 Point (org.eclipse.draw2d.geometry.Point)7 NodeID (org.knime.core.node.workflow.NodeID)7 ConnectionID (org.knime.core.node.workflow.ConnectionID)6 Map (java.util.Map)5 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)5 NodeContainer (org.knime.core.node.workflow.NodeContainer)4 HashMap (java.util.HashMap)3 ConnectionContainerUI (org.knime.core.ui.node.workflow.ConnectionContainerUI)3 ArrayList (java.util.ArrayList)2 Builder (org.knime.core.node.workflow.ConnectionUIInformation.Builder)2 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)2 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)2 Point2D (java.awt.geom.Point2D)1 HashSet (java.util.HashSet)1 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)1 EditPartViewer (org.eclipse.gef.EditPartViewer)1 EditorUIInformation (org.knime.core.node.workflow.EditorUIInformation)1