Search in sources :

Example 1 with ConvertMetaNodeToSubNodeCommand

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

the class ConvertMetaNodeToSubNodeAction method runOnNodes.

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

Aggregations

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