Search in sources :

Example 6 with AbstractPortEditPart

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

Example 7 with AbstractPortEditPart

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

the class NodeContainerEditPart method getTargetConnectionAnchor.

/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getTargetConnectionAnchor(final Request request) {
    if (!(request instanceof CreateConnectionRequest)) {
        return null;
    }
    CreateConnectionRequest req = (CreateConnectionRequest) request;
    Command cmd = req.getStartCommand();
    if (!(cmd instanceof CreateConnectionCommand)) {
        return null;
    }
    CreateConnectionCommand connCmd = (CreateConnectionCommand) cmd;
    // find a free port that could take the connection
    int portIdx = getFreeInPort(connCmd.getSourceNode(), connCmd.getSourcePortID());
    if (portIdx < 0) {
        return null;
    }
    for (Object part : getChildren()) {
        if (part instanceof AbstractPortEditPart) {
            AbstractPortEditPart port = (AbstractPortEditPart) part;
            if (port.isInPort() && port.getIndex() == portIdx) {
                return port.getTargetConnectionAnchor(request);
            }
        }
    }
    return null;
}
Also used : CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) Command(org.eclipse.gef.commands.Command) ShiftConnectionCommand(org.knime.workbench.editor2.commands.ShiftConnectionCommand) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) Point(org.eclipse.draw2d.geometry.Point)

Example 8 with AbstractPortEditPart

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

the class NodeContainerEditPart method stateChanged.

/**
 * {@inheritDoc}
 */
@Override
public void stateChanged(final NodeStateEvent state) {
    // works because we are retrieving the current state information!
    if (m_updateInProgress.compareAndSet(false, true)) {
        Display display = Display.getDefault();
        if (display.isDisposed()) {
            return;
        }
        display.asyncExec(new Runnable() {

            @Override
            public void run() {
                // let others know we are in the middle of processing
                // this update - they will now need to start their own job.
                NodeContainerFigure fig = (NodeContainerFigure) getFigure();
                m_updateInProgress.set(false);
                if (isActive()) {
                    NodeContainerUI nc = getNodeContainer();
                    fig.setStateFromNC(nc);
                    updateNodeMessage();
                    // reset the tooltip text of the outports
                    for (Object part : getChildren()) {
                        if (part instanceof NodeOutPortEditPart || part instanceof WorkflowInPortEditPart || part instanceof MetaNodeOutPortEditPart) {
                            AbstractPortEditPart outPortPart = (AbstractPortEditPart) part;
                            outPortPart.rebuildTooltip();
                        }
                    }
                    // always refresh visuals (does not seem to do anything
                    // by default though: call repaints on updated figures).
                    refreshVisuals();
                }
            }
        });
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) Display(org.eclipse.swt.widgets.Display) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 9 with AbstractPortEditPart

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

the class SnapToPortGeometry method snapRectangle.

/**
 * {@inheritDoc}
 */
@Override
public int snapRectangle(final Request request, int snapOrientation, PrecisionRectangle baseRect, final PrecisionRectangle result) {
    assert (request instanceof ChangeBoundsRequest) : "Unexpected request type: " + request.getClass();
    ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest) request;
    baseRect = baseRect.getPreciseCopy();
    makeRelative(m_container.getContentPane(), baseRect);
    PrecisionRectangle correction = new PrecisionRectangle();
    makeRelative(m_container.getContentPane(), correction);
    // Recalculate snapping locations if needed
    boolean isClone = request.getType().equals(RequestConstants.REQ_CLONE);
    List exclusionSet = null;
    if (m_rows == null || m_cols == null || isClone != m_cachedCloneBool) {
        m_cachedCloneBool = isClone;
        exclusionSet = Collections.EMPTY_LIST;
        if (!isClone) {
            exclusionSet = changeBoundsRequest.getEditParts();
        }
        populateRowsAndCols(generateSnapPartsList(exclusionSet), exclusionSet);
    }
    if ((snapOrientation & HORIZONTAL) != 0) {
        double xcorrect = getCorrectionFor(m_cols, changeBoundsRequest.getExtendedData(), true, baseRect.preciseX, baseRect.preciseRight());
        if (xcorrect != THRESHOLD) {
            snapOrientation &= ~HORIZONTAL;
            correction.preciseX += xcorrect;
        }
    }
    // get y values of the draged node part ports
    if (exclusionSet != null) {
        List<AbstractPortEditPart> ports = getPorts(exclusionSet);
        Entry[] yValues = new Entry[ports.size()];
        int i = 0;
        for (AbstractPortEditPart port : ports) {
            boolean inport = false;
            if (port instanceof NodeInPortEditPart || port instanceof WorkflowInPortEditPart) {
                inport = true;
            }
            yValues[i] = new Entry(0, getFigureBounds(port).getLeft().y, inport, port.getType());
            i++;
        }
        m_yValues = yValues;
    }
    // get the move delta of the orignial location
    Point moveDeltaPoint = changeBoundsRequest.getMoveDelta();
    WorkflowEditor.adaptZoom(m_zoomManager, moveDeltaPoint, false);
    int moveDelta = moveDeltaPoint.y;
    if ((snapOrientation & VERTICAL) != 0) {
        double ycorrect = THRESHOLD;
        ycorrect = getCorrectionForY(m_rows, changeBoundsRequest.getExtendedData(), m_yValues, moveDelta);
        if (Math.abs(ycorrect) < THRESHOLD) {
            snapOrientation &= ~VERTICAL;
            correction.preciseY += ycorrect;
        }
    }
    if ((snapOrientation & EAST) != 0) {
        double rightCorrection = getCorrectionFor(m_cols, request.getExtendedData(), true, baseRect.preciseRight() - 1, 1);
        if (rightCorrection != THRESHOLD) {
            snapOrientation &= ~EAST;
            correction.preciseWidth += rightCorrection;
        }
    }
    if ((snapOrientation & WEST) != 0) {
        double leftCorrection = getCorrectionFor(m_cols, request.getExtendedData(), true, baseRect.preciseX, -1);
        if (leftCorrection != THRESHOLD) {
            snapOrientation &= ~WEST;
            correction.preciseWidth -= leftCorrection;
            correction.preciseX += leftCorrection;
        }
    }
    if ((snapOrientation & SOUTH) != 0) {
        double bottom = getCorrectionFor(m_rows, request.getExtendedData(), false, baseRect.preciseBottom() - 1, 1);
        if (bottom != THRESHOLD) {
            snapOrientation &= ~SOUTH;
            correction.preciseHeight += bottom;
        }
    }
    if ((snapOrientation & NORTH) != 0) {
        double topCorrection = getCorrectionFor(m_rows, request.getExtendedData(), false, baseRect.preciseY, -1);
        if (topCorrection != THRESHOLD) {
            snapOrientation &= ~NORTH;
            correction.preciseHeight -= topCorrection;
            correction.preciseY += topCorrection;
        }
    }
    correction.updateInts();
    makeAbsolute(m_container.getContentPane(), correction);
    result.preciseX += correction.preciseX;
    result.preciseY += correction.preciseY;
    result.preciseWidth += correction.preciseWidth;
    result.preciseHeight += correction.preciseHeight;
    result.updateInts();
    return snapOrientation;
}
Also used : PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) ArrayList(java.util.ArrayList) PointList(org.eclipse.draw2d.geometry.PointList) List(java.util.List) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart)

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