use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class AutoLayoutCommand method undo.
/**
* {@inheritDoc}
*/
@Override
public void undo() {
Map<NodeID, NodeUIInformation> oldPositions = m_layoutMgr.getOldNodeCoordinates();
Map<ConnectionID, ConnectionUIInformation> oldBendpoints = m_layoutMgr.getOldBendpoints();
// re-position nodes
for (Map.Entry<NodeID, NodeUIInformation> e : oldPositions.entrySet()) {
NodeContainer nc = m_wfm.getNodeContainer(e.getKey());
if (nc == null) {
continue;
}
nc.setUIInformation(e.getValue());
}
// re-create bendpoints
for (Map.Entry<ConnectionID, ConnectionUIInformation> e : oldBendpoints.entrySet()) {
ConnectionContainer cc = m_wfm.getConnection(e.getKey());
if (cc == null) {
continue;
}
cc.setUIInfo(e.getValue());
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class ParallelizedChunkContentMaster method cleanupChunks.
/**
* Clean up chunks (and containing WFM).
*/
public void cleanupChunks() {
synchronized (m_chunks) {
for (int i = 0; i < m_chunks.length; i++) {
ParallelizedChunkContent pbc = m_chunks[i];
if (pbc != null) {
pbc.removeLoopEndStateChangeListener(this);
m_chunks[i] = null;
}
}
if ((m_manager != null) && m_manager.getParent().containsNodeContainer(m_manager.getID())) {
NodeContainer nc = m_manager.getParent().getNodeContainer(m_manager.getID());
if (m_manager == nc) {
// need to make sure that this is not just another node
// with the same ID (in rare cases this can happen if
// the metanode was cleared but the StartNode did not
// get notified and calls this function again.)
m_manager.getParent().removeNode(m_manager.getID());
}
}
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class DeleteAction method closeOpenWorkflows.
private void closeOpenWorkflows(final List<IContainer> allWorkflows) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
for (IContainer wf : allWorkflows) {
NodeContainer wfm = ProjectWorkflowMap.getWorkflow(wf.getLocationURI());
if (wfm != null) {
for (IEditorReference editRef : page.getEditorReferences()) {
IEditorPart editor = editRef.getEditor(false);
if (editor == null) {
// got closed in the mean time
continue;
}
WorkflowEditorAdapter wea = (WorkflowEditorAdapter) editor.getAdapter(WorkflowEditorAdapter.class);
NodeContainer editWFM = null;
if (wea != null) {
editWFM = wea.getWorkflowManager();
}
if (wfm == editWFM) {
page.closeEditor(editor, false);
}
}
}
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class WorkflowCoachView method updateInput.
private void updateInput(final ISelection selection) {
if (NodeRecommendationManager.getInstance().getNumLoadedProviders() == 0) {
// if there is at least one enabled triple provider then the statistics might need to be download first
if (NodeRecommendationManager.getInstance().getNodeTripleProviders().stream().anyMatch(ntp -> ntp.isEnabled())) {
if (m_loadState.get() == LoadState.Disposed) {
return;
}
m_loadState.set(LoadState.LoadingNodes);
updateInput("Loading recommendations ...");
// try updating the triple provider that are enabled and require an update
updateTripleProviders(e -> {
m_loadState.set(LoadState.Initizalized);
if (e.isPresent()) {
updateInputNoProvider();
} else {
try {
NodeRecommendationManager.getInstance().loadRecommendations();
if (NodeRecommendationManager.getInstance().getNumLoadedProviders() == 0) {
// if there are still no triple provider, show link
updateInputNoProvider();
} else {
updateInput("Statistics successfully loaded. Select a node...");
}
} catch (Exception e1) {
updateInputNoProvider();
}
}
}, true, false);
} else {
// no triple provider enabled -> needs to be configured
updateInputNoProvider();
return;
}
}
IStructuredSelection structSel = (IStructuredSelection) selection;
if (structSel.size() > 1) {
updateInput("No recommendation for multiple selected nodes.");
return;
}
// retrieve first (and only!) selection:
Iterator<?> selIt = structSel.iterator();
boolean nodeSelected = selIt.hasNext();
NodeContainer nc = null;
if (nodeSelected) {
Object sel = selIt.next();
nodeSelected &= (sel instanceof NodeContainerEditPart);
if (nodeSelected) {
NodeContainerUI uinc = ((NodeContainerEditPart) sel).getNodeContainer();
if (!Wrapper.wraps(uinc, NodeContainer.class)) {
updateInput("Worklfow coach only supports native nodes, so far.\nBut the selected one is of type '" + uinc.getClass().getSimpleName() + "'.");
return;
} else {
nc = Wrapper.unwrapNC(uinc);
nodeSelected &= nc instanceof NativeNodeContainer;
}
}
}
// -> in that case no redraw is required
if (nodeSelected) {
if (m_lastSelection.equals(nc.getNameWithID())) {
return;
} else {
m_lastSelection = nc.getNameWithID();
}
} else {
if (m_lastSelection.equals("no node selected")) {
return;
} else {
m_lastSelection = "no node selected";
}
}
List<NodeRecommendation>[] recommendations;
if (nodeSelected) {
// retrieve node recommendations if exactly one node is selected
recommendations = NodeRecommendationManager.getInstance().getNodeRecommendationFor((NativeNodeContainer) nc);
} else if (nc == null) {
// retrieve node recommendations if no node is selected (most likely the source nodes etc.)
recommendations = NodeRecommendationManager.getInstance().getNodeRecommendationFor();
} else {
Display.getDefault().syncExec(() -> {
m_viewer.setInput("");
m_viewer.refresh();
});
return;
}
if (recommendations == null) {
// something went wrong with loading the node recommendations, show the configure link
updateInputNoProvider();
return;
}
// TODO: cache node recommendations??
int maxSize = 0;
for (List<NodeRecommendation> l : recommendations) {
maxSize = Math.max(maxSize, l.size());
}
List<NodeRecommendation[]> recommendationsJoined = joinRecommendations(recommendations, maxSize);
// remove duplicates from list
Set<String> duplicates = new HashSet<>();
List<NodeRecommendation[]> recommendationsWithoutDups = new ArrayList<>(recommendationsJoined.size());
for (NodeRecommendation[] nrs : recommendationsJoined) {
int idx = getNonNullIdx(nrs);
if (duplicates.add(nrs[idx].toString())) {
recommendationsWithoutDups.add(nrs);
}
}
// update viewer
changeViewerStateTo(ViewerState.RECOMMENDATIONS);
Display.getDefault().syncExec(() -> {
m_viewer.setInput(recommendationsWithoutDups);
m_viewer.refresh();
m_recommendationsAvailable = true;
// scroll to the very top
if (!recommendationsWithoutDups.isEmpty()) {
m_viewer.getTable().setTopIndex(0);
}
});
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class WorkflowExportPage method handleSingleSelection.
private IContainer handleSingleSelection(final IStructuredSelection selection) {
Object obj = selection.getFirstElement();
IContainer resultContainer = null;
// prepare default export file name
if (obj instanceof IContainer) {
resultContainer = (IContainer) obj;
} else if (obj instanceof IResource) {
resultContainer = ((IResource) obj).getParent();
}
if (obj instanceof NodeContainer) {
resultContainer = getContainerForWorkflow((NodeContainer) obj);
}
if (obj instanceof IContainer) {
IContainer container = (IContainer) obj;
// check whether it is a workflow group -> list all workflows
if (KnimeResourceUtil.isWorkflowGroup(container) || container instanceof IWorkspaceRoot) {
// get all contained containers and list them recursively
m_treeViewer.setInput(container);
m_treeViewer.getTree().setVisible(true);
m_treeViewer.expandAll();
// all
if (selection.size() <= 1) {
/*
* Since the tree is expanded before the deprecated method
* should work. Reason why it is deprecated:
* "this method only checks or unchecks visible items" but
* CheckboxTreeViewer#setSubtreeChecked(Object, boolean)
* does not work.
*/
m_treeViewer.setAllChecked(true);
}
} else if (KnimeResourceUtil.isWorkflow(container)) {
// or a workflow -> list nothing
m_treeViewer.getTree().setVisible(false);
}
}
return resultContainer;
}
Aggregations