Search in sources :

Example 1 with AbstractWorkflowPortBarEditPart

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

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

the class NewWorkflowXYLayoutPolicy method createChangeConstraintCommand.

/**
 * Creates command to move / resize <code>NodeContainer</code> components on
 * the project's client area.
 *
 * {@inheritDoc}
 */
@Override
protected Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
    // only rectangular constraints are supported
    if (!(constraint instanceof Rectangle)) {
        return null;
    }
    Command command = null;
    Rectangle rect = ((Rectangle) constraint).getCopy();
    if (child.getModel() instanceof NodeContainerUI) {
        NodeContainerUI container = (NodeContainerUI) child.getModel();
        if (!Wrapper.wraps(container, NodeContainer.class)) {
            // not supported for others than ordinary NodeContainers
            return null;
        }
        NodeContainerEditPart nodePart = (NodeContainerEditPart) child;
        command = new ChangeNodeBoundsCommand(Wrapper.unwrapNC(container), (NodeContainerFigure) nodePart.getFigure(), rect);
    } else if (child instanceof AbstractWorkflowPortBarEditPart) {
        command = new ChangeWorkflowPortBarCommand((AbstractWorkflowPortBarEditPart) child, rect);
    } else if (child instanceof AnnotationEditPart) {
        AnnotationEditPart annoPart = (AnnotationEditPart) child;
        // TODO the workflow annotation could know what its WFM is?
        WorkflowRootEditPart root = (WorkflowRootEditPart) annoPart.getParent();
        WorkflowManagerUI wm = root.getWorkflowManager();
        if (!Wrapper.wraps(wm, WorkflowManager.class)) {
            // not supported for others than an ordinary workflow manager
            return null;
        }
        command = new ChangeAnnotationBoundsCommand(Wrapper.unwrapWFM(wm), annoPart, rect);
    }
    return command;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) ChangeNodeBoundsCommand(org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ChangeWorkflowPortBarCommand(org.knime.workbench.editor2.commands.ChangeWorkflowPortBarCommand) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) NodeContainer(org.knime.core.node.workflow.NodeContainer) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure) ChangeAnnotationBoundsCommand(org.knime.workbench.editor2.commands.ChangeAnnotationBoundsCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) ChangeWorkflowPortBarCommand(org.knime.workbench.editor2.commands.ChangeWorkflowPortBarCommand) ChangeNodeBoundsCommand(org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand) ChangeAnnotationBoundsCommand(org.knime.workbench.editor2.commands.ChangeAnnotationBoundsCommand) Command(org.eclipse.gef.commands.Command)

Example 3 with AbstractWorkflowPortBarEditPart

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

Aggregations

AbstractWorkflowPortBarEditPart (org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart)3 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)2 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)2 ArrayList (java.util.ArrayList)1 IFigure (org.eclipse.draw2d.IFigure)1 PolylineConnection (org.eclipse.draw2d.PolylineConnection)1 ConnectionEditPart (org.eclipse.gef.ConnectionEditPart)1 EditPart (org.eclipse.gef.EditPart)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 Command (org.eclipse.gef.commands.Command)1 NodeContainer (org.knime.core.node.workflow.NodeContainer)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)1 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)1 ChangeAnnotationBoundsCommand (org.knime.workbench.editor2.commands.ChangeAnnotationBoundsCommand)1 ChangeNodeBoundsCommand (org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand)1 ChangeWorkflowPortBarCommand (org.knime.workbench.editor2.commands.ChangeWorkflowPortBarCommand)1 AbstractPortEditPart (org.knime.workbench.editor2.editparts.AbstractPortEditPart)1