Search in sources :

Example 1 with SubNodeContainer

use of org.knime.core.node.workflow.SubNodeContainer 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)

Example 2 with SubNodeContainer

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

the class ChangeSubNodeLinkAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length < 1) {
        return;
    }
    SubNodeContainer subNode = Wrapper.unwrap(nodeParts[0].getNodeContainer(), SubNodeContainer.class);
    if (Role.Link.equals(subNode.getTemplateInformation().getRole())) {
        WorkflowManager wfm = subNode.getParent();
        URI targetURI = subNode.getTemplateInformation().getSourceURI();
        LinkType linkType = LinkType.None;
        try {
            if (ResolverUtil.isMountpointRelativeURL(targetURI)) {
                linkType = LinkType.MountpointRelative;
            } else if (ResolverUtil.isWorkflowRelativeURL(targetURI)) {
                linkType = LinkType.WorkflowRelative;
            } else {
                linkType = LinkType.Absolute;
            }
        } catch (IOException e) {
            LOGGER.error("Unable to resolve current link to template " + targetURI + ": " + e.getMessage(), e);
            return;
        }
        String msg = "This is a linked (read-only) Wrapped Metanode. Only the link type can be changed.\n";
        msg += "Please select the new type of the link to the Wrapped Metanode template.\n";
        msg += "(current type: " + linkType + ", current link: " + targetURI + ")\n";
        msg += "The origin of the template will not be changed - just the way it is referenced.";
        LinkPrompt dlg = new LinkPrompt(getEditor().getSite().getShell(), msg, linkType);
        dlg.open();
        if (dlg.getReturnCode() == Window.CANCEL) {
            return;
        }
        LinkType newLinkType = dlg.getLinkType();
        if (linkType.equals(newLinkType)) {
            LOGGER.info("Link type not changes as selected type equals existing type " + targetURI);
            return;
        }
        // as the workflow is local and the template in the same mountID, it should resolve to a file
        URI newURI = null;
        NodeContext.pushContext(subNode);
        try {
            File targetFile = ResolverUtil.resolveURItoLocalFile(targetURI);
            LocalExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.fromLocalFile(targetFile);
            newURI = AbstractContentProvider.createMetanodeLinkUri(subNode, targetfs, newLinkType);
        } catch (IOException e) {
            LOGGER.error("Unable to resolve Wrapped Metanode template URI " + targetURI + ": " + e.getMessage(), e);
            return;
        } catch (URISyntaxException e) {
            LOGGER.error("Unable to resolve Wrapped Metanode template URI " + targetURI + ": " + e.getMessage(), e);
            return;
        } catch (CoreException e) {
            LOGGER.error("Unable to resolve Wrapped Metanode template URI " + targetURI + ": " + e.getMessage(), e);
            return;
        } finally {
            NodeContext.removeLastContext();
        }
        ChangeSubNodeLinkCommand cmd = new ChangeSubNodeLinkCommand(wfm, subNode, targetURI, newURI);
        getCommandStack().execute(cmd);
    } else {
        throw new IllegalStateException("Can only change the type of a template link if the Wrapped Metanode is actually linked to a template - " + subNode + " is not.");
    }
}
Also used : LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) CoreException(org.eclipse.core.runtime.CoreException) LinkType(org.knime.workbench.explorer.view.AbstractContentProvider.LinkType) File(java.io.File) ChangeSubNodeLinkCommand(org.knime.workbench.editor2.commands.ChangeSubNodeLinkCommand)

Example 3 with SubNodeContainer

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

the class ChangeSubNodeLinkAction method internalCalculateEnabled.

