Search in sources :

Example 6 with NodeID

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

the class LoadWorkflowRunnable method run.

/**
 * {@inheritDoc}
 */
@Override
public void run(final IProgressMonitor pm) {
    // indicates whether to create an empty workflow
    // this is done if the file is empty
    boolean createEmptyWorkflow = false;
    // name of workflow will be null (uses directory name then)
    String name = null;
    m_throwable = null;
    try {
        // create progress monitor
        ProgressHandler progressHandler = new ProgressHandler(pm, 101, "Loading workflow...");
        final CheckCancelNodeProgressMonitor progressMonitor = new CheckCancelNodeProgressMonitor(pm);
        progressMonitor.addProgressListener(progressHandler);
        File workflowDirectory = m_workflowFile.getParentFile();
        Display d = Display.getDefault();
        GUIWorkflowLoadHelper loadHelper = new GUIWorkflowLoadHelper(d, workflowDirectory.getName(), m_mountpointURI, workflowDirectory, m_mountpointRoot);
        final WorkflowLoadResult result = WorkflowManager.loadProject(workflowDirectory, new ExecutionMonitor(progressMonitor), loadHelper);
        final WorkflowManager wm = result.getWorkflowManager();
        m_editor.setWorkflowManager(wm);
        pm.subTask("Finished.");
        pm.done();
        if (wm.isDirty()) {
            m_editor.markDirty();
        }
        final IStatus status = createStatus(result, !result.getGUIMustReportDataLoadErrors());
        String message;
        switch(status.getSeverity()) {
            case IStatus.OK:
                message = "No problems during load.";
                break;
            case IStatus.WARNING:
                message = "Warnings during load";
                logPreseveLineBreaks("Warnings during load: " + result.getFilteredError("", LoadResultEntryType.Warning), false);
                break;
            default:
                message = "Errors during load";
                logPreseveLineBreaks("Errors during load: " + result.getFilteredError("", LoadResultEntryType.Warning), true);
        }
        if (!status.isOK()) {
            showLoadErrorDialog(result, status, message);
        }
        final List<NodeID> linkedMNs = wm.getLinkedMetaNodes(true);
        if (!linkedMNs.isEmpty()) {
            final WorkflowEditor editor = m_editor;
            m_editor.addAfterOpenRunnable(new Runnable() {

                @Override
                public void run() {
                    postLoadCheckForMetaNodeUpdates(editor, wm, linkedMNs);
                }
            });
        }
    } catch (FileNotFoundException fnfe) {
        m_throwable = fnfe;
        LOGGER.fatal("File not found", fnfe);
    } catch (IOException ioe) {
        m_throwable = ioe;
        if (m_workflowFile.length() == 0) {
            LOGGER.info("New workflow created.");
            // this is the only place to set this flag to true: we have an
            // empty workflow file, i.e. a new project was created
            // bugfix 1555: if an exception is thrown DO NOT create empty
            // workflow
            createEmptyWorkflow = true;
        } else {
            LOGGER.error("Could not load workflow from: " + m_workflowFile.getName(), ioe);
        }
    } catch (InvalidSettingsException ise) {
        LOGGER.error("Could not load workflow from: " + m_workflowFile.getName(), ise);
        m_throwable = ise;
    } catch (UnsupportedWorkflowVersionException uve) {
        m_loadingCanceledMessage = INCOMPATIBLE_VERSION_MSG;
        LOGGER.info(m_loadingCanceledMessage, uve);
        m_editor.setWorkflowManager(null);
    } catch (CanceledExecutionException cee) {
        m_loadingCanceledMessage = "Canceled loading workflow: " + m_workflowFile.getParentFile().getName();
        LOGGER.info(m_loadingCanceledMessage, cee);
        m_editor.setWorkflowManager(null);
    } catch (LockFailedException lfe) {
        StringBuilder error = new StringBuilder();
        error.append("Unable to load workflow \"");
        error.append(m_workflowFile.getParentFile().getName());
        if (m_workflowFile.getParentFile().exists()) {
            error.append("\"\nIt is in use by another user/instance.");
        } else {
            error.append("\"\nLocation does not exist.");
        }
        m_loadingCanceledMessage = error.toString();
        LOGGER.info(m_loadingCanceledMessage, lfe);
        m_editor.setWorkflowManager(null);
    } catch (Throwable e) {
        m_throwable = e;
        LOGGER.error("Workflow could not be loaded. " + e.getMessage(), e);
        m_editor.setWorkflowManager(null);
    } finally {
        // (empty workflow file)
        if (createEmptyWorkflow) {
            WorkflowCreationHelper creationHelper = new WorkflowCreationHelper();
            WorkflowContext.Factory fac = new WorkflowContext.Factory(m_workflowFile.getParentFile());
            fac.setMountpointRoot(m_mountpointRoot);
            fac.setMountpointURI(m_mountpointURI);
            creationHelper.setWorkflowContext(fac.createContext());
            m_editor.setWorkflowManager(WorkflowManager.ROOT.createAndAddProject(name, creationHelper));
            // save empty project immediately
            // bugfix 1341 -> see WorkflowEditor line 1294
            // (resource delta visitor movedTo)
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    m_editor.doSave(new NullProgressMonitor());
                }
            });
            m_editor.setIsDirty(false);
        }
        // IMPORTANT: Remove the reference to the file and the
        // editor!!! Otherwise the memory cannot be freed later
        m_editor = null;
        m_workflowFile = null;
        m_mountpointRoot = null;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) UnsupportedWorkflowVersionException(org.knime.core.node.workflow.UnsupportedWorkflowVersionException) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) FileNotFoundException(java.io.FileNotFoundException) WorkflowCreationHelper(org.knime.core.node.workflow.WorkflowCreationHelper) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) NodeID(org.knime.core.node.workflow.NodeID) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) LockFailedException(org.knime.core.util.LockFailedException) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) IOException(java.io.IOException) WorkflowLoadResult(org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 7 with NodeID

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

the class WorkflowEditor method addMetaNode.

/*
     * --------- methods for adding a auto-placed and auto-connected node -----
     */
/**
 * {@inheritDoc}
 * Listener interface method of the {@link NodeProvider}.
 * Called when other instances want to add a metanode to the workflow in
 * the editor. <br>
 * The implementation only adds it if the editor is active. If one other
 * node is selected in the editor, to which the new node will then be
 * connected to.
 *
 * @param sourceManager wfm to copy the metanode from
 * @param id the id of the metanode in the source manager
 * @return if the metanode was actually added
 */
@Override
public boolean addMetaNode(final WorkflowManager sourceManager, final NodeID id) {
    if (id == null || sourceManager == null) {
        return false;
    }
    if (!isEditorActive()) {
        return false;
    }
    NodeContainerEditPart preNode = getTheOneSelectedNode();
    NodeID preID = null;
    Point nodeLoc = null;
    if (preNode == null) {
        nodeLoc = getViewportCenterLocation();
        nodeLoc = toAbsolute(nodeLoc);
    } else {
        nodeLoc = getLocationRightOf(preNode);
        preID = preNode.getNodeContainer().getID();
    }
    if (getEditorSnapToGrid()) {
        nodeLoc = getClosestGridLocation(nodeLoc);
    }
    Command newNodeCmd = new CreateNewConnectedMetaNodeCommand(getViewer(), unwrapWFM(m_manager), sourceManager, id, nodeLoc, preID);
    getCommandStack().execute(newNodeCmd);
    // after adding a node the editor should get the focus
    setFocus();
    return true;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) CreateNewConnectedMetaNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand) CreateNewConnectedNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedNodeCommand) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand) Command(org.eclipse.gef.commands.Command) CreateNewConnectedMetaNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand) NodeID(org.knime.core.node.workflow.NodeID) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 8 with NodeID

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

