Search in sources :

Example 1 with NodeContainerState

use of org.knime.core.node.workflow.NodeContainerState 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();
}
Also used : SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) LoopStatus(org.knime.core.node.workflow.NativeNodeContainer.LoopStatus) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Example 2 with NodeContainerState

use of org.knime.core.node.workflow.NodeContainerState 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)

Example 3 with NodeContainerState

use of org.knime.core.node.workflow.NodeContainerState in project knime-core by knime.

the class KnimeResourceLabelProvider method getImage.

/**
 * {@inheritDoc}
 */
@Override
public Image getImage(final Object element) {
    Image img = super.getImage(element);
    NodeContainerUI projectNode = null;
    if (element instanceof IContainer) {
        IContainer container = (IContainer) element;
        if (container.exists(WORKFLOW_FILE)) {
            // in any case a knime workflow or meta node (!)
            projectNode = ProjectWorkflowMap.getWorkflowUI(container.getLocationURI());
            if (projectNode == null && !isMetaNode(container)) {
                return CLOSED_WORKFLOW;
            }
        }
        if (projectNode == null) {
            if (isMetaNode(container)) {
                return NODE;
            } else if (container.exists(METAINFO_FILE)) {
                return WORKFLOW_GROUP;
            }
        }
    } else if (element instanceof NodeContainerUI) {
        projectNode = (NodeContainerUI) element;
    }
    if (projectNode != null) {
        if (projectNode instanceof WorkflowManagerUI && // are displayed with state
        ((WorkflowManagerUI) projectNode).getID().hasSamePrefix(WorkflowManager.ROOT.getID())) {
            NodeContainerState state = projectNode.getNodeContainerState();
            if (projectNode.getNodeMessage().getMessageType().equals(NodeMessage.Type.ERROR)) {
                return ERROR;
            }
            if (state.isExecuted()) {
                return EXECUTED;
            } else if (state.isExecutionInProgress()) {
                return EXECUTING;
            } else {
                return CONFIGURED;
            }
        } else {
            return NODE;
        }
    }
    return img;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) Image(org.eclipse.swt.graphics.Image) IContainer(org.eclipse.core.resources.IContainer)

Example 4 with NodeContainerState

use of org.knime.core.node.workflow.NodeContainerState in project knime-core by knime.

the class SubnodeViewableModel method onNodeStateChange.

/**
 * Called by state listener on subnode container.
 */
private void onNodeStateChange() {
    NodeContainerState nodeContainerState = m_container.getNodeContainerState();
    // (ideally this should be removed but those state changes on the SNC are not protected by the workflow lock)
    if (!(m_isReexecuteInProgress.get() || nodeContainerState.isExecutionInProgress())) {
        boolean isCallModelChanged = true;
        SubnodeViewValue v = getViewValue();
        if (nodeContainerState.isExecuted()) {
            if (v == null) {
                // node was just executed, i.e. view is open and user executes via "run" button in main application
                try {
                    createPageAndValue();
                    assert m_value != null : "value supposed to be non-null on executed node";
                } catch (IOException e) {
                    LOGGER.error("Creating view failed: " + e.getMessage(), e);
                    reset();
                }
            } else {
                // reset->configured->executing events were swallowed as part of m_isReexecutionInProgress
                if (m_view != null && v.equals(m_view.getLastRetrievedValue())) {
                    isCallModelChanged = false;
                }
            }
        } else if (v != null) {
            // sets #getViewValue to null
            reset();
        }
        if (m_view != null && isCallModelChanged) {
            m_view.callViewableModelChanged();
        }
    }
}
Also used : NodeContainerState(org.knime.core.node.workflow.NodeContainerState) IOException(java.io.IOException)

Example 5 with NodeContainerState

use of org.knime.core.node.workflow.NodeContainerState in project knime-core by knime.

the class SubnodeViewableModel method loadViewValue.

/**
 * {@inheritDoc}
 */
@Override
public void loadViewValue(final SubnodeViewValue value, final boolean useAsDefault) {
    try {
        CheckUtils.checkState(m_container.getNodeContainerState().isExecuted(), "Node needs to be in executed state to apply new view values.");
        m_isReexecuteInProgress.set(true);
        try (WorkflowLock lock = m_container.getParent().lock()) {
            m_spm.applyValidatedValuesAndReexecute(value.getViewValues(), m_container.getID(), useAsDefault);
            m_value = value;
        } finally {
            m_isReexecuteInProgress.set(false);
            NodeContainerState state = m_container.getNodeContainerState();
            if (state.isExecuted()) {
            // the framework refused to reset the node (because there are downstream nodes still executing);
            // ignore it.
            } else if (!m_container.getNodeContainerState().isExecutionInProgress()) {
                // this happens if after the reset the execution can't be triggered, e.g. because #configure of
                // a node rejects the current settings -> #onNodeStateChange has been called as part of the reset
                // but was ignored due to the m_isReexecuteInProgress = true.
                onNodeStateChange();
            }
        }
    } catch (IOException e) {
        logErrorAndReset("Loading view values for node " + m_container.getID() + " failed: ", e);
    }
}
Also used : WorkflowLock(org.knime.core.node.workflow.WorkflowLock) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) IOException(java.io.IOException)

Aggregations

NodeContainerState (org.knime.core.node.workflow.NodeContainerState)8 IOException (java.io.IOException)4 Image (org.eclipse.swt.graphics.Image)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IContainer (org.eclipse.core.resources.IContainer)1 CoreException (org.eclipse.core.runtime.CoreException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IAction (org.eclipse.jface.action.IAction)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbench (org.eclipse.ui.IWorkbench)1 PartInitException (org.eclipse.ui.PartInitException)1 IProgressService (org.eclipse.ui.progress.IProgressService)1