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);
}
}
}
}
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);
}
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;
}
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);
}
}
}
}
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));
}
}
Aggregations