use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class RevealMetaNodeTemplateAction 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 (model instanceof WorkflowManagerUI) {
NodeContext.pushContext(Wrapper.unwrapNC(p.getNodeContainer()));
try {
WorkflowManager wm = Wrapper.unwrapWFM((UI) model);
MetaNodeTemplateInformation i = wm.getTemplateInformation();
if (Role.Link.equals(i.getRole())) {
candidateList.add(wm.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.NodeID in project knime-core by knime.
the class SaveAsMetaNodeTemplateAction method getDefaultSaveLocation.
private ContentObject getDefaultSaveLocation(final WorkflowManager arg) {
final NodeID id = arg.getID();
URI uri = DisconnectMetaNodeLinkCommand.RECENTLY_USED_URIS.get(id);
if (uri == null || !ExplorerFileSystem.SCHEME.equals(uri.getScheme())) {
return null;
}
final AbstractExplorerFileStore oldTemplateFileStore = ExplorerFileSystem.INSTANCE.getStore(uri);
final AbstractExplorerFileStore parent = oldTemplateFileStore == null ? null : oldTemplateFileStore.getParent();
if (parent != null) {
return ContentObject.forFile(parent);
}
return null;
}
use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class CreateMetaNodeCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// Add node to workflow and get the container
try {
WorkflowManager wfm = getHostWFM();
m_copyContent = wfm.paste(m_persistor);
NodeID[] nodeIDs = m_copyContent.getNodeIDs();
if (nodeIDs.length > 0) {
NodeID first = nodeIDs[0];
m_container = wfm.getNodeContainer(first);
// create extra info and set it
NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(m_snapToGrid).setIsDropLocation(true).build();
m_container.setUIInformation(info);
}
} catch (Throwable t) {
// if fails notify the user
String error = "Metanode cannot be created";
LOGGER.debug(error + ": " + t.getMessage(), t);
MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
mb.setText(error);
mb.setMessage("The metanode could not be created " + "due to the following reason:\n" + t.getMessage());
mb.open();
return;
}
}
use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class CreateMetaNodeCommand method undo.
/**
* {@inheritDoc}
*/
@Override
public void undo() {
NodeID[] ids = m_copyContent.getNodeIDs();
if (LOGGER.isDebugEnabled()) {
String debug = "Removing node";
if (ids.length == 1) {
debug = debug + " " + ids[0];
} else {
debug = debug + "s " + Arrays.asList(ids);
}
LOGGER.debug(debug);
}
WorkflowManager wm = getHostWFM();
if (canUndo()) {
for (NodeID id : ids) {
wm.removeNode(id);
}
for (WorkflowAnnotation anno : m_copyContent.getAnnotations()) {
wm.removeAnnotation(anno);
}
} else {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Operation no allowed", "The node(s) " + Arrays.asList(ids) + " can currently not be removed");
}
}
use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class CreateNewConnectedMetaNodeCommand method createNewNode.
/**
* {@inheritDoc}
*/
@Override
protected NodeID createNewNode() {
WorkflowCopyContent.Builder content = WorkflowCopyContent.builder();
content.setNodeIDs(m_sourceID);
WorkflowManager hostWFM = getHostWFM();
NodeID[] copied = hostWFM.copyFromAndPasteHere(m_source, content.build()).getNodeIDs();
assert copied.length == 1;
return copied[0];
}
Aggregations