Search in sources :

Example 1 with ConvertSubNodeToMetaNodeCommand

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

the class ConvertSubNodeToMetaNodeAction method runOnNodes.

/**
 * Expand metanode!
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length < 1) {
        return;
    }
    try {
        WorkflowManager manager = getManager();
        SubNodeContainer subNode = Wrapper.unwrap(nodeParts[0].getNodeContainer(), SubNodeContainer.class);
        if (!subNode.getWorkflowManager().unlock(new GUIWorkflowCipherPrompt())) {
            return;
        }
        // before we do anything, let's see if the convert will reset the metanode
        if (manager.canResetNode(subNode.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 WrappedNode 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(subNode.getID())) {
                manager.resetAndConfigureNode(subNode.getID());
            }
        }
        ConvertSubNodeToMetaNodeCommand cmnc = new ConvertSubNodeToMetaNodeCommand(manager, subNode.getID());
        execute(cmnc);
    } catch (IllegalArgumentException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
        mb.setMessage("Sorry, Unwrapping WrappedNode failed: " + e.getMessage());
        mb.setText("Convert 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 : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ConvertSubNodeToMetaNodeCommand(org.knime.workbench.editor2.commands.ConvertSubNodeToMetaNodeCommand) GUIWorkflowCipherPrompt(org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

MessageBox (org.eclipse.swt.widgets.MessageBox)1 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 ConvertSubNodeToMetaNodeCommand (org.knime.workbench.editor2.commands.ConvertSubNodeToMetaNodeCommand)1 GUIWorkflowCipherPrompt (org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt)1