Search in sources :

Example 1 with TemplateNodeContainerPersistor

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

the class LoadMetaNodeTemplateRunnable method run.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("null")
@Override
public void run(final IProgressMonitor pm) {
    try {
        // create progress monitor
        ProgressHandler progressHandler = new ProgressHandler(pm, 101, "Loading metanode template...");
        final CheckCancelNodeProgressMonitor progressMonitor = new CheckCancelNodeProgressMonitor(pm);
        progressMonitor.addProgressListener(progressHandler);
        URI sourceURI = m_templateKNIMEFolder.toURI();
        File parentFile = ResolverUtil.resolveURItoLocalOrTempFile(sourceURI, pm);
        if (pm.isCanceled()) {
            throw new InterruptedException();
        }
        Display d = Display.getDefault();
        GUIWorkflowLoadHelper loadHelper = new GUIWorkflowLoadHelper(d, parentFile.getName(), sourceURI, parentFile, null, true);
        TemplateNodeContainerPersistor loadPersistor = loadHelper.createTemplateLoadPersistor(parentFile, sourceURI);
        MetaNodeLinkUpdateResult loadResult = new MetaNodeLinkUpdateResult("Template from \"" + sourceURI + "\"");
        m_parentWFM.load(loadPersistor, loadResult, new ExecutionMonitor(progressMonitor), false);
        m_result = loadResult;
        if (pm.isCanceled()) {
            throw new InterruptedException();
        }
        pm.subTask("Finished.");
        pm.done();
        final IStatus status = createStatus(m_result, !m_result.getGUIMustReportDataLoadErrors());
        final 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: " + m_result.getFilteredError("", LoadResultEntryType.Warning), false);
                break;
            default:
                message = "Errors during load";
                logPreseveLineBreaks("Errors during load: " + m_result.getFilteredError("", LoadResultEntryType.Warning), true);
        }
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                // will not open if status is OK.
                ErrorDialog.openError(Display.getDefault().getActiveShell(), "Workflow Load", message, status);
            }
        });
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        // IMPORTANT: Remove the reference to the file and the
        // editor!!! Otherwise the memory cannot be freed later
        m_parentWFM = null;
        m_templateKNIMEFolder = null;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) URI(java.net.URI) TemplateNodeContainerPersistor(org.knime.core.node.workflow.TemplateNodeContainerPersistor) MetaNodeLinkUpdateResult(org.knime.core.node.workflow.WorkflowPersistor.MetaNodeLinkUpdateResult) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Aggregations

File (java.io.File)1 URI (java.net.URI)1 IStatus (org.eclipse.core.runtime.IStatus)1 Display (org.eclipse.swt.widgets.Display)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1 TemplateNodeContainerPersistor (org.knime.core.node.workflow.TemplateNodeContainerPersistor)1 MetaNodeLinkUpdateResult (org.knime.core.node.workflow.WorkflowPersistor.MetaNodeLinkUpdateResult)1