use of org.knime.workbench.editor2.commands.CreateNewConnectedNodeCommand in project knime-core by knime.
the class WorkflowEditor method addNode.
/**
* Listener interface method of the {@link NodeProvider}. Called when other
* instances want to add a node to the workflow in the editor. <br>
* The implementation only adds it if the editor is active and one node is
* selected in the editor, to which the new node will then be connected to.
* {@inheritDoc}
*/
@Override
public boolean addNode(final NodeFactory<? extends NodeModel> nodeFactory) {
if (!isEditorActive()) {
return false;
}
if (!getWorkflowManager().isPresent()) {
return false;
}
NodeContainerEditPart preNode = getTheOneSelectedNode();
Point nodeLoc = null;
Command newNodeCmd = null;
if (preNode == null) {
nodeLoc = getViewportCenterLocation();
// this command accepts/requires relative coordinates
newNodeCmd = new CreateNodeCommand(unwrapWFM(m_manager), nodeFactory, nodeLoc, getEditorSnapToGrid());
} else {
nodeLoc = getLocationRightOf(preNode);
newNodeCmd = new CreateNewConnectedNodeCommand(getViewer(), unwrapWFM(m_manager), nodeFactory, nodeLoc, preNode.getNodeContainer().getID());
}
getCommandStack().execute(newNodeCmd);
// after adding a node the editor should get the focus
// this is issued asynchronously, in order to avoid bug #3029
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
setFocus();
}
});
return true;
}
Aggregations