Search in sources :

Example 11 with WorkflowManager

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

the class AbstractSaveRunnable method run.

@Override
public final void run(final IProgressMonitor pm) {
    File workflowDir = getSaveLocation();
    try {
        final WorkflowManager wfm = m_editor.getWorkflowManager().get();
        ProgressHandler progressHandler = new ProgressHandler(pm, wfm.getNodeContainers().size(), "Saving workflow... (cannot be canceled)");
        final CheckCancelNodeProgressMonitor progressMonitor = new CheckCancelNodeProgressMonitor(pm);
        progressMonitor.addProgressListener(progressHandler);
        final ExecutionMonitor exec = new ExecutionMonitor(progressMonitor);
        save(wfm, exec);
        // the refresh used to take place in WorkflowEditor#saveTo but
        // was moved to this runnable as part of bug fix 3028
        IResource r = KnimeResourceUtil.getResourceForURI(workflowDir.toURI());
        if (r != null) {
            String pName = r.getName();
            pm.setTaskName("Refreshing " + pName + "...");
            r.refreshLocal(IResource.DEPTH_INFINITE, pm);
        }
    } catch (FileNotFoundException fnfe) {
        m_logger.fatal("File not found", fnfe);
        m_exceptionMessage.append("File access problems: " + fnfe.getMessage());
        m_monitor.setCanceled(true);
    } catch (IOException ioe) {
        if (new File(workflowDir, WorkflowPersistor.WORKFLOW_FILE).length() == 0) {
            m_logger.info("New workflow created.");
        } else {
            m_logger.error("Could not save workflow: " + workflowDir.getName(), ioe);
            m_exceptionMessage.append("File access problems: " + ioe.getMessage());
            m_monitor.setCanceled(true);
        }
    } catch (CanceledExecutionException cee) {
        m_logger.info("Canceled saving workflow: " + workflowDir.getName());
        m_exceptionMessage.append("Saving workflow" + " was canceled.");
        m_monitor.setCanceled(true);
    } catch (Exception e) {
        m_logger.error("Could not save workflow", e);
        m_exceptionMessage.append("Could not save workflow: " + e.getMessage());
        m_monitor.setCanceled(true);
    } finally {
        pm.subTask("Finished.");
        pm.done();
        m_editor = null;
        m_exceptionMessage = null;
        m_monitor = null;
    }
}
Also used : CanceledExecutionException(org.knime.core.node.CanceledExecutionException) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) File(java.io.File) IResource(org.eclipse.core.resources.IResource) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) LockFailedException(org.knime.core.util.LockFailedException)

Example 12 with WorkflowManager

use of org.knime.core.node.workflow.WorkflowManager 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 13 with WorkflowManager

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

the class ReconfigureMetaNodeCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    NodeContainer nc = getHostWFM().getNodeContainer(m_metanodeID);
    if (nc instanceof WorkflowManager) {
        if (m_name != null) {
            WorkflowManager metaNode = (WorkflowManager) nc;
            m_oldName = metaNode.getName();
            metaNode.setName(m_name);
        }
        if (m_inPorts != null) {
            m_reverseInports = createReverseOperationList(getHostWFM().getMetanodeInputPortInfo(m_metanodeID), m_inPorts);
            getHostWFM().changeMetaNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
        }
        if (m_outPorts != null) {
            m_reverseOutports = createReverseOperationList(getHostWFM().getMetanodeOutputPortInfo(m_metanodeID), m_outPorts);
            getHostWFM().changeMetaNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
        }
    } else if (nc instanceof SubNodeContainer) {
        SubNodeContainer snc = (SubNodeContainer) nc;
        if (m_name != null) {
            m_oldName = snc.getName();
            snc.setName(m_name);
        }
        if (m_inPorts != null) {
            m_reverseInports = createReverseOperationList(getHostWFM().getSubnodeInputPortInfo(m_metanodeID), m_inPorts);
            getHostWFM().changeSubNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
        }
        if (m_outPorts != null) {
            m_reverseOutports = createReverseOperationList(getHostWFM().getSubnodeOutputPortInfo(m_metanodeID), m_outPorts);
            getHostWFM().changeSubNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
        }
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) MetaPortInfo(org.knime.core.node.port.MetaPortInfo)

Example 14 with WorkflowManager

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

the class UpdateMetaNodeLinkCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    UpdateMetaNodeTemplateRunnable updateRunner = null;
    try {
        IWorkbench wb = PlatformUI.getWorkbench();
        IProgressService ps = wb.getProgressService();
        WorkflowManager hostWFM = getHostWFM();
        updateRunner = new UpdateMetaNodeTemplateRunnable(hostWFM, m_ids);
        ps.busyCursorWhile(updateRunner);
        m_newIDs = updateRunner.getNewIDs();
        m_undoPersistors = updateRunner.getUndoPersistors();
        assert m_newIDs.size() == m_undoPersistors.size();
    } catch (Exception ex) {
        // if fails notify the user
        LOGGER.debug("Node cannot be created.", ex);
        MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Node cannot be created.", "The selected node could not be created " + "due to the following reason:\n" + ex.getMessage());
        return;
    } finally {
        if (updateRunner != null) {
            updateRunner.discard();
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) UpdateMetaNodeTemplateRunnable(org.knime.workbench.editor2.UpdateMetaNodeTemplateRunnable) IProgressService(org.eclipse.ui.progress.IProgressService) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 15 with WorkflowManager

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

the class NodeContainerProperties method setPropertyValue.

/**
 * {@inheritDoc}
 */
@Override
public void setPropertyValue(final Object id, final Object value) {
    if ((id instanceof String) && (value instanceof String)) {
        String strVal = (String) value;
        String strID = (String) id;
        if (strID.startsWith(m_prefix)) {
            String[] hierarchy = strID.split(CONFIG_SEPARATOR);
            String key = hierarchy[hierarchy.length - 1];
            // apply it to the node's settings:
            NodeContainer node = getNode();
            if (node == null) {
                return;
            }
            WorkflowManager wfm = node.getParent();
            NodeSettings nodeSettings = new NodeSettings("Transfer");
            NodeSettings settings;
            try {
                wfm.saveNodeSettings(node.getID(), nodeSettings);
                // overwrite our config in the settings
                settings = nodeSettings.getNodeSettings("model");
                if (hierarchy.length > 1) {
                    for (int i = 0; i < hierarchy.length - 1; i++) {
                        settings = settings.getNodeSettings(hierarchy[i]);
                        if (settings == null) {
                            return;
                        }
                    }
                }
            } catch (InvalidSettingsException e) {
                // somehow node is not able to save its settings anymore
                return;
            }
            AbstractConfigEntry entry = settings.getEntry(key);
            if (entry == null || entry instanceof Config) {
                // settings are not complete or correct anymore
                return;
            }
            switch(entry.getType()) {
                case xboolean:
                    settings.addBoolean(key, Boolean.parseBoolean(strVal));
                    break;
                case xbyte:
                    settings.addByte(key, Byte.parseByte(strVal));
                    break;
                case xchar:
                    String decoded = TokenizerSettings.unescapeString(strVal);
                    settings.addChar(key, decoded.charAt(0));
                    break;
                case xdouble:
                    settings.addDouble(key, Double.parseDouble(strVal));
                    break;
                case xfloat:
                    settings.addFloat(key, Float.parseFloat(strVal));
                    break;
                case xint:
                    settings.addInt(key, Integer.parseInt(strVal));
                    break;
                case xlong:
                    settings.addLong(key, Long.parseLong(strVal));
                    break;
                case xshort:
                    settings.addShort(key, Short.parseShort(strVal));
                    break;
                case xstring:
                    String dec = TokenizerSettings.unescapeString(strVal);
                    settings.addString(key, dec);
                    break;
                default:
                    // ignore the new value
                    return;
            }
            try {
                wfm.loadNodeSettings(node.getID(), nodeSettings);
            } catch (Exception ex) {
                LOGGER.error("Invalid Value (" + strVal + "): " + ex.getMessage(), ex);
                return;
            }
            return;
        }
    }
}
Also used : AbstractConfigEntry(org.knime.core.node.config.base.AbstractConfigEntry) NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)99 NodeID (org.knime.core.node.workflow.NodeID)38 NodeContainer (org.knime.core.node.workflow.NodeContainer)22 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)19 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)14 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)14 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)10 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)10 MessageBox (org.eclipse.swt.widgets.MessageBox)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 List (java.util.List)8 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)8 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)8