the class WorkflowRootEditPart method createChild.

/**
 * {@inheritDoc}
 */
@Override
protected EditPart createChild(final Object model) {
    final EditPart part = super.createChild(model);
    LOGGER.debug("part: " + part);
    if (part instanceof NodeContainerEditPart) {
        getViewer().deselect(this);
        NodeID id = ((NodeContainerEditPart) part).getNodeContainer().getID();
        if (m_futureSelection.isEmpty()) {
            // select only this element
            getViewer().deselectAll();
            getViewer().select(part);
        } else if (m_futureSelection.contains(id)) {
            // append this element to the current selection
            getViewer().appendSelection(part);
            m_futureSelection.remove(id);
            // reveal the editpart after it has been created completely
            Display.getCurrent().asyncExec(new Runnable() {

                @Override
                public void run() {
                    getViewer().reveal(part);
                }
            });
        }
    }
    if (model instanceof Annotation) {
        // newly created annotations are only selected if done explicitly
        getViewer().deselect(this);
        if (m_annotationSelection.contains(model)) {
            getViewer().appendSelection(part);
            m_annotationSelection.remove(model);
            // reveal the editpart after it has been created completely
            Display.getCurrent().asyncExec(new Runnable() {

                @Override
                public void run() {
                    getViewer().reveal(part);
                }
            });
        }
    }
    // connections are selected in workflowChanged
    return part;
}
Also used : EditPart(org.eclipse.gef.EditPart) NodeID(org.knime.core.node.workflow.NodeID) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation)

Example 9 with NodeID

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

the class DisconnectSubNodeLinkAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    List<NodeID> idList = new ArrayList<NodeID>();
    for (NodeContainerEditPart p : nodeParts) {
        Object model = p.getModel();
        if (Wrapper.wraps(model, SubNodeContainer.class)) {
            SubNodeContainer snc = Wrapper.unwrap((UI) model, SubNodeContainer.class);
            MetaNodeTemplateInformation i = snc.getTemplateInformation();
            if (Role.Link.equals(i.getRole())) {
                idList.add(snc.getID());
            }
        }
    }
    NodeID[] ids = idList.toArray(new NodeID[idList.size()]);
    DisconnectSubNodeLinkCommand disCmd = new DisconnectSubNodeLinkCommand(getManager(), ids);
    execute(disCmd);
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) NodeID(org.knime.core.node.workflow.NodeID) ArrayList(java.util.ArrayList) DisconnectSubNodeLinkCommand(org.knime.workbench.editor2.commands.DisconnectSubNodeLinkCommand) MetaNodeTemplateInformation(org.knime.core.node.workflow.MetaNodeTemplateInformation)

Example 10 with NodeID

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

the class ExecuteAction method runOnNodes.

/**
 * This starts an execution job for the selected nodes. Note that this is
 * all controlled by the WorkflowManager object of the currently open
 * editor.
 *
 * @see org.knime.workbench.editor2.actions.AbstractNodeAction
 *      #runOnNodes(org.knime.workbench.editor2.
 *      editparts.NodeContainerEditPart[])
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (!isEnabled()) {
        // for some reason hitting F7 bypasses the enable status
        return;
    }
    LOGGER.debug("Creating execution job for " + nodeParts.length + " node(s)...");
    WorkflowManager manager = getManager();
    NodeID[] ids = new NodeID[nodeParts.length];
    for (int i = 0; i < nodeParts.length; i++) {
        ids[i] = nodeParts[i].getNodeContainer().getID();
    }
    manager.executeUpToHere(ids);
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID)

Aggregations

NodeID (org.knime.core.node.workflow.NodeID)71 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)30 NodeContainer (org.knime.core.node.workflow.NodeContainer)17 ArrayList (java.util.ArrayList)12 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)11 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)11 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)10 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)10 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)10 Map (java.util.Map)9 ConnectionID (org.knime.core.node.workflow.ConnectionID)9 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)9 ConnectionUIInformation (org.knime.core.node.workflow.ConnectionUIInformation)7 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)6 MessageBox (org.eclipse.swt.widgets.MessageBox)5 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)5 File (java.io.File)4 IOException (java.io.IOException)4 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)4 NodeContainerTemplate (org.knime.core.node.workflow.NodeContainerTemplate)4