Search in sources :

Example 11 with SubNodeContainer

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

the class RevealSubNodeTemplateAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    List<NodeID> candidateList = new ArrayList<NodeID>();
    List<AbstractExplorerFileStore> templates = new ArrayList<AbstractExplorerFileStore>();
    for (NodeContainerEditPart p : nodes) {
        Object model = p.getModel();
        if (wraps(model, SubNodeContainer.class)) {
            NodeContext.pushContext(Wrapper.unwrapNC(p.getNodeContainer()));
            try {
                SubNodeContainer snc = unwrap((UI) model, SubNodeContainer.class);
                MetaNodeTemplateInformation i = snc.getTemplateInformation();
                if (Role.Link.equals(i.getRole())) {
                    candidateList.add(snc.getID());
                    AbstractExplorerFileStore template = ExplorerFileSystem.INSTANCE.getStore(i.getSourceURI());
                    if (template != null) {
                        templates.add(template);
                    }
                }
            } finally {
                NodeContext.removeLastContext();
            }
        }
    }
    List<Object> treeObjects = ContentDelegator.getTreeObjectList(templates);
    if (treeObjects != null && treeObjects.size() > 0) {
        IViewReference[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
        for (IViewReference view : views) {
            if (ExplorerView.ID.equals(view.getId())) {
                ExplorerView explorerView = (ExplorerView) view.getView(true);
                explorerView.getViewer().setSelection(new StructuredSelection(treeObjects), true);
            }
        }
    }
}
Also used : ExplorerView(org.knime.workbench.explorer.view.ExplorerView) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) IViewReference(org.eclipse.ui.IViewReference) NodeID(org.knime.core.node.workflow.NodeID) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 12 with SubNodeContainer

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

the class SaveAsSubNodeTemplateAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    if (nodes.length < 1) {
        return;
    }
    SubNodeContainer snc = unwrap(nodes[0].getNodeContainer(), SubNodeContainer.class);
    WorkflowManager wm = snc.getWorkflowManager();
    List<String> validMountPointList = new ArrayList<String>();
    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 Wrapped Metanode Template");
    dialog.setHeader("Select destination workflow group for Wrapped 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.saveSubNodeTemplate(snc, target);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) ContentObject(org.knime.workbench.explorer.view.ContentObject) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) 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 13 with SubNodeContainer

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

the class DisconnectSubNodeLinkCommand method canExecute.

/**
 * We can execute, if all components were 'non-null' in the constructor.
 * {@inheritDoc}
 */
@Override
public boolean canExecute() {
    if (!super.canExecute()) {
        return false;
    }
    if (m_ids == null) {
        return false;
    }
    for (NodeID id : m_ids) {
        NodeContainer nc = getHostWFM().getNodeContainer(id);
        if (nc instanceof SubNodeContainer) {
            SubNodeContainer snc = (SubNodeContainer) nc;
            MetaNodeTemplateInformation lI = snc.getTemplateInformation();
            if (Role.Link.equals(lI.getRole())) {
                return true;
            }
        }
    }
    return false;
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeID(org.knime.core.node.workflow.NodeID) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 14 with SubNodeContainer

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

the class DisconnectSubNodeLinkCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    m_changedIDs = new ArrayList<NodeID>();
    m_oldTemplInfos = new ArrayList<MetaNodeTemplateInformation>();
    WorkflowManager hostWFM = getHostWFM();
    for (NodeID id : m_ids) {
        NodeContainer nc = hostWFM.getNodeContainer(id);
        if (nc instanceof SubNodeContainer) {
            SubNodeContainer snc = (SubNodeContainer) nc;
            MetaNodeTemplateInformation lI = snc.getTemplateInformation();
            if (Role.Link.equals(lI.getRole())) {
                MetaNodeTemplateInformation old = hostWFM.setTemplateInformation(id, MetaNodeTemplateInformation.NONE);
                RECENTLY_USED_URIS.put(snc.getID(), old.getSourceURI());
                m_changedIDs.add(id);
                m_oldTemplInfos.add(old);
            }
        }
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 15 with SubNodeContainer

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

the class SandboxedNodeCreator method copyFileStoreHandlerReference.

/**
 * Sets the file store handlers set on the original node recursively into the sandboxed node. This is
 * only done when the data is _not_ to be copied as the sandboxed node should use the data (includes file stores)
 * from the original node.
 * @param runNC The sandbox node container
 * @param origNCParent the parent of the original workflow
 * @param nullIt <code>true</code> to set a <code>null</code> file store handler - used in
 * {@link SandboxedNode#close()} (otherwise the file store handler is cleared when the temp flow is disposed).
 */
private void copyFileStoreHandlerReference(final NodeContainer runNC, final WorkflowManager origNCParent, final boolean nullIt) {
    final NodeID origParentID = origNCParent.getID();
    final int runNCIndex = runNC.getID().getIndex();
    if (runNC instanceof NativeNodeContainer) {
        NativeNodeContainer runNNC = (NativeNodeContainer) runNC;
        NativeNodeContainer origNNC = origNCParent.getNodeContainer(origParentID.createChild(runNCIndex), NativeNodeContainer.class, true);
        if (origNNC.getNodeContainerState().isExecutionInProgress()) {
            final IFileStoreHandler fsHdl = nullIt ? null : origNNC.getNode().getFileStoreHandler();
            if (!nullIt) {
                runNNC.clearFileStoreHandler();
            }
            runNNC.getNode().setFileStoreHandler(fsHdl);
        }
    } else if (runNC instanceof WorkflowManager) {
        WorkflowManager runWFM = (WorkflowManager) runNC;
        WorkflowManager origWFM = origNCParent.getNodeContainer(origParentID.createChild(runNCIndex), WorkflowManager.class, true);
        runWFM.getNodeContainers().stream().forEach(n -> copyFileStoreHandlerReference(n, origWFM, nullIt));
    } else {
        WorkflowManager runSubWFM = ((SubNodeContainer) runNC).getWorkflowManager();
        WorkflowManager origSubWFM = origNCParent.getNodeContainer(origParentID.createChild(runNCIndex), SubNodeContainer.class, true).getWorkflowManager();
        runSubWFM.getNodeContainers().stream().forEach(n -> copyFileStoreHandlerReference(n, origSubWFM, nullIt));
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ReferencedFile(org.knime.core.internal.ReferencedFile) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) NativeNodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult) NodeContainer(org.knime.core.node.workflow.NodeContainer) Map(java.util.Map) PortObjectInNodeModel(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeModel) PortObjectInNodeFactory(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeFactory) PortType(org.knime.core.node.port.PortType) LockFailedException(org.knime.core.util.LockFailedException) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Collection(java.util.Collection) ConnectionID(org.knime.core.node.workflow.ConnectionID) WorkflowCreationHelper(org.knime.core.node.workflow.WorkflowCreationHelper) Collectors(java.util.stream.Collectors) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) List(java.util.List) BufferedDataTable(org.knime.core.node.BufferedDataTable) Stream(java.util.stream.Stream) Optional(java.util.Optional) CredentialsStore(org.knime.core.node.workflow.CredentialsStore) CheckUtils(org.knime.core.node.util.CheckUtils) PortObject(org.knime.core.node.port.PortObject) NodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NodeContainerExecutionResult) IntStream(java.util.stream.IntStream) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeExecutionJobManagerPool(org.knime.core.node.util.NodeExecutionJobManagerPool) FlowVariable(org.knime.core.node.workflow.FlowVariable) NodeSettings(org.knime.core.node.NodeSettings) BDTInNodeFactory(org.knime.core.node.exec.dataexchange.in.BDTInNodeFactory) ArrayList(java.util.ArrayList) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) ExecutionContext(org.knime.core.node.ExecutionContext) NodeExecutionJobManager(org.knime.core.node.workflow.NodeExecutionJobManager) NodeLogger(org.knime.core.node.NodeLogger) WorkflowExecutionResult(org.knime.core.node.workflow.execresult.WorkflowExecutionResult) NodeFactory(org.knime.core.node.NodeFactory) NodeInPort(org.knime.core.node.workflow.NodeInPort) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) NodeContext(org.knime.core.node.workflow.NodeContext) WorkflowCopyContent(org.knime.core.node.workflow.WorkflowCopyContent) File(java.io.File) PortObjectRepository(org.knime.core.node.exec.dataexchange.PortObjectRepository) NodeExecutionResult(org.knime.core.node.workflow.execresult.NodeExecutionResult) NodeID(org.knime.core.node.workflow.NodeID) FileUtil(org.knime.core.util.FileUtil) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) SubnodeContainerExecutionResult(org.knime.core.node.workflow.execresult.SubnodeContainerExecutionResult) Collections(java.util.Collections) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

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