use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class PasteFromWorkflowPersistorCommand method canUndo.
/**
* {@inheritDoc}
*/
@Override
public boolean canUndo() {
WorkflowManager manager = m_editor.getWorkflowManager().get();
NodeID[] pastedNodes = m_pastedContent.getNodeIDs();
Annotation[] pastedAnnos = m_pastedContent.getAnnotations();
if ((pastedNodes == null || pastedNodes.length == 0) && (pastedAnnos == null || pastedAnnos.length == 0)) {
return false;
}
for (NodeID id : pastedNodes) {
if (!manager.canRemoveNode(id)) {
return false;
}
}
return true;
}
use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class SearchQueryContributionItem method createNode.
/**
* Helper to insert a node into the workflow editor.
*
* @param event
*/
private void createNode(final Object o) {
if (o instanceof NodeTemplate) {
NodeTemplate tmplt = (NodeTemplate) o;
NodeFactory<? extends NodeModel> nodeFact;
try {
nodeFact = tmplt.createFactoryInstance();
} catch (Exception e) {
NodeLogger.getLogger(SearchQueryContributionItem.class).error("Unable to instantiate the selected node " + tmplt.getFactory().getName(), e);
return;
}
boolean added = NodeProvider.INSTANCE.addNode(nodeFact);
if (added) {
NodeUsageRegistry.addNode(tmplt);
}
}
if (o instanceof MetaNodeTemplate) {
MetaNodeTemplate mnt = (MetaNodeTemplate) o;
NodeID metaNode = mnt.getManager().getID();
NodeProvider.INSTANCE.addMetaNode(WorkflowManager.META_NODE_ROOT, metaNode);
}
}
use of org.knime.core.node.workflow.NodeID 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.NodeID 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.NodeID 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());
}
}
Aggregations