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);
}
}
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);
}
}
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);
}
}
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());
}
}
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());
}
Aggregations