Search in sources :

Example 11 with NodeUIInformation

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

the class LayoutManager method createGraphNodeForNC.

/**
 * Creates a new graph node with the coordinates from the UI info and the
 * label set to custom name.
 *
 * @param nc
 * @return
 */
private Node createGraphNodeForNC(final NodeContainerUI nc) {
    NodeUIInformation uiInfo = nc.getUIInformation();
    int x = 0;
    int y = 0;
    String label = nc.getCustomName();
    if (label == null || label.isEmpty()) {
        label = "Node " + nc.getID().toString();
    }
    if (uiInfo != null) {
        int[] bounds = uiInfo.getBounds();
        x = bounds[0];
        y = bounds[1];
        return m_g.createNode(label, x, y);
    } else {
        return m_g.createNode(label);
    }
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) Point(org.eclipse.draw2d.geometry.Point)

Example 12 with NodeUIInformation

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

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

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

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

the class NodeUIInformationTest method testCopyBuilder.

@Test
public void testCopyBuilder() {
    NodeUIInformation uiinf = NodeUIInformation.builder().setHasAbsoluteCoordinates(false).setIsDropLocation(true).setIsSymbolRelative(false).setSnapToGrid(true).setNodeLocation(10, 11, 13, 15).translate(new int[] { 2, 3 }).build();
    NodeUIInformation uiinf2 = NodeUIInformation.builder(uiinf).build();
    assertEquals(uiinf.hasAbsoluteCoordinates(), uiinf2.hasAbsoluteCoordinates());
    assertEquals(uiinf.isSymbolRelative(), uiinf2.isSymbolRelative());
    assertEquals(uiinf.isDropLocation(), uiinf2.isDropLocation());
    assertEquals(uiinf.getSnapToGrid(), uiinf2.getSnapToGrid());
    assertArrayEquals(uiinf.getBounds(), uiinf2.getBounds());
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) Test(org.junit.Test)

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