Search in sources :

Example 1 with ConnectableEditPart

use of org.knime.workbench.editor2.editparts.ConnectableEditPart 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 ConnectableEditPart

use of org.knime.workbench.editor2.editparts.ConnectableEditPart in project knime-core by knime.

the class CreateConnectionCommand method canExecute.

/**
 * @return <code>true</code> if the connection can be added (that is, all
 *         fields were set to valid values before and the corresponding edit
 *         parts are not locked
 * @see org.eclipse.gef.commands.Command#canExecute()
 */
@Override
public boolean canExecute() {
    if (!super.canExecute()) {
        return false;
    }
    if (m_sourceNode == null || m_targetNode == null) {
        return false;
    }
    WorkflowManager wm = getHostWFM();
    if (m_targetPortID < 0) {
        ConnectableEditPart target = getTargetNode();
        if (target instanceof NodeContainerEditPart) {
            m_targetPortID = ((NodeContainerEditPart) target).getFreeInPort(getSourceNode(), getSourcePortID());
        }
    }
    // check whether an existing connection can be removed
    ConnectionContainer conn = wm.getIncomingConnectionFor(m_targetNode.getNodeContainer().getID(), m_targetPortID);
    boolean canRemove = conn == null || wm.canRemoveConnection(conn);
    // let the workflow manager check if the connection can be created
    // or removed
    boolean canAdd = wm.canAddConnection(m_sourceNode.getNodeContainer().getID(), m_sourcePortID, m_targetNode.getNodeContainer().getID(), m_targetPortID);
    return canRemove && canAdd;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 3 with ConnectableEditPart

use of org.knime.workbench.editor2.editparts.ConnectableEditPart 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)

Aggregations

ConnectableEditPart (org.knime.workbench.editor2.editparts.ConnectableEditPart)3 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)3 CreateConnectionCommand (org.knime.workbench.editor2.commands.CreateConnectionCommand)2 AbstractPortEditPart (org.knime.workbench.editor2.editparts.AbstractPortEditPart)2 MetaNodeOutPortEditPart (org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart)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 EditPart (org.eclipse.gef.EditPart)1 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)1 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)1 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)1