Search in sources :

Example 1 with NodeStateChangeListener

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());
}
Also used : IAction(org.eclipse.jface.action.IAction) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) InteractiveWebViewsResult(org.knime.core.node.workflow.action.InteractiveWebViewsResult) NodeStateChangeListener(org.knime.core.node.workflow.NodeStateChangeListener) NodeStateEvent(org.knime.core.node.workflow.NodeStateEvent)

Aggregations

IAction (org.eclipse.jface.action.IAction)1 NodeContainerState (org.knime.core.node.workflow.NodeContainerState)1 NodeStateChangeListener (org.knime.core.node.workflow.NodeStateChangeListener)1 NodeStateEvent (org.knime.core.node.workflow.NodeStateEvent)1 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)1 InteractiveWebViewsResult (org.knime.core.node.workflow.action.InteractiveWebViewsResult)1