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