Search in sources :

Example 1 with CreateNodeCommand

use of org.knime.workbench.editor2.commands.CreateNodeCommand in project knime-core by knime.

the class NewWorkflowContainerEditPolicy method handleNodeDrop.

/**
 * @param manager the workflow manager
 * @param factory the ndoe factory
 * @param request the drop request
 */
private Command handleNodeDrop(final WorkflowManager manager, final NodeFactory<? extends NodeModel> factory, final CreateDropRequest request) {
    RequestType requestType = request.getRequestType();
    Point location = request.getLocation();
    boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
    if (requestType.equals(RequestType.CREATE)) {
        // create a new node
        return new CreateNodeCommand(manager, factory, location, snapToGrid);
    } else {
        AbstractEditPart editPart = request.getEditPart();
        if (requestType.equals(RequestType.INSERT)) {
            // insert new node into connection
            InsertNodeCommand insertCommand = new InsertNodeCommand(manager, factory, location, snapToGrid, (ConnectionContainerEditPart) editPart);
            if (request.createSpace()) {
                CreateSpaceAction csa = new CreateSpaceAction((WorkflowEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(), request.getDirection(), request.getDistance());
                return insertCommand.chain(csa.createCompoundCommand(csa.selectedParts()));
            } else {
                return insertCommand;
            }
        } else if (requestType.equals(RequestType.REPLACE)) {
            // replace node with a node
            return new ReplaceNodeCommand(manager, factory, location, snapToGrid, (NodeContainerEditPart) editPart);
        } else {
            return null;
        }
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) ReplaceNodeCommand(org.knime.workbench.editor2.commands.ReplaceNodeCommand) Point(org.eclipse.draw2d.geometry.Point) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand) InsertNodeCommand(org.knime.workbench.editor2.commands.InsertNodeCommand) CreateSpaceAction(org.knime.workbench.editor2.actions.CreateSpaceAction) RequestType(org.knime.workbench.editor2.CreateDropRequest.RequestType)

Example 2 with CreateNodeCommand

use of org.knime.workbench.editor2.commands.CreateNodeCommand 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;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) CreateNewConnectedNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedNodeCommand) 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) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand)

Aggregations

Point (org.eclipse.draw2d.geometry.Point)2 CreateNodeCommand (org.knime.workbench.editor2.commands.CreateNodeCommand)2 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)2 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)1 Command (org.eclipse.gef.commands.Command)1 AbstractEditPart (org.eclipse.gef.editparts.AbstractEditPart)1 RequestType (org.knime.workbench.editor2.CreateDropRequest.RequestType)1 CreateSpaceAction (org.knime.workbench.editor2.actions.CreateSpaceAction)1 CreateNewConnectedMetaNodeCommand (org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand)1 CreateNewConnectedNodeCommand (org.knime.workbench.editor2.commands.CreateNewConnectedNodeCommand)1 InsertNodeCommand (org.knime.workbench.editor2.commands.InsertNodeCommand)1 ReplaceNodeCommand (org.knime.workbench.editor2.commands.ReplaceNodeCommand)1