Search in sources :

Example 1 with WorkflowRootEditPart

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

the class HideNodeNamesAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void runOnNodes(final NodeContainerEditPart[] parts) {
    ScrollingGraphicalViewer provider = (ScrollingGraphicalViewer) getEditor().getEditorSite().getSelectionProvider();
    if (provider == null) {
        return;
    }
    // get parent of the node parts
    WorkflowRootEditPart editorPart = (WorkflowRootEditPart) provider.getRootEditPart().getChildren().get(0);
    editorPart.changeHideNodeNames();
    for (NodeContainerEditPart edit : getAllParts(NodeContainerEditPart.class)) {
        edit.callHideNodeName();
    }
}
Also used : ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart)

Example 2 with WorkflowRootEditPart

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

the class NodeContainerEditPart method refreshBounds.

/**
 * Adjusts the height and width of the node's figure. It automatically sets them to the preferred height/width of
 * the figure (which might change if the warning icons change). It doesn't change x/y position of the figure. It
 * does change width and height.
 */
private void refreshBounds() {
    NodeUIInformation uiInfo = getNodeContainer().getUIInformation();
    int[] bounds = uiInfo.getBounds();
    WorkflowRootEditPart parent = (WorkflowRootEditPart) getParent();
    NodeContainerFigure fig = (NodeContainerFigure) getFigure();
    Dimension pref = fig.getPreferredSize();
    boolean set = false;
    if (pref.width != bounds[2]) {
        bounds[2] = pref.width;
        set = true;
    }
    if (pref.height != bounds[3]) {
        bounds[3] = pref.height;
        set = true;
    }
    if (set) {
        // notify uiInfo listeners (e.g. node annotations)
        m_uiListenerActive = false;
        getNodeContainer().setUIInformation(NodeUIInformation.builder().setNodeLocation(bounds[0], bounds[1], bounds[2], bounds[3]).build());
        m_uiListenerActive = true;
    }
    // since ver2.3.0 all coordinates are relative to the icon
    Point offset = fig.getOffsetToRefPoint(uiInfo);
    bounds[0] -= offset.x;
    bounds[1] -= offset.y;
    Rectangle rect = new Rectangle(bounds[0], bounds[1], bounds[2], bounds[3]);
    fig.setBounds(rect);
    parent.setLayoutConstraint(this, fig, rect);
}
Also used : NodeUIInformation(org.knime.core.node.workflow.NodeUIInformation) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Example 3 with WorkflowRootEditPart

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

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

the class SnapIconToGrid method snapRectangle.

/**
 * {@inheritDoc}
 */
@Override
public int snapRectangle(final Request request, final int snapLocations, final PrecisionRectangle rect, final PrecisionRectangle result) {
    PrecisionRectangle r = rect;
    if (request instanceof ChangeBoundsRequest) {
        EditPart refPart = getReferencePart(((ChangeBoundsRequest) request).getEditParts(), ((ChangeBoundsRequest) request).getLocation(), ((ChangeBoundsRequest) request).getMoveDelta());
        if (refPart instanceof NodeContainerEditPart) {
            // adjust the rectangle to snap the center of the icon of the node
            NodeContainerEditPart contPart = (NodeContainerEditPart) refPart;
            NodeContainerFigure fig = (NodeContainerFigure) contPart.getFigure();
            Point iconOffset = getIconOffset(fig);
            r = rect.getPreciseCopy();
            r.translate(iconOffset);
        } else if (refPart instanceof NodeAnnotationEditPart) {
            // the rect is the annotation outline - adjust it to snap the center of the corresponding node icon
            NodeAnnotationEditPart annoPart = (NodeAnnotationEditPart) refPart;
            WorkflowRootEditPart parent = (WorkflowRootEditPart) annoPart.getParent();
            IFigure annoFig = annoPart.getFigure();
            NodeAnnotation anno = (NodeAnnotation) annoPart.getModel();
            NodeContainerEditPart nodePart = (NodeContainerEditPart) m_container.getViewer().getEditPartRegistry().get(parent.getWorkflowManager().getNodeContainer(anno.getNodeID()));
            NodeContainerFigure nodeFig = (NodeContainerFigure) nodePart.getFigure();
            Point iconOffset = getIconOffset(nodeFig);
            int xOff = nodeFig.getBounds().x - annoFig.getBounds().x;
            xOff += iconOffset.x;
            int yOff = iconOffset.y - nodeFig.getBounds().height;
            r = rect.getPreciseCopy();
            r.translate(new Point(xOff, yOff));
        }
    }
    return super.snapRectangle(request, snapLocations, r, result);
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) EditPart(org.eclipse.gef.EditPart) Point(org.eclipse.draw2d.geometry.Point) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 5 with WorkflowRootEditPart

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

the class WorkflowEditor method getClosestGridLocation.

/**
 * Returns the closest location that is located on the grid.
 *
 * @param loc reference point for the closest grid location, must be translated relative to the container
 * @return closest grid point
 */
public Point getClosestGridLocation(final Point loc) {
    Point location = loc.getCopy();
    IFigure gridContainer = ((WorkflowRootEditPart) getViewer().getRootEditPart().getContents()).getFigure();
    gridContainer.translateToRelative(location);
    Point result = location.getCopy();
    int locX = loc.x;
    int gridX = getEditorGridX();
    if (gridX > 1) {
        // distance to the left grid line (or right, if locX is negative)
        int leftGrid = (locX / gridX) * gridX;
        if (Math.abs(locX - leftGrid) <= (gridX / 2)) {
            result.x = leftGrid;
        } else {
            // location is closer to the next grid (right of the location, or left if x is negative)
            result.x = leftGrid + (((int) Math.signum(locX)) * gridX);
        }
    }
    int locY = loc.y;
    int gridY = getEditorGridY();
    if (gridY > 1) {
        // distance to the next upper grid line (or lower line, if y is negative)
        int upperGrid = (locY / gridY) * gridY;
        if (Math.abs(locY - upperGrid) <= (gridY / 2)) {
            // location is closer to the upper grid line (or lower line, if y is negative)
            result.y = upperGrid;
        } else {
            // location is closer to the next lower grid
            result.y = upperGrid + (((int) Math.signum(locY)) * gridY);
        }
    }
    return result;
}
Also used : WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)18 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)7 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)6 NodeContainerFigure (org.knime.workbench.editor2.figures.NodeContainerFigure)5 Point (org.eclipse.draw2d.geometry.Point)4 EditPart (org.eclipse.gef.EditPart)4 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 EditPartViewer (org.eclipse.gef.EditPartViewer)3 IEditorPart (org.eclipse.ui.IEditorPart)3 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)3 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)3 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)3 IFigure (org.eclipse.draw2d.IFigure)2 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)2 ZoomManager (org.eclipse.gef.editparts.ZoomManager)2 ScrollingGraphicalViewer (org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)2 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)2 NodeContainer (org.knime.core.node.workflow.NodeContainer)2 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)2