use of org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand in project knime-core by knime.
the class WorkflowEditor method addMetaNode.
/*
* --------- methods for adding a auto-placed and auto-connected node -----
*/
/**
* {@inheritDoc}
* Listener interface method of the {@link NodeProvider}.
* Called when other instances want to add a metanode to the workflow in
* the editor. <br>
* The implementation only adds it if the editor is active. If one other
* node is selected in the editor, to which the new node will then be
* connected to.
*
* @param sourceManager wfm to copy the metanode from
* @param id the id of the metanode in the source manager
* @return if the metanode was actually added
*/
@Override
public boolean addMetaNode(final WorkflowManager sourceManager, final NodeID id) {
if (id == null || sourceManager == null) {
return false;
}
if (!isEditorActive()) {
return false;
}
NodeContainerEditPart preNode = getTheOneSelectedNode();
NodeID preID = null;
Point nodeLoc = null;
if (preNode == null) {
nodeLoc = getViewportCenterLocation();
nodeLoc = toAbsolute(nodeLoc);
} else {
nodeLoc = getLocationRightOf(preNode);
preID = preNode.getNodeContainer().getID();
}
if (getEditorSnapToGrid()) {
nodeLoc = getClosestGridLocation(nodeLoc);
}
Command newNodeCmd = new CreateNewConnectedMetaNodeCommand(getViewer(), unwrapWFM(m_manager), sourceManager, id, nodeLoc, preID);
getCommandStack().execute(newNodeCmd);
// after adding a node the editor should get the focus
setFocus();
return true;
}
Aggregations