/**
 * @return true, if underlying model instance of <code>WorkflowManager</code>, otherwise false
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
    if (nodes.length != 1) {
        return false;
    }
    NodeContainer nc = Wrapper.unwrapNC(nodes[0].getNodeContainer());
    if (!(nc instanceof SubNodeContainer)) {
        return false;
    }
    SubNodeContainer subNode = (SubNodeContainer) nc;
    if (!Role.Link.equals(subNode.getTemplateInformation().getRole()) || subNode.getParent().isWriteProtected()) {
        // sub node must be linked and parent must not forbid the change
        return false;
    }
    // we can reconfigure the template link - but only if template and flow are in the same mountpoint
    URI targetURI = subNode.getTemplateInformation().getSourceURI();
    try {
        if (ResolverUtil.isMountpointRelativeURL(targetURI) || ResolverUtil.isWorkflowRelativeURL(targetURI)) {
            return true;
        }
    } catch (IOException e) {
        return false;
    }
    // we can change absolute links if the mount points of flow and template are the same
    AbstractContentProvider workflowMountPoint = null;
    WorkflowContext wfc = subNode.getProjectWFM().getContext();
    LocalExplorerFileStore fs = ExplorerFileSystem.INSTANCE.fromLocalFile(wfc.getMountpointRoot());
    if (fs != null) {
        workflowMountPoint = fs.getContentProvider();
    }
    if (workflowMountPoint == null) {
        return false;
    }
    AbstractExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.getStore(targetURI);
    if (targetfs == null) {
        return false;
    }
    return workflowMountPoint.equals(targetfs.getContentProvider());
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) IOException(java.io.IOException) URI(java.net.URI)

Example 4 with SubNodeContainer

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

the class NodeUsageComposite method createNodeGrid.

private void createNodeGrid(final SubNodeContainer subNodeContainer, @SuppressWarnings("rawtypes") final Map<NodeIDSuffix, WizardNode> viewNodes) {
    ScrolledComposite scrollPane = new ScrolledComposite(this, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    scrollPane.setExpandHorizontal(true);
    scrollPane.setExpandVertical(true);
    Composite composite = new Composite(scrollPane, SWT.NONE);
    scrollPane.setContent(composite);
    scrollPane.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    composite.setLayout(new GridLayout(3, false));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
    // titles
    new Composite(composite, SWT.NONE);
    /* Placeholder */
    Label wizardLabel = new Label(composite, SWT.CENTER);
    FontData fontData = wizardLabel.getFont().getFontData()[0];
    Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
    wizardLabel.setText("WebPortal /\nWrapped Metanode View");
    wizardLabel.setFont(boldFont);
    Label dialogLabel = new Label(composite, SWT.CENTER);
    dialogLabel.setText("\nWrapped Metanode Dialog");
    dialogLabel.setFont(boldFont);
    // select all checkboxes
    Label selectAllLabel = new Label(composite, SWT.LEFT);
    selectAllLabel.setText("Enable/Disable");
    Button selectAllWizard = createCheckbox(composite);
    Button selectAllDialog = createCheckbox(composite);
    // individual nodes
    for (@SuppressWarnings("rawtypes") Entry<NodeIDSuffix, WizardNode> entry : viewNodes.entrySet()) {
        NodeIDSuffix suffix = entry.getKey();
        NodeID id = suffix.prependParent(subNodeContainer.getWorkflowManager().getID());
        NodeContainer nodeContainer = viewNodes.containsKey(suffix) ? subNodeContainer.getWorkflowManager().getNodeContainer(id) : null;
        createNodeLabelComposite(composite, id, nodeContainer);
        @SuppressWarnings("rawtypes") WizardNode model = entry.getValue();
        Button wizardButton = createCheckbox(composite);
        wizardButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                checkAllSelected(m_wizardUsageMap, selectAllWizard);
            }
        });
        wizardButton.setToolTipText("Enable/disable for usage in WebPortal and wizard execution.");
        wizardButton.setSelection(!((WizardNode<?, ?>) model).isHideInWizard());
        m_wizardUsageMap.put(id, wizardButton);
        if (model instanceof DialogNode) {
            Button dialogButton = createCheckbox(composite);
            dialogButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(final SelectionEvent e) {
                    checkAllSelected(m_dialogUsageMap, selectAllDialog);
                }
            });
            dialogButton.setToolTipText("Enable/disable for usage in wrapped metanode configure dialog.");
            dialogButton.setSelection(!((DialogNode<?, ?>) model).isHideInDialog());
            m_dialogUsageMap.put(id, dialogButton);
        } else {
            new Composite(composite, SWT.NONE);
        /* Placeholder */
        }
    }
    checkAllSelected(m_wizardUsageMap, selectAllWizard);
    checkAllSelected(m_dialogUsageMap, selectAllDialog);
    selectAllWizard.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            selectAllWizard.setGrayed(false);
            for (Button b : m_wizardUsageMap.values()) {
                b.setSelection(selectAllWizard.getSelection());
            }
        }
    });
    if (m_wizardUsageMap.size() < 1) {
        selectAllWizard.setEnabled(false);
    }
    selectAllDialog.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            selectAllDialog.setGrayed(false);
            for (Button b : m_dialogUsageMap.values()) {
                b.setSelection(selectAllDialog.getSelection());
            }
        }
    });
    if (m_dialogUsageMap.size() < 1) {
        selectAllDialog.setEnabled(false);
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FontData(org.eclipse.swt.graphics.FontData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) DialogNode(org.knime.core.node.dialog.DialogNode) WizardNode(org.knime.core.node.wizard.WizardNode) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) NodeID(org.knime.core.node.workflow.NodeID) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Example 5 with SubNodeContainer

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

the class ReconfigureMetaNodeCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    NodeContainer nc = getHostWFM().getNodeContainer(m_metanodeID);
    if (nc instanceof WorkflowManager) {
        if (m_name != null) {
            WorkflowManager metaNode = (WorkflowManager) nc;
            m_oldName = metaNode.getName();
            metaNode.setName(m_name);
        }
        if (m_inPorts != null) {
            m_reverseInports = createReverseOperationList(getHostWFM().getMetanodeInputPortInfo(m_metanodeID), m_inPorts);
            getHostWFM().changeMetaNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
        }
        if (m_outPorts != null) {
            m_reverseOutports = createReverseOperationList(getHostWFM().getMetanodeOutputPortInfo(m_metanodeID), m_outPorts);
            getHostWFM().changeMetaNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
        }
    } else if (nc instanceof SubNodeContainer) {
        SubNodeContainer snc = (SubNodeContainer) nc;
        if (m_name != null) {
            m_oldName = snc.getName();
            snc.setName(m_name);
        }
        if (m_inPorts != null) {
            m_reverseInports = createReverseOperationList(getHostWFM().getSubnodeInputPortInfo(m_metanodeID), m_inPorts);
            getHostWFM().changeSubNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
        }
        if (m_outPorts != null) {
            m_reverseOutports = createReverseOperationList(getHostWFM().getSubnodeOutputPortInfo(m_metanodeID), m_outPorts);
            getHostWFM().changeSubNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
        }
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) MetaPortInfo(org.knime.core.node.port.MetaPortInfo)

Aggregations

SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)26 NodeContainer (org.knime.core.node.workflow.NodeContainer)12 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)12 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)8 NodeID (org.knime.core.node.workflow.NodeID)7 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)4 File (java.io.File)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 AbstractExplorerFileStore (org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore)3 AbstractContentProvider (org.knime.workbench.explorer.view.AbstractContentProvider)3 URI (java.net.URI)2 Map (java.util.Map)2 IAction (org.eclipse.jface.action.IAction)2 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)2 ConnectionID (org.knime.core.node.workflow.ConnectionID)2 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)2 GUIWorkflowCipherPrompt (org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt)2