use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class SelectLoopAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
WorkflowManager wfm = getManager();
for (NodeContainerEditPart selNode : nodeParts) {
NodeContainerUI selNC = selNode.getNodeContainer();
if (selNC instanceof SingleNodeContainerUI) {
EditPartViewer viewer = selNode.getViewer();
List<NodeContainer> loopNodes = wfm.getNodesInScope(Wrapper.unwrap(selNC, SingleNodeContainer.class));
for (NodeContainer nc : loopNodes) {
NodeContainerEditPart sel = (NodeContainerEditPart) viewer.getEditPartRegistry().get(NodeContainerWrapper.wrap(nc));
viewer.appendSelection(sel);
}
}
}
try {
// Give focus to the editor again. Otherwise the actions (selection)
// is not updated correctly.
getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
} catch (Exception e) {
// ignore
}
}
use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class StepLoopAction method internalCalculateEnabled.
/**
* @return <code>true</code>, if just one loop end node part is selected
* which is executable and a loop is in progress.
*
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean internalCalculateEnabled() {
NodeContainerEditPart[] parts = getSelectedParts(NodeContainerEditPart.class);
if (parts.length != 1) {
return false;
}
// enabled if the one selected node is a configured and "in progress"
// LoopEndNode
NodeContainerUI nc = parts[0].getNodeContainer();
if (Wrapper.wraps(nc, NativeNodeContainer.class)) {
NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
if (nnc.isModelCompatibleTo(LoopEndNode.class) && nnc.getLoopStatus().equals(LoopStatus.PAUSED)) {
// either the node is paused...
return true;
}
WorkflowManager wm = getEditor().getWorkflowManager().get();
if (wm.canExecuteNodeDirectly(nc.getID())) {
// ...or we can execute it (then this will be the first step)
return true;
}
}
return false;
}
use of org.knime.core.ui.node.workflow.NodeContainerUI in project knime-core by knime.
the class HorizAlignmentCenter method doLayout.
/**
* @param wfm the manager holding the nodes to layout
* @param nodeParts the nodes to align
* @return a map with offsets for the nodes
*/
static Map<NodeContainerEditPart, Integer> doLayout(final WorkflowManagerUI wfm, final NodeContainerEditPart[] nodeParts) {
if (nodeParts.length == 0) {
return Collections.emptyMap();
}
NodeContainerEditPart[] nodes = nodeParts.clone();
// sorts by the x position
Arrays.sort(nodes, new Comparator<NodeContainerEditPart>() {
@Override
public int compare(final NodeContainerEditPart o1, final NodeContainerEditPart o2) {
NodeUIInformation ui1 = o1.getNodeContainer().getUIInformation();
NodeUIInformation ui2 = o2.getNodeContainer().getUIInformation();
if (ui1 == null || ui2 == null) {
return 0;
}
if (ui1.getBounds()[0] < ui2.getBounds()[0]) {
return -1;
} else {
return (ui1.getBounds()[0] > ui2.getBounds()[0]) ? 1 : 0;
}
}
});
// most left node is the anchor that doesn't change
HashMap<NodeContainerEditPart, Integer> offsets = new HashMap<NodeContainerEditPart, Integer>();
NodeUIInformation nui = nodes[0].getNodeContainer().getUIInformation();
if (nui == null) {
LOGGER.warn("Only nodes with location information can be aligned.");
return Collections.emptyMap();
}
int refY = nui.getBounds()[1];
for (int i = 1; /* idx 0 is anchor */
i < nodes.length; i++) {
NodeContainerUI nc = nodes[i].getNodeContainer();
NodeUIInformation ui = nc.getUIInformation();
if (ui.getBounds()[1] != refY) {
offsets.put(nodes[i], refY - ui.getBounds()[1]);
}
}
return offsets;
}
use of org.knime.core.ui.node.workflow.NodeContainerUI 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.ui.node.workflow.NodeContainerUI 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());
}
}
Aggregations