Search in sources :

Example 1 with CreateNewConnectedMetaNodeCommand

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;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) CreateNewConnectedMetaNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand) CreateNewConnectedNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedNodeCommand) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand) Command(org.eclipse.gef.commands.Command) CreateNewConnectedMetaNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand) NodeID(org.knime.core.node.workflow.NodeID) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)1 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)1 Command (org.eclipse.gef.commands.Command)1 NodeID (org.knime.core.node.workflow.NodeID)1 CreateNewConnectedMetaNodeCommand (org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand)1 CreateNewConnectedNodeCommand (org.knime.workbench.editor2.commands.CreateNewConnectedNodeCommand)1 CreateNodeCommand (org.knime.workbench.editor2.commands.CreateNodeCommand)1 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)1