Search in sources :

Example 71 with NodeContainerEditPart

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

the class MoveNodeAbstractAction method createCompoundCommand.

/**
 * @param nodeParts selected nodes and connections
 * @return compound command of all move commands or null if no edit part is selected
 */
public CompoundCommand createCompoundCommand(final NodeContainerEditPart[] nodeParts) {
    List<EditPart> selParts = getMoveableSelectedEditParts();
    if (selParts.size() < 1) {
        return null;
    }
    // should be initialized from the pref page
    // (0, 1) moves down, (-1, 0) moves left
    Point offset = getMoveDirection();
    int signX = (int) Math.signum(offset.x);
    int signY = (int) Math.signum(offset.y);
    CompoundCommand compoundCommand = new CompoundCommand();
    if (getEditor().getEditorSnapToGrid()) {
        // adjust offset to grid size (note: arguments must be not-negative numbers)
        offset = new Point(signX * getEditor().getEditorGridXOffset(signX * offset.x), signY * getEditor().getEditorGridYOffset(signY * offset.y));
        if (selParts.size() == 1) {
            // with one element we move the element onto the grid if it is off
            Point refLoc = null;
            if (selParts.get(0) instanceof NodeContainerEditPart) {
                NodeContainerEditPart node = (NodeContainerEditPart) selParts.get(0);
                NodeContainerFigure figure = (NodeContainerFigure) node.getFigure();
                Point iconOffset = SnapIconToGrid.getGridRefPointOffset(figure);
                refLoc = new Point(figure.getBounds().x, figure.getBounds().y);
                refLoc.translate(iconOffset);
            } else {
                IFigure fig = ((AbstractWorkflowEditPart) selParts.get(0)).getFigure();
                refLoc = new Point(fig.getBounds().x, fig.getBounds().y);
            }
            Point gridLoc = new Point(0, 0);
            Point prevGridLoc = getEditor().getPrevGridLocation(refLoc);
            Point nextGridLoc = getEditor().getNextGridLocation(refLoc);
            boolean toGrid = false;
            if (signX < 0) {
                gridLoc.x = prevGridLoc.x;
                toGrid = (gridLoc.x != refLoc.x);
            }
            if (signX > 0) {
                gridLoc.x = nextGridLoc.x;
                toGrid = (gridLoc.x != refLoc.x);
            }
            if (signY < 0) {
                gridLoc.y = prevGridLoc.y;
                toGrid = (gridLoc.y != refLoc.y);
            }
            if (signY > 0) {
                gridLoc.y = nextGridLoc.y;
                toGrid = (gridLoc.y != refLoc.y);
            }
            if (toGrid) {
                offset = new Point(Math.abs(gridLoc.x - refLoc.x) * signX, Math.abs(gridLoc.y - refLoc.y) * signY);
            }
        }
    }
    int noNodes = 0;
    // apply the offset to all selected elements
    for (EditPart epart : selParts) {
        // apply to selected nodes
        if (epart instanceof NodeContainerEditPart) {
            NodeContainerEditPart node = (NodeContainerEditPart) epart;
            noNodes++;
            NodeContainerUI nc = node.getNodeContainer();
            NodeContainerFigure figure = (NodeContainerFigure) node.getFigure();
            Rectangle bounds = figure.getBounds().getCopy();
            bounds.translate(offset);
            ChangeNodeBoundsCommand cmd = new ChangeNodeBoundsCommand(Wrapper.unwrapNC(nc), figure, bounds);
            compoundCommand.add(cmd);
        }
        // apply to all selected workflow annotations
        if ((epart instanceof AnnotationEditPart) && !(epart instanceof NodeAnnotationEditPart)) {
            AnnotationEditPart anno = (AnnotationEditPart) epart;
            Rectangle bounds = anno.getFigure().getBounds().getCopy();
            bounds.translate(offset);
            ChangeAnnotationBoundsCommand cmd = new ChangeAnnotationBoundsCommand(getManager(), anno, bounds);
            compoundCommand.add(cmd);
        }
    }
    if (noNodes > 1) {
        // if multiple nodes are selected/moved we need to move fully contained connections as well
        ConnectionContainerEditPart[] conns = WorkflowSelectionDragEditPartsTracker.getEmbracedConnections(selParts);
        for (ConnectionContainerEditPart conn : conns) {
            ChangeBendPointLocationCommand connCmd = new ChangeBendPointLocationCommand(conn, offset.getCopy(), null);
            compoundCommand.add(connCmd);
        }
    }
    return compoundCommand;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) ChangeNodeBoundsCommand(org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) AbstractWorkflowEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowEditPart) EditPart(org.eclipse.gef.EditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) 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) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) AbstractWorkflowEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowEditPart) IFigure(org.eclipse.draw2d.IFigure) ChangeBendPointLocationCommand(org.knime.workbench.editor2.commands.ChangeBendPointLocationCommand)

Example 72 with NodeContainerEditPart

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

the class OpenDialogAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length > 0) {
        final NodeContainerEditPart nodeContainerEditPart = nodeParts[0];
        nodeContainerEditPart.openNodeDialog();
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart)

Example 73 with NodeContainerEditPart

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

the class OpenDialogAction method internalCalculateEnabled.

/**
 * @return <code>true</code> if at we have a single node which has a
 *         dialog
 * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] selected = getSelectedParts(NodeContainerEditPart.class);
    if (selected.length != 1) {
        return false;
    }
    NodeContainerEditPart part = selected[0];
    return part.getNodeContainer().hasDialog();
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart)

Example 74 with NodeContainerEditPart

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

the class RevealMetaNodeTemplateAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    List<NodeID> candidateList = new ArrayList<NodeID>();
    List<AbstractExplorerFileStore> templates = new ArrayList<AbstractExplorerFileStore>();
    for (NodeContainerEditPart p : nodes) {
        Object model = p.getModel();
        if (model instanceof WorkflowManagerUI) {
            NodeContext.pushContext(Wrapper.unwrapNC(p.getNodeContainer()));
            try {
                WorkflowManager wm = Wrapper.unwrapWFM((UI) model);
                MetaNodeTemplateInformation i = wm.getTemplateInformation();
                if (Role.Link.equals(i.getRole())) {
                    candidateList.add(wm.getID());
                    AbstractExplorerFileStore template = ExplorerFileSystem.INSTANCE.getStore(i.getSourceURI());
                    if (template != null) {
                        templates.add(template);
                    }
                }
            } finally {
                NodeContext.removeLastContext();
            }
        }
    }
    List<Object> treeObjects = ContentDelegator.getTreeObjectList(templates);
    if (treeObjects != null && treeObjects.size() > 0) {
        IViewReference[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
        for (IViewReference view : views) {
            if (ExplorerView.ID.equals(view.getId())) {
                ExplorerView explorerView = (ExplorerView) view.getView(true);
                explorerView.getViewer().setSelection(new StructuredSelection(treeObjects), true);
            }
        }
    }
}
Also used : ExplorerView(org.knime.workbench.explorer.view.ExplorerView) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) IViewReference(org.eclipse.ui.IViewReference) NodeID(org.knime.core.node.workflow.NodeID) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 75 with NodeContainerEditPart

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

the class PasteAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    ClipboardObject clipObject = getEditor().getClipboardContent();
    ShiftCalculator shiftCalculator = newShiftCalculator();
    PasteFromWorkflowPersistorCommand pasteCommand = new PasteFromWorkflowPersistorCommand(getEditor(), clipObject, shiftCalculator);
    // enables undo
    getCommandStack().execute(pasteCommand);
    // update the actions
    getEditor().updateActions();
    // Give focus to the editor again. Otherwise the actions (selection)
    // is not updated correctly.
    getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
}
Also used : ClipboardObject(org.knime.workbench.editor2.ClipboardObject) PasteFromWorkflowPersistorCommand(org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand) ShiftCalculator(org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand.ShiftCalculator)

Aggregations

NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)77 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)28 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)24 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)16 EditPart (org.eclipse.gef.EditPart)15 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)14 Point (org.eclipse.draw2d.geometry.Point)11 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)11 NodeContainer (org.knime.core.node.workflow.NodeContainer)9 NodeID (org.knime.core.node.workflow.NodeID)9 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)9 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)9 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)9 ArrayList (java.util.ArrayList)8 GUIWorkflowCipherPrompt (org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt)8 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)6 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)6 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 MessageBox (org.eclipse.swt.widgets.MessageBox)5