Search in sources :

Example 1 with NodeInPortEditPart

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

the class SnapToPortGeometry method populateRowsAndCols.

/**
 * Updates the cached row and column Entries using the provided parts.
 * Columns are only the center of a node figure while rows are all ports of
 * a node.
 *
 * @param parts a List of EditParts
 */
protected void populateRowsAndCols(final List parts, final List dragedParts) {
    // add the port edit parts to a list
    List<AbstractPortEditPart> portList = getPorts(parts);
    // create all row relevant points fromt the port list
    List<Entry> rowVector = new ArrayList<Entry>();
    for (int i = 0; i < portList.size(); i++) {
        GraphicalEditPart child = portList.get(i);
        Rectangle bounds = getFigureBounds(child);
        // get information is this is an inport
        boolean inport = false;
        if (portList.get(i) instanceof NodeInPortEditPart || portList.get(i) instanceof WorkflowInPortEditPart) {
            inport = true;
        }
        // get information is this is a model port
        rowVector.add(new Entry(0, bounds.y + (bounds.height - 1) / 2, inport, portList.get(i).getType()));
    }
    // add the port edit parts to a list
    List<AbstractPortEditPart> dargedPortList = getPorts(dragedParts);
    for (int i = 0; i < dargedPortList.size(); i++) {
        // for each port get a possible connection (if connected)
        AbstractPortEditPart portPart = dargedPortList.get(i);
        List sourceConnections = portPart.getSourceConnections();
        for (int j = 0; j < sourceConnections.size(); j++) {
            ConnectionContainerEditPart conPart = (ConnectionContainerEditPart) sourceConnections.get(j);
            Point p = ((Connection) conPart.getFigure()).getPoints().getPoint(2);
            rowVector.add(new Entry(0, p.y, true, portPart.getType()));
        }
        List targetConnections = portPart.getTargetConnections();
        for (int j = 0; j < targetConnections.size(); j++) {
            ConnectionContainerEditPart conPart = (ConnectionContainerEditPart) targetConnections.get(j);
            PointList pList = ((Connection) conPart.getFigure()).getPoints();
            Point p = pList.getPoint(pList.size() - 3);
            rowVector.add(new Entry(0, p.y, false, portPart.getType()));
        }
    }
    List<Entry> colVector = new ArrayList<Entry>();
    for (int i = 0; i < parts.size(); i++) {
        GraphicalEditPart child = (GraphicalEditPart) parts.get(i);
        Rectangle bounds = getFigureBounds(child);
        colVector.add(new Entry(0, bounds.x + (bounds.width - 1) / 2));
    }
    m_rows = rowVector.toArray(new Entry[rowVector.size()]);
    m_cols = colVector.toArray(new Entry[colVector.size()]);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) ArrayList(java.util.ArrayList) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Connection(org.eclipse.draw2d.Connection) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) ArrayList(java.util.ArrayList) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart)

Example 2 with NodeInPortEditPart

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

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

the class WorkflowEditPartFactory method createEditPart.

/**
 * Creates the referring edit parts for the following parts of the model.
 * <ul>
 * <li>{@link WorkflowManager}: either {@link WorkflowRootEditPart} or {@link NodeContainerEditPart} (depending on
 * the currently displayed level)</li>
 * <li>{@link SingleNodeContainer}: {@link NodeContainerEditPart}</li>
 * <li>{@link NodeInPort}: {@link NodeInPortEditPart}</li>
 * <li>{@link NodeOutPort}: {@link NodeOutPortEditPart}</li>
 * <li>{@link ConnectionContainer}: {@link ConnectionContainerEditPart}</li>
 * <li>{@link WorkflowInPort}: {@link WorkflowInPortEditPart}</li>
 * <li>{@link WorkflowOutPort}: {@link WorkflowOutPortEditPart}</li>
 * </ul>
 *
 * The {@link WorkflowRootEditPart} has its {@link NodeContainer}s and its {@link WorkflowInPort}s and
 * {@link WorkflowOutPort}s as model children. The {@link NodeContainerEditPart} has its {@link NodePort}s as its
 * children.
 *
 * @see WorkflowRootEditPart#getModelChildren()
 * @see NodeContainerEditPart#getModelChildren()
 *
 * @throws IllegalArgumentException if any other object is passed
 *
 *             {@inheritDoc}
 */
