use of org.knime.core.node.workflow.NativeNodeContainer in project knime-core by knime.
the class NodeContainerFigure method setStateFromNC.
/**
* @param nc new state of underlying node
*/
public void setStateFromNC(final NodeContainerUI nc) {
boolean isInactive = false;
LoopStatus loopStatus = LoopStatus.NONE;
if (nc instanceof SingleNodeContainerUI) {
SingleNodeContainerUI snc = (SingleNodeContainerUI) nc;
isInactive = snc.isInactive();
if (Wrapper.wraps(snc, NativeNodeContainer.class)) {
NativeNodeContainer nnc = Wrapper.unwrap(snc, NativeNodeContainer.class);
loopStatus = nnc.getLoopStatus();
}
}
NodeContainerState state = nc.getNodeContainerState();
if (!isInactive) {
if (state.isIdle()) {
setStatusAmple();
m_statusFigure.setIcon(RED);
} else if (state.isConfigured()) {
setStatusAmple();
m_statusFigure.setIcon(YELLOW);
} else if (state.isExecuted()) {
setStatusAmple();
m_statusFigure.setIcon(GREEN);
} else if (state.isWaitingToBeExecuted()) {
if (LoopStatus.PAUSED.equals(loopStatus)) {
setProgressBar(ProgressMode.PAUSED);
} else {
setProgressBar(ProgressMode.QUEUED);
}
} else if (state.isExecutionInProgress()) {
setProgressBar(ProgressMode.EXECUTING);
} else {
setStatusAmple();
m_statusFigure.setIcon(INACTIVE);
}
} else {
setStatusAmple();
m_statusFigure.setIcon(INACTIVE);
}
setLoopStatus(loopStatus, state.isExecuted());
repaint();
}
use of org.knime.core.node.workflow.NativeNodeContainer in project knime-core by knime.
the class ResumeLoopAction method runOnNodes.
/**
* Resume paused loop.
*
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
LOGGER.debug("Creating 'Resume Loop Execution' job for " + nodeParts.length + " node(s)...");
WorkflowManager manager = getManager();
for (NodeContainerEditPart p : nodeParts) {
NodeContainerUI nc = p.getNodeContainer();
if (Wrapper.wraps(nc, NativeNodeContainer.class)) {
NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
if (nnc.isModelCompatibleTo(LoopEndNode.class) && nnc.getLoopStatus().equals(LoopStatus.PAUSED)) {
manager.resumeLoopExecution(nnc, /*oneStep=*/
false);
}
}
}
try {
// Give focus to the editor again. Otherwise the actions (selection)
// is not updated correctly.
getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
} catch (Exception e) {
// ignore
}
}
use of org.knime.core.node.workflow.NativeNodeContainer in project knime-core by knime.
the class StepLoopAction method internalCalculateEnabled.
/**
* @return <code>true</code>, if just one loop end node part is selected
* which is executable and a loop is in progress.
*
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean internalCalculateEnabled() {
NodeContainerEditPart[] parts = getSelectedParts(NodeContainerEditPart.class);
if (parts.length != 1) {
return false;
}
// enabled if the one selected node is a configured and "in progress"
// LoopEndNode
NodeContainerUI nc = parts[0].getNodeContainer();
if (Wrapper.wraps(nc, NativeNodeContainer.class)) {
NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
if (nnc.isModelCompatibleTo(LoopEndNode.class) && nnc.getLoopStatus().equals(LoopStatus.PAUSED)) {
// either the node is paused...
return true;
}
WorkflowManager wm = getEditor().getWorkflowManager().get();
if (wm.canExecuteNodeDirectly(nc.getID())) {
// ...or we can execute it (then this will be the first step)
return true;
}
}
return false;
}
use of org.knime.core.node.workflow.NativeNodeContainer 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.NativeNodeContainer 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