Search in sources :

Example 36 with WorkflowManagerUI

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

the class ProjectWorkflowMap method remove.

/**
 * Removes the {@link WorkflowManager} from the map, typically when the
 *  referring editor is closed and the WorkflowEditor is disposed.
 * @param path URI of the directory under which the
 * {@link WorkflowManager} is stored in the map.
 */
public static void remove(final URI path) {
    MapWFKey p = new MapWFKey(path);
    final WorkflowManagerUI manager = (WorkflowManagerUI) PROJECTS.get(p);
    // workflow is only in client map if there is at least one client
    if (manager != null && !WORKFLOW_CLIENTS.containsKey(p)) {
        Wrapper.unwrapWFMOptional(manager).ifPresent(wm -> NodeContext.pushContext(wm));
        try {
            PROJECTS.remove(p);
            WF_LISTENER.workflowChanged(new WorkflowEvent(WorkflowEvent.Type.NODE_REMOVED, manager.getID(), Wrapper.unwrapWFM(manager), null));
            manager.removeListener(WF_LISTENER);
            manager.removeNodeStateChangeListener(NSC_LISTENER);
            manager.removeNodeMessageListener(MSG_LISTENER);
            manager.removeNodePropertyChangedListener(NODE_PROP_LISTENER);
            try {
                manager.shutdown();
            } catch (Throwable t) {
                // at least we have tried it
                LOGGER.error("Could not cancel workflow manager for workflow " + p, t);
            } finally {
                if (manager.getNodeContainerState().isExecutionInProgress()) {
                    ThreadUtils.threadWithContext(() -> {
                        final int timeout = 20;
                        LOGGER.debugWithFormat("Workflow still in execution after canceling it - " + "waiting %d seconds max....", timeout);
                        try {
                            manager.waitWhileInExecution(timeout, TimeUnit.SECONDS);
                        } catch (InterruptedException ie) {
                            LOGGER.fatal("interrupting thread that no one has access to", ie);
                        }
                        if (manager.getNodeContainerState().isExecutionInProgress()) {
                            LOGGER.errorWithFormat("Workflow did not react on cancel within %d seconds, giving up", timeout);
                        } else {
                            LOGGER.debug("Workflow now canceled - will remove from parent");
                        }
                        WorkflowManager.ROOT.removeProject(manager.getID());
                    }, "Removal workflow - " + manager.getNameWithID()).start();
                } else {
                    WorkflowManager.ROOT.removeProject(manager.getID());
                }
            }
        } finally {
            Wrapper.unwrapWFMOptional(manager).ifPresent(wm -> NodeContext.removeLastContext());
        }
    }
}
Also used : WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) WorkflowEvent(org.knime.core.node.workflow.WorkflowEvent)

Example 37 with WorkflowManagerUI

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

the class ProjectWorkflowMap method putWorkflowUI.

/**
 * Adds a {@link WorkflowManagerUI} of an opened workflow with the URI of
 * the workflow directory to the map. Used by the WorkflowEditor.
 *
 * @param path URI of the directory containing the workflow.knime file
 * @param manager {@link WorkflowManagerUI} in memory holding the workflow
 */
public static void putWorkflowUI(final URI path, final WorkflowManagerUI manager) {
    MapWFKey p = new MapWFKey(path);
    // in case the manager is replaced
    // -> unregister listeners from the old one
    NodeContainerUI oldOne = PROJECTS.get(p);
    if (oldOne != null) {
        oldOne.removeNodeStateChangeListener(NSC_LISTENER);
        ((WorkflowManagerUI) oldOne).removeListener(WF_LISTENER);
        oldOne.removeNodeMessageListener(MSG_LISTENER);
        oldOne.removeNodePropertyChangedListener(NODE_PROP_LISTENER);
    }
    PROJECTS.put(p, manager);
    manager.addNodeStateChangeListener(NSC_LISTENER);
    manager.addListener(WF_LISTENER);
    manager.addNodeMessageListener(MSG_LISTENER);
    manager.addNodePropertyChangedListener(NODE_PROP_LISTENER);
    // with WorkflowManagerUI instances, too!
    if (Wrapper.wraps(manager, WorkflowManager.class)) {
        WF_LISTENER.workflowChanged(new WorkflowEvent(WorkflowEvent.Type.NODE_ADDED, manager.getID(), null, Wrapper.unwrapWFM(manager)));
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) WorkflowEvent(org.knime.core.node.workflow.WorkflowEvent)

Aggregations

WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)37 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)16 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)12 SubNodeContainerUI (org.knime.core.ui.node.workflow.SubNodeContainerUI)7 ArrayList (java.util.ArrayList)6 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)6 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)5 URI (java.net.URI)3 IContainer (org.eclipse.core.resources.IContainer)3 Point (org.eclipse.draw2d.geometry.Point)3 EditPart (org.eclipse.gef.EditPart)3 Image (org.eclipse.swt.graphics.Image)3 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)3 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)3 NodeID (org.knime.core.node.workflow.NodeID)3 SingleNodeContainerUI (org.knime.core.ui.node.workflow.SingleNodeContainerUI)3 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)3 WorkflowInPortEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortEditPart)3 List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2