@Override
public EditPart createEditPart(final EditPart context, final Object model) {
    // instantiated here
    // correct type in the if statement
    // model at the end of method
    EditPart part = null;
    if (model instanceof WorkflowManagerUI) {
        // this is out "root" workflow manager
        if (m_isTop) {
            // all following objects of type WorkflowManager are treated as
            // metanodes and displayed as NodeContainers
            m_isTop = false;
            part = new WorkflowRootEditPart();
        } else {
            // we already have a "root" workflow manager
            // must be a metanode
            part = new SubworkflowEditPart();
        }
    } else if (model instanceof NodeAnnotation) {
        /* IMPORTANT: first test NodeAnnotation then Annotation (as the
             * first derives from the latter! */
        part = new NodeAnnotationEditPart();
    } else if (model instanceof Annotation) {
        /* IMPORTANT: first test NodeAnnotation then Annotation (as the
             * first derives from the latter! */
        /* workflow annotations hang off the workflow manager */
        part = new AnnotationEditPart();
    } else if (model instanceof WorkflowPortBar) {
        WorkflowPortBar bar = (WorkflowPortBar) model;
        if (bar.isInPortBar()) {
            part = new WorkflowInPortBarEditPart();
        } else {
            part = new WorkflowOutPortBarEditPart();
        }
    } else if (model instanceof SingleNodeContainerUI) {
        // SingleNodeContainer -> NodeContainerEditPart
        part = new NodeContainerEditPart();
    // we have to test for WorkflowInPort first because it's a
    // subclass of NodeInPort (same holds for WorkflowOutPort and
    // NodeOutPort)
    } else if (model instanceof WorkflowInPortUI && context instanceof WorkflowInPortBarEditPart) {
        // WorkflowInPort and context WorkflowRootEditPart ->
        // WorkflowInPortEditPart
        /*
             * if the context is a WorkflowRootEditPart it indicates that the
             * WorkflowInPort is a model child of the WorkflowRootEditPart, i.e.
             * we look at it as a workflow in port. If the context is a
             * NodeContainerEditPart the WorkflowInPort is a model child of a
             * NodeContainerEditPart and we look at it as a node in port.
             */
        WorkflowInPortUI inport = (WorkflowInPortUI) model;
        part = new WorkflowInPortEditPart(inport.getPortType(), inport.getPortIndex());
    } else if (model instanceof WorkflowOutPortUI && context instanceof WorkflowOutPortBarEditPart) {
        // WorkflowOutPort and context WorkflowRootEditPart ->
        // WorkflowOutPortEditPart
        /*
             * if the context is a WorkflowRootEditPart it indicates that the
             * WorkflowOutPort is a model child of the WorkflowRootEditPart,
             * i.e. we look at it as a workflow out port. If the context is a
             * NodeContainerEditPart the WorkflowOutPort is a model child of a
             * NodeContainerEditPart and we look at it as a node out port.
             */
        // TODO: return SubWorkFlowOutPortEditPart
        WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
        part = new WorkflowOutPortEditPart(outport.getPortType(), outport.getPortIndex());
    } else if (model instanceof WorkflowOutPortUI) {
        // TODO: return SubWorkFlowOutPortEditPart
        WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
        part = new MetaNodeOutPortEditPart(outport.getPortType(), outport.getPortIndex());
    } else if (model instanceof NodeInPortUI) {
        // NodeInPort -> NodeInPortEditPart
        NodePortUI port = (NodeInPortUI) model;
        part = new NodeInPortEditPart(port.getPortType(), port.getPortIndex());
    } else if (model instanceof NodeOutPortUI) {
        // NodeOutPort -> NodeOutPortEditPart
        NodePortUI port = (NodeOutPortUI) model;
        part = new NodeOutPortEditPart(port.getPortType(), port.getPortIndex());
    } else if (model instanceof ConnectionContainerUI) {
        // ConnectionContainer -> ConnectionContainerEditPart
        part = new ConnectionContainerEditPart();
    } else {
        throw new IllegalArgumentException("unknown model obj: " + model);
    }
    // associate the model with the part (= the controller)
    part.setModel(model);
    return part;
}
Also used : SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) WorkflowOutPortUI(org.knime.core.ui.node.workflow.WorkflowOutPortUI) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation) NodeInPortUI(org.knime.core.ui.node.workflow.NodeInPortUI) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) NodeOutPortUI(org.knime.core.ui.node.workflow.NodeOutPortUI) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) WorkflowInPortUI(org.knime.core.ui.node.workflow.WorkflowInPortUI) NodePortUI(org.knime.core.ui.node.workflow.NodePortUI)

Example 4 with NodeInPortEditPart

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

the class PortGraphicalRoleEditPolicy method getReconnectTargetCommand.

/**
 * {@inheritDoc}
 */
@Override
protected Command getReconnectTargetCommand(final ReconnectRequest req) {
    // only connect to inports
    if (!(getHost() instanceof NodeInPortEditPart || getHost() instanceof WorkflowOutPortEditPart)) {
        return null;
    }
    // get new target in port
    AbstractPortEditPart target = (AbstractPortEditPart) req.getTarget();
    ReconnectConnectionCommand reconnectCmd = new ReconnectConnectionCommand((ConnectionContainerEditPart) req.getConnectionEditPart(), (AbstractPortEditPart) req.getConnectionEditPart().getSource(), target);
    return reconnectCmd;
}
Also used : ReconnectConnectionCommand(org.knime.workbench.editor2.commands.ReconnectConnectionCommand) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart)

Example 5 with NodeInPortEditPart

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

NodeInPortEditPart (org.knime.workbench.editor2.editparts.NodeInPortEditPart)6 AbstractPortEditPart (org.knime.workbench.editor2.editparts.AbstractPortEditPart)5 WorkflowInPortEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortEditPart)5 WorkflowOutPortEditPart (org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart)4 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)3 MetaNodeOutPortEditPart (org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart)3 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)3 NodeOutPortEditPart (org.knime.workbench.editor2.editparts.NodeOutPortEditPart)3 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Point (org.eclipse.draw2d.geometry.Point)2 PointList (org.eclipse.draw2d.geometry.PointList)2 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)2 EditPart (org.eclipse.gef.EditPart)2 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)2 CreateConnectionCommand (org.knime.workbench.editor2.commands.CreateConnectionCommand)2 ConnectableEditPart (org.knime.workbench.editor2.editparts.ConnectableEditPart)2 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)2 Connection (org.eclipse.draw2d.Connection)1