Search in sources :

Example 1 with ConnectionContainerEditPart

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

the class WorkflowSelectionDragEditPartsTracker method getCommand.

/**
 * Asks each edit part in the
 * {@link org.eclipse.gef.tools.AbstractTool#getOperationSet() operation set}
 * to contribute to a {@link CompoundCommand} after first setting the
 * request type to either {@link org.eclipse.gef.RequestConstants#REQ_MOVE}
 * or {@link org.eclipse.gef.RequestConstants#REQ_ORPHAN}, depending on the
 * result of {@link #isMove()}.
 *
 * Additionally the method creates a command to adapt connections where both
 * node container are include in the drag operation.
 *
 * {@inheritDoc}
 */
@Override
protected Command getCommand() {
    CompoundCommand command = new CompoundCommand();
    command.setDebugLabel("Drag Object Tracker");
    Iterator iter = getOperationSet().iterator();
    Request request = getTargetRequest();
    if (isCloneActive()) {
        request.setType(REQ_CLONE);
    } else if (isMove()) {
        request.setType(REQ_MOVE);
    } else {
        request.setType(REQ_ORPHAN);
    }
    if (!isCloneActive()) {
        while (iter.hasNext()) {
            EditPart editPart = (EditPart) iter.next();
            command.add(editPart.getCommand(request));
        }
    }
    // now add the commands for the node-embraced connections
    ConnectionContainerEditPart[] connectionsToAdapt = getEmbracedConnections(getOperationSet());
    for (ConnectionContainerEditPart connectionPart : connectionsToAdapt) {
        command.add(connectionPart.getBendpointAdaptionCommand(request));
    }
    if (!isMove() || isCloneActive()) {
        if (!isCloneActive()) {
            request.setType(REQ_ADD);
        }
        if (getTargetEditPart() == null) {
            command.add(UnexecutableCommand.INSTANCE);
        } else {
            command.add(getTargetEditPart().getCommand(getTargetRequest()));
        }
    }
    return command;
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) Iterator(java.util.Iterator) Request(org.eclipse.gef.Request) 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) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 2 with ConnectionContainerEditPart

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

the class WorkflowMarqueeSelectionTool method calculateNewSelection.

private void calculateNewSelection(final Collection<GraphicalEditPart> newSelections, final Collection<GraphicalEditPart> deselections) {
    Rectangle marqueeRect = getMarqueeSelectionRectangle();
    for (Iterator<GraphicalEditPart> itr = getAllChildren().iterator(); itr.hasNext(); ) {
        GraphicalEditPart child = itr.next();
        IFigure figure = child.getFigure();
        if (!child.isSelectable() || child.getTargetEditPart(MARQUEE_REQUEST) != child || !isFigureVisible(figure) || !figure.isShowing()) {
            continue;
        }
        if (!(child instanceof NodeContainerEditPart || child instanceof ConnectionContainerEditPart || child instanceof AbstractWorkflowPortBarEditPart || child instanceof AnnotationEditPart)) {
            continue;
        }
        Rectangle r = figure.getBounds().getCopy();
        figure.translateToAbsolute(r);
        boolean included = false;
        if (child instanceof ConnectionEditPart && marqueeRect.intersects(r)) {
            Rectangle relMarqueeRect = Rectangle.SINGLETON;
            figure.translateToRelative(relMarqueeRect.setBounds(marqueeRect));
            included = ((PolylineConnection) figure).getPoints().intersects(relMarqueeRect);
        } else if (child instanceof AnnotationEditPart) {
            // select WorkflowAnnotations only if they are fully included in the selection
            if (figure instanceof WorkflowAnnotationFigure) {
                included = marqueeRect.contains(r);
            }
        } else if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
            included = marqueeRect.intersects(r);
        } else {
            included = marqueeRect.contains(r);
        }
        if (included) {
            if (isToggle()) {
                if (wasSelected(child)) {
                    deselections.add(child);
                } else {
                    newSelections.add(child);
                }
            } else {
                newSelections.add(child);
            }
        } else if (isToggle()) {
            // readded if it was in the selection before
            if (wasSelected(child)) {
                newSelections.add(child);
            } else {
                deselections.add(child);
            }
        }
    }
    if (marqueeBehavior == BEHAVIOR_NODES_AND_CONNECTIONS_TOUCHED) {
        calculateConnections(newSelections, deselections);
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) WorkflowAnnotationFigure(org.knime.workbench.editor2.figures.WorkflowAnnotationFigure) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) ConnectionEditPart(org.eclipse.gef.ConnectionEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IFigure(org.eclipse.draw2d.IFigure) PolylineConnection(org.eclipse.draw2d.PolylineConnection)

Example 3 with ConnectionContainerEditPart

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

the class AbstractClipboardAction method getSelectedConnectionParts.

/**
 * @return The selected <code>ConnectionContainerEditParts</code>, may be
 *         empty
 */
protected ConnectionContainerEditPart[] getSelectedConnectionParts() {
    ArrayList<ConnectionContainerEditPart> objects = new ArrayList<ConnectionContainerEditPart>(getSelectedObjects());
    // parts for a ConnectionContainer
    for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
        Object element = iter.next();
        if (!(element instanceof ConnectionContainerEditPart)) {
            iter.remove();
            continue;
        }
    }
    final ConnectionContainerEditPart[] parts = objects.toArray(new ConnectionContainerEditPart[objects.size()]);
    return parts;
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 4 with ConnectionContainerEditPart

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

the class ConnectionBendpointEditPolicy method getDeleteBendpointCommand.

/**
 * {@inheritDoc}
 */
protected Command getDeleteBendpointCommand(final BendpointRequest req) {
    // get the index of the bendpoint to delete
    int index = req.getIndex();
    ConnectionContainerEditPart editPart = (ConnectionContainerEditPart) getHost();
    WorkflowManager wfm = getWorkflowManager();
    return new NewBendpointDeleteCommand(editPart, wfm, index);
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NewBendpointDeleteCommand(org.knime.workbench.editor2.commands.NewBendpointDeleteCommand) AbsoluteBendpoint(org.eclipse.draw2d.AbsoluteBendpoint) Point(org.eclipse.draw2d.geometry.Point) Bendpoint(org.eclipse.draw2d.Bendpoint)

Example 5 with ConnectionContainerEditPart

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

Aggregations

ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)13 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)10 Point (org.eclipse.draw2d.geometry.Point)9 EditPart (org.eclipse.gef.EditPart)7 AbstractPortEditPart (org.knime.workbench.editor2.editparts.AbstractPortEditPart)5 ArrayList (java.util.ArrayList)4 AbstractWorkflowPortBarEditPart (org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart)4 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)3 Bendpoint (org.eclipse.draw2d.Bendpoint)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)3 NodeInPortEditPart (org.knime.workbench.editor2.editparts.NodeInPortEditPart)3 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)3 WorkflowOutPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart)3 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)3 Iterator (java.util.Iterator)2 IFigure (org.eclipse.draw2d.IFigure)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 AbstractEditPart (org.eclipse.gef.editparts.AbstractEditPart)2