Search in sources :

Example 1 with ExpandMetaNodeCommand

use of org.knime.workbench.editor2.commands.ExpandMetaNodeCommand in project knime-core by knime.

the class ExpandMetaNodeAction method runOnNodes.

/**
 * Expand metanode!
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length < 1) {
        return;
    }
    LOGGER.debug("Creating 'Expand MetaNode' job for " + nodeParts.length + " node(s)...");
    try {
        WorkflowManager manager = getManager();
        WorkflowManagerUI metaNode = (WorkflowManagerUI) nodeParts[0].getNodeContainer();
        if (!Wrapper.unwrapWFM(metaNode).unlock(new GUIWorkflowCipherPrompt())) {
            return;
        }
        // reset the metanode
        if (manager.canResetNode(metaNode.getID())) {
            // yes: ask if we can reset, otherwise bail
            MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.OK | SWT.CANCEL);
            mb.setMessage("Executed Nodes inside Metanode will be reset" + " - are you sure?");
            mb.setText("Reset Executed Nodes");
            int dialogreturn = mb.open();
            if (dialogreturn == SWT.CANCEL) {
                return;
            }
            // perform reset
            if (manager.canResetNode(metaNode.getID())) {
                manager.resetAndConfigureNode(metaNode.getID());
            }
        }
        String res = manager.canExpandMetaNode(metaNode.getID());
        if (res != null) {
            throw new IllegalArgumentException(res);
        }
        ExpandMetaNodeCommand emnc = new ExpandMetaNodeCommand(manager, metaNode.getID(), getEditor());
        execute(emnc);
    } catch (IllegalArgumentException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
        mb.setMessage("Sorry, expanding Metanode failed: " + e.getMessage());
        mb.setText("Expand failed");
        mb.open();
    }
    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 : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) GUIWorkflowCipherPrompt(org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt) MessageBox(org.eclipse.swt.widgets.MessageBox) ExpandMetaNodeCommand(org.knime.workbench.editor2.commands.ExpandMetaNodeCommand)

Aggregations

MessageBox (org.eclipse.swt.widgets.MessageBox)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)1 ExpandMetaNodeCommand (org.knime.workbench.editor2.commands.ExpandMetaNodeCommand)1 GUIWorkflowCipherPrompt (org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt)1