Search in sources :

Example 6 with ConnectionContainerEditPart

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

the class WorkflowEditorDropTargetListener method dragOver.

/**
 * {@inheritDoc}
 *
 * Marks nodes or edges if a new node should replace an old node or should be inserted on an edge.
 */
@Override
public void dragOver(final DropTargetEvent event) {
    WorkflowManagerUI wfm = ((WorkflowRootEditPart) getViewer().getRootEditPart().getContents()).getWorkflowManager();
    m_node = null;
    m_edge = null;
    m_nodeCount = 0;
    m_edgeCount = 0;
    // edge-/nodedist
    double edgedist = Integer.MAX_VALUE;
    double nodedist = Integer.MAX_VALUE;
    Point dropLocation = getDropLocation(event);
    EditPart ep = getViewer().findObjectAt(dropLocation.getTranslated(0, 0));
    if (ep instanceof NodeContainerEditPart) {
        double temp = dropLocation.getDistance(dropLocation.getTranslated(0, 0));
        // choose nearest node to mouse position
        if (nodedist >= temp) {
            m_node = (NodeContainerEditPart) ep;
            nodedist = temp;
        }
        m_nodeCount++;
    } else if (ep instanceof ConnectionContainerEditPart) {
        double temp = dropLocation.getDistance(dropLocation.getTranslated(0, 0));
        // choose nearest edge to mouse-position
        if (edgedist >= temp) {
            m_edge = (ConnectionContainerEditPart) ep;
            edgedist = temp;
        }
        m_edgeCount++;
    }
    unmark(wfm);
    if (m_node != null && m_nodeCount >= m_edgeCount) {
        m_markedNode = m_node;
        m_markedNode.mark();
        // workaround for eclipse bug 393868 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=393868)
        WindowsDNDHelper.hideDragImage();
    } else if (m_edge != null) {
        m_edgeColor = m_edge.getFigure().getForegroundColor();
        m_edgeWidth = ((ProgressPolylineConnection) m_edge.getFigure()).getLineWidth();
        m_markedEdge = m_edge;
        ((ProgressPolylineConnection) m_markedEdge.getFigure()).setLineWidth(m_edgeWidth + 3);
        m_markedEdge.getFigure().setForegroundColor(RED);
        // workaround for eclipse bug 393868 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=393868)
        WindowsDNDHelper.hideDragImage();
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) 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) ProgressPolylineConnection(org.knime.workbench.editor2.figures.ProgressPolylineConnection) Point(org.eclipse.draw2d.geometry.Point)

Example 7 with ConnectionContainerEditPart

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

the class NewWorkflowContainerEditPolicy method handleNodeDrop.

/**
 * @param manager the workflow manager
 * @param factory the ndoe factory
 * @param request the drop request
 */
private Command handleNodeDrop(final WorkflowManager manager, final NodeFactory<? extends NodeModel> factory, final CreateDropRequest request) {
    RequestType requestType = request.getRequestType();
    Point location = request.getLocation();
    boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
    if (requestType.equals(RequestType.CREATE)) {
        // create a new node
        return new CreateNodeCommand(manager, factory, location, snapToGrid);
    } else {
        AbstractEditPart editPart = request.getEditPart();
        if (requestType.equals(RequestType.INSERT)) {
            // insert new node into connection
            InsertNodeCommand insertCommand = new InsertNodeCommand(manager, factory, location, snapToGrid, (ConnectionContainerEditPart) editPart);
            if (request.createSpace()) {
                CreateSpaceAction csa = new CreateSpaceAction((WorkflowEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(), request.getDirection(), request.getDistance());
                return insertCommand.chain(csa.createCompoundCommand(csa.selectedParts()));
            } else {
                return insertCommand;
            }
        } else if (requestType.equals(RequestType.REPLACE)) {
            // replace node with a node
            return new ReplaceNodeCommand(manager, factory, location, snapToGrid, (NodeContainerEditPart) editPart);
        } else {
            return null;
        }
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) ReplaceNodeCommand(org.knime.workbench.editor2.commands.ReplaceNodeCommand) Point(org.eclipse.draw2d.geometry.Point) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand) InsertNodeCommand(org.knime.workbench.editor2.commands.InsertNodeCommand) CreateSpaceAction(org.knime.workbench.editor2.actions.CreateSpaceAction) RequestType(org.knime.workbench.editor2.CreateDropRequest.RequestType)

Example 8 with ConnectionContainerEditPart

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

the class NewWorkflowContainerEditPolicy method handleMetaNodeTemplateDrop.

/**
 * @param manager the workflow manager
 * @param request the drop request
 * @param filestore the location of the metanode template
 */
private Command handleMetaNodeTemplateDrop(final WorkflowManager manager, final CreateDropRequest request, final AbstractExplorerFileStore filestore) {
    RequestType requestType = request.getRequestType();
    Point location = request.getLocation();
    boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
    if (requestType.equals(RequestType.CREATE)) {
        // create metanode from template
        return new CreateMetaNodeTemplateCommand(manager, filestore, location, snapToGrid);
    } else {
        AbstractEditPart editPart = request.getEditPart();
        if (requestType.equals(RequestType.INSERT)) {
            // insert metanode from template into connection
            InsertMetaNodeTempalteCommand insertCommand = new InsertMetaNodeTempalteCommand(manager, filestore, location, snapToGrid, (ConnectionContainerEditPart) editPart);
            if (request.createSpace()) {
                CreateSpaceAction csa = new CreateSpaceAction((WorkflowEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(), request.getDirection(), request.getDistance());
                return insertCommand.chain(csa.createCompoundCommand(csa.selectedParts()));
            } else {
                return insertCommand;
            }
        } else if (requestType.equals(RequestType.REPLACE)) {
            // replace node with metanode from template
            return new ReplaceMetaNodeTemplateCommand(manager, filestore, location, snapToGrid, (NodeContainerEditPart) editPart);
        } else {
            return null;
        }
    }
}
Also used : ReplaceMetaNodeTemplateCommand(org.knime.workbench.editor2.commands.ReplaceMetaNodeTemplateCommand) CreateMetaNodeTemplateCommand(org.knime.workbench.editor2.commands.CreateMetaNodeTemplateCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) Point(org.eclipse.draw2d.geometry.Point) InsertMetaNodeTempalteCommand(org.knime.workbench.editor2.commands.InsertMetaNodeTempalteCommand) CreateSpaceAction(org.knime.workbench.editor2.actions.CreateSpaceAction) RequestType(org.knime.workbench.editor2.CreateDropRequest.RequestType)

Example 9 with ConnectionContainerEditPart

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

the class WorkflowEditorDropTargetListener method selectNodes.

/**
 * Selects all nodes after this node which are around the same y coordinate and closer than
 * {@link WorkflowEditorDropTargetListener#m_distanceToMoveTarget} +
 * {@link WorkflowEditorDropTargetListener#MINIMUM_NODE_DISTANCE}
 *
 * All selected elements will be moved by the move action.
 *
 * @param node from which on the selection starts
 */
private void selectNodes(final NodeContainerEditPart node, final double zoom) {
    getViewer().getSelectionManager().appendSelection(node);
    for (ConnectionContainerEditPart c : node.getOutgoingConnections()) {
        EditPart source = c.getSource().getParent();
        EditPart target = c.getTarget().getParent();
        if (source instanceof NodeContainerEditPart && target instanceof NodeContainerEditPart) {
            NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
            NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
            int[] sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
            int[] targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
            sourceBounds = recomputeBounds(sourceBounds);
            targetBounds = recomputeBounds(targetBounds);
            int sourceYTop = sourceBounds[1];
            int sourceYBot = sourceYTop + sourceBounds[3] + sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
            int targetYTop = targetBounds[1];
            int targetYBot = targetYTop + targetBounds[3] + targetNode.getNodeAnnotationEditPart().getModel().getHeight();
            if (selectSuccessor(sourceBounds[0], targetBounds[0], sourceYTop, sourceYBot, targetYTop, targetYBot, zoom)) {
                selectNodes(targetNode, zoom);
            }
        }
    }
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) 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) Point(org.eclipse.draw2d.geometry.Point)

Example 10 with ConnectionContainerEditPart

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

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