Search in sources :

Example 1 with CreateConnectionCommand

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

the class PortGraphicalRoleEditPolicy method getConnectionCompleteCommand.

/**
 * This tries to complete the command to create a connection.
 *
 * {@inheritDoc}
 */
@Override
protected Command getConnectionCompleteCommand(final CreateConnectionRequest request) {
    // get the previously started command
    CreateConnectionCommand cmd = (CreateConnectionCommand) request.getStartCommand();
    if (cmd == null) {
        return null;
    }
    EditPart target = request.getTargetEditPart();
    if ((target instanceof NodeOutPortEditPart) || target instanceof WorkflowInPortEditPart) {
        return null;
    } else if (target instanceof NodeInPortEditPart || target instanceof WorkflowOutPortEditPart) {
        cmd.setTargetPortID(((AbstractPortEditPart) target).getIndex());
        cmd.setTargetNode((ConnectableEditPart) target.getParent());
    } else if (target instanceof NodeContainerEditPart) {
        if (cmd.wasStartedOnOutPort()) {
            cmd.setTargetPortID(-1);
            cmd.setTargetNode((NodeContainerEditPart) target);
        } else {
            cmd.setSourcePortID(-1);
            cmd.setSourceNode((NodeContainerEditPart) target);
        }
    } else {
        return null;
    }
    return cmd;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart)

Example 2 with CreateConnectionCommand

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

the class PortGraphicalRoleEditPolicy method getConnectionCreateCommand.

/**
 * This tries to initialize the command to create a connection as far as
 * possible. However, it is completed by
 * <code>getConnectionCompleteCommand</code>
 *
 * {@inheritDoc}
 */
@Override
protected Command getConnectionCreateCommand(final CreateConnectionRequest req) {
    if (!(getHost() instanceof AbstractPortEditPart)) {
        return null;
    }
    ConnectableEditPart nodePart = (ConnectableEditPart) getHost().getParent();
    WorkflowManagerUI wm;
    // TODO: if NodeContainerEditPart -> getParent
    if (nodePart instanceof NodeContainerEditPart) {
        NodeContainerEditPart p = (NodeContainerEditPart) nodePart;
        wm = p.getWorkflowManager();
    } else if (nodePart instanceof WorkflowInPortBarEditPart) {
        WorkflowInPortBarEditPart barEditPart = (WorkflowInPortBarEditPart) nodePart;
        WorkflowPortBar model = (WorkflowPortBar) barEditPart.getModel();
        wm = model.getWorkflowManager();
    } else {
        return null;
    }
    CreateConnectionCommand cmd = new CreateConnectionCommand(Wrapper.unwrapWFM(wm));
    if (getHost() instanceof NodeOutPortEditPart || getHost() instanceof WorkflowInPortEditPart || getHost() instanceof MetaNodeOutPortEditPart) {
        // request started on out port?
        cmd.setSourceNode(nodePart);
        cmd.setSourcePortID(((AbstractPortEditPart) getHost()).getIndex());
        cmd.setStartedOnOutPort(true);
    } else if (getHost() instanceof NodeInPortEditPart || getHost() instanceof WorkflowOutPortEditPart) {
        return null;
    }
    // we need the manager to execute the command
    // we must remember this partially initialized command in the request.
    req.setStartCommand(cmd);
    return cmd;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart)

Example 3 with CreateConnectionCommand

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

the class NodeContainerEditPart method getTargetConnectionAnchor.

/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getTargetConnectionAnchor(final Request request) {
    if (!(request instanceof CreateConnectionRequest)) {
        return null;
    }
    CreateConnectionRequest req = (CreateConnectionRequest) request;
    Command cmd = req.getStartCommand();
    if (!(cmd instanceof CreateConnectionCommand)) {
        return null;
    }
    CreateConnectionCommand connCmd = (CreateConnectionCommand) cmd;
    // find a free port that could take the connection
    int portIdx = getFreeInPort(connCmd.getSourceNode(), connCmd.getSourcePortID());
    if (portIdx < 0) {
        return null;
    }
    for (Object part : getChildren()) {
        if (part instanceof AbstractPortEditPart) {
            AbstractPortEditPart port = (AbstractPortEditPart) part;
            if (port.isInPort() && port.getIndex() == portIdx) {
                return port.getTargetConnectionAnchor(request);
            }
        }
    }
    return null;
}
Also used : CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) Command(org.eclipse.gef.commands.Command) ShiftConnectionCommand(org.knime.workbench.editor2.commands.ShiftConnectionCommand) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

CreateConnectionCommand (org.knime.workbench.editor2.commands.CreateConnectionCommand)3 AbstractPortEditPart (org.knime.workbench.editor2.editparts.AbstractPortEditPart)2 ConnectableEditPart (org.knime.workbench.editor2.editparts.ConnectableEditPart)2 MetaNodeOutPortEditPart (org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart)2 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)2 NodeInPortEditPart (org.knime.workbench.editor2.editparts.NodeInPortEditPart)2 NodeOutPortEditPart (org.knime.workbench.editor2.editparts.NodeOutPortEditPart)2 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)2 WorkflowInPortEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortEditPart)2 WorkflowOutPortEditPart (org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart)2 Point (org.eclipse.draw2d.geometry.Point)1 EditPart (org.eclipse.gef.EditPart)1 Command (org.eclipse.gef.commands.Command)1 CreateConnectionRequest (org.eclipse.gef.requests.CreateConnectionRequest)1 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)1 ShiftConnectionCommand (org.knime.workbench.editor2.commands.ShiftConnectionCommand)1 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)1 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)1