use of org.knime.core.node.workflow.NodeStateChangeListener in project knime-core by knime.
the class ExecuteAndOpenViewAction method executeAndOpen.
private void executeAndOpen(final NodeContainer cont) {
boolean hasView = cont.getNrViews() > 0;
final InteractiveWebViewsResult interactiveWebViews = cont.getInteractiveWebViews();
hasView |= cont.hasInteractiveView() || interactiveWebViews.size() > 0;
hasView |= OpenSubnodeWebViewAction.hasContainerView(cont);
if (hasView) {
// another listener must be registered at the workflow manager to
// receive also those events from nodes that have just been queued
cont.addNodeStateChangeListener(new NodeStateChangeListener() {
@Override
public void stateChanged(final NodeStateEvent state) {
NodeContainerState ncState = cont.getNodeContainerState();
// removed from the queue)
if ((state.getSource() == cont.getID()) && ncState.isExecuted()) {
// if the node was successfully executed
// start the view
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
// run open view action
IAction viewAction;
if (cont.hasInteractiveView()) {
viewAction = new OpenInteractiveViewAction(cont);
} else if (cont instanceof SubNodeContainer) {
viewAction = new OpenSubnodeWebViewAction((SubNodeContainer) cont);
} else if (interactiveWebViews.size() > 0) {
viewAction = new OpenInteractiveWebViewAction(cont, interactiveWebViews.get(0));
} else {
viewAction = new OpenViewAction(cont, 0);
}
viewAction.run();
}
});
}
if (!ncState.isExecutionInProgress()) {
// in those cases remove the listener
cont.removeNodeStateChangeListener(this);
}
}
});
}
getManager().executeUpToHere(cont.getID());
}
Aggregations