Search in sources :

Example 1 with AbstractPortEditPart

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

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

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

the class WorkflowSelectionDragEditPartsTracker method getEmbracedConnections.

/**
 * Returns the connections whose source and target is contained in the argument list.
 * @param parts list of selected nodes
 * @return the connections whose source and target is contained in the argument list.
 */
public static ConnectionContainerEditPart[] getEmbracedConnections(final List<EditPart> parts) {
    // result list
    List<ConnectionContainerEditPart> result = new ArrayList<ConnectionContainerEditPart>();
    for (EditPart part : parts) {
        if (part instanceof NodeContainerEditPart || part instanceof AbstractWorkflowPortBarEditPart) {
            EditPart containerPart = part;
            ConnectionContainerEditPart[] outPortConnectionParts = getOutportConnections(containerPart);
            // selected list, the connections bendpoints must be adapted
            for (ConnectionContainerEditPart connectionPart : outPortConnectionParts) {
                // get the in-port-node part of the connection and check
                AbstractPortEditPart inPortPart = null;
                if (connectionPart.getTarget() != null && ((AbstractPortEditPart) connectionPart.getTarget()).isInPort()) {
                    inPortPart = (AbstractPortEditPart) connectionPart.getTarget();
                } else if (connectionPart.getSource() != null) {
                    inPortPart = (AbstractPortEditPart) connectionPart.getSource();
                }
                if (inPortPart != null && isPartInList(inPortPart.getParent(), parts)) {
                    result.add(connectionPart);
                }
            }
        }
    }
    return result.toArray(new ConnectionContainerEditPart[result.size()]);
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) ArrayList(java.util.ArrayList) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart)

Example 4 with AbstractPortEditPart

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

the class WorkflowSelectionDragEditPartsTracker method getOutportConnections.

@SuppressWarnings("unchecked")
private static ConnectionContainerEditPart[] getOutportConnections(final EditPart containerPart) {
    // result list
    List<ConnectionContainerEditPart> result = new ArrayList<ConnectionContainerEditPart>();
    List<EditPart> children = containerPart.getChildren();
    for (EditPart part : children) {
        if (part instanceof AbstractPortEditPart) {
            AbstractPortEditPart outPortPart = (AbstractPortEditPart) part;
            // append all connection edit parts
            result.addAll(outPortPart.getSourceConnections());
        }
    }
    return result.toArray(new ConnectionContainerEditPart[result.size()]);
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) ArrayList(java.util.ArrayList) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart)

Example 5 with AbstractPortEditPart

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

Aggregations

AbstractPortEditPart (org.knime.workbench.editor2.editparts.AbstractPortEditPart)7 NodeInPortEditPart (org.knime.workbench.editor2.editparts.NodeInPortEditPart)5 ArrayList (java.util.ArrayList)4 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)4 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)4 WorkflowInPortEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortEditPart)4 Point (org.eclipse.draw2d.geometry.Point)3 EditPart (org.eclipse.gef.EditPart)3 CreateConnectionCommand (org.knime.workbench.editor2.commands.CreateConnectionCommand)3 WorkflowOutPortEditPart (org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart)3 List (java.util.List)2 PointList (org.eclipse.draw2d.geometry.PointList)2 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)2 AbstractWorkflowPortBarEditPart (org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart)2 ConnectableEditPart (org.knime.workbench.editor2.editparts.ConnectableEditPart)2 MetaNodeOutPortEditPart (org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart)2 NodeOutPortEditPart (org.knime.workbench.editor2.editparts.NodeOutPortEditPart)2 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)2 Connection (org.eclipse.draw2d.Connection)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1