Search in sources :

Example 21 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class LockSubNodeAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    if (nodes.length != 1) {
        return;
    }
    Object model = nodes[0].getModel();
    if (!(Wrapper.wraps(model, SubNodeContainer.class))) {
        return;
    }
    WorkflowManager metaNodeWFM = Wrapper.unwrap((UI) model, SubNodeContainer.class).getWorkflowManager();
    final Shell shell = Display.getCurrent().getActiveShell();
    if (!metaNodeWFM.unlock(new GUIWorkflowCipherPrompt())) {
        return;
    }
    LockMetaNodeDialog lockDialog = new LockMetaNodeDialog(shell, metaNodeWFM);
    if (lockDialog.open() != Window.OK) {
        return;
    }
    String password = lockDialog.getPassword();
    String hint = lockDialog.getPasswordHint();
    try {
        metaNodeWFM.setWorkflowPassword(password, hint);
    } catch (NoSuchAlgorithmException e) {
        String msg = "Unable to encrypt Wrapped Metanode: " + e.getMessage();
        LOGGER.error(msg, e);
        MessageDialog.openError(shell, "Wrapped Metanode encrypt", msg);
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) Shell(org.eclipse.swt.widgets.Shell) UI(org.knime.core.ui.UI) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) GUIWorkflowCipherPrompt(org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt)

Example 22 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class PasteActionContextMenu method newShiftCalculator.

/**
 * {@inheritDoc}
 */
@Override
protected ShiftCalculator newShiftCalculator() {
    return new ShiftCalculator() {

        /**
         * {@inheritDoc}
         */
        @Override
        public int[] calculateShift(final Iterable<int[]> boundsList, final WorkflowManager manager, final ClipboardObject clipObject) {
            int x = getEditor().getSelectionTool().getXLocation();
            int y = getEditor().getSelectionTool().getYLocation();
            int smallestX = Integer.MAX_VALUE;
            int smallestY = Integer.MAX_VALUE;
            for (int[] bounds : boundsList) {
                int currentX = bounds[0];
                int currentY = bounds[1];
                if (currentX < smallestX) {
                    smallestX = currentX;
                }
                if (currentY < smallestY) {
                    smallestY = currentY;
                }
            }
            ZoomManager zoomManager = (ZoomManager) getEditor().getViewer().getProperty(ZoomManager.class.toString());
            Point viewPortLocation = zoomManager.getViewport().getViewLocation();
            x += viewPortLocation.x;
            y += viewPortLocation.y;
            double zoom = zoomManager.getZoom();
            x /= zoom;
            y /= zoom;
            int shiftx = x - smallestX;
            int shifty = y - smallestY;
            if (getEditor().getEditorSnapToGrid()) {
                shiftx = getEditor().getEditorGridXOffset(shiftx);
                shifty = getEditor().getEditorGridYOffset(shifty);
            }
            return new int[] { shiftx, shifty };
        }
    };
}
Also used : ClipboardObject(org.knime.workbench.editor2.ClipboardObject) ZoomManager(org.eclipse.gef.editparts.ZoomManager) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Point(org.eclipse.draw2d.geometry.Point) ShiftCalculator(org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand.ShiftCalculator) Point(org.eclipse.draw2d.geometry.Point)

Example 23 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class ResumeLoopAction method runOnNodes.

/**
 * Resume paused loop.
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    LOGGER.debug("Creating 'Resume Loop Execution' job for " + nodeParts.length + " node(s)...");
    WorkflowManager manager = getManager();
    for (NodeContainerEditPart p : nodeParts) {
        NodeContainerUI nc = p.getNodeContainer();
        if (Wrapper.wraps(nc, NativeNodeContainer.class)) {
            NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
            if (nnc.isModelCompatibleTo(LoopEndNode.class) && nnc.getLoopStatus().equals(LoopStatus.PAUSED)) {
                manager.resumeLoopExecution(nnc, /*oneStep=*/
                false);
            }
        }
    }
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) LoopEndNode(org.knime.core.node.workflow.LoopEndNode)

Example 24 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class SaveAsMetaNodeTemplateAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    if (nodes.length < 1) {
        return;
    }
    WorkflowManager wm = Wrapper.unwrapWFM(nodes[0].getNodeContainer());
    List<String> validMountPointList = new ArrayList<String>();
    // Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().findView(ID)
    for (Map.Entry<String, AbstractContentProvider> entry : ExplorerMountTable.getMountedContent().entrySet()) {
        AbstractContentProvider contentProvider = entry.getValue();
        if (contentProvider.isWritable() && contentProvider.canHostMetaNodeTemplates()) {
            validMountPointList.add(entry.getKey());
        }
    }
    if (validMountPointList.isEmpty()) {
        throw new IllegalStateException("No valid mount points found - " + "this is inconsistent with calculateEnabled()");
    }
    String[] validMountPoints = validMountPointList.toArray(new String[0]);
    final Shell shell = Display.getCurrent().getActiveShell();
    ContentObject defSel = getDefaultSaveLocation(wm);
    SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(shell, validMountPoints, defSel);
    dialog.setTitle("Save As Metanode Template");
    dialog.setHeader("Select destination workflow group for metanode template");
    dialog.setValidator(new Validator() {

        @Override
        public String validateSelectionValue(final AbstractExplorerFileStore selection, final String name) {
            final AbstractExplorerFileInfo info = selection.fetchInfo();
            if (info.isWorkflowGroup()) {
                return null;
            }
            return "Only workflow groups can be selected as target.";
        }
    });
    if (dialog.open() != Window.OK) {
        return;
    }
    AbstractExplorerFileStore target = dialog.getSelection();
    AbstractContentProvider contentProvider = target.getContentProvider();
    contentProvider.saveMetaNodeTemplate(wm, target);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) ContentObject(org.knime.workbench.explorer.view.ContentObject) Shell(org.eclipse.swt.widgets.Shell) SpaceResourceSelectionDialog(org.knime.workbench.explorer.dialogs.SpaceResourceSelectionDialog) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) AbstractExplorerFileInfo(org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo) Map(java.util.Map) Validator(org.knime.workbench.explorer.dialogs.Validator)

Example 25 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.

the class SelectLoopAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    WorkflowManager wfm = getManager();
    for (NodeContainerEditPart selNode : nodeParts) {
        NodeContainerUI selNC = selNode.getNodeContainer();
        if (selNC instanceof SingleNodeContainerUI) {
            EditPartViewer viewer = selNode.getViewer();
            List<NodeContainer> loopNodes = wfm.getNodesInScope(Wrapper.unwrap(selNC, SingleNodeContainer.class));
            for (NodeContainer nc : loopNodes) {
                NodeContainerEditPart sel = (NodeContainerEditPart) viewer.getEditPartRegistry().get(NodeContainerWrapper.wrap(nc));
                viewer.appendSelection(sel);
            }
        }
    }
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) EditPartViewer(org.eclipse.gef.EditPartViewer) NodeContainer(org.knime.core.node.workflow.NodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)99 NodeID (org.knime.core.node.workflow.NodeID)38 NodeContainer (org.knime.core.node.workflow.NodeContainer)22 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)19 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)14 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)14 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)10 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)10 MessageBox (org.eclipse.swt.widgets.MessageBox)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 List (java.util.List)8 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)8 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)8