use of org.knime.workbench.editor2.LoadMetaNodeTemplateRunnable in project knime-core by knime.
the class CreateMetaNodeTemplateCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// Add node to workflow and get the container
LoadMetaNodeTemplateRunnable loadRunnable = null;
try {
IWorkbench wb = PlatformUI.getWorkbench();
IProgressService ps = wb.getProgressService();
// this one sets the workflow manager in the editor
loadRunnable = new LoadMetaNodeTemplateRunnable(getHostWFM(), m_templateKNIMEFolder);
ps.run(false, true, loadRunnable);
MetaNodeLinkUpdateResult result = loadRunnable.getLoadResult();
m_container = (NodeContainer) result.getLoadedInstance();
if (m_container == null) {
throw new RuntimeException("No template returned by load routine, see log for details");
}
// create extra info and set it
NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(m_snapToGrid).setIsDropLocation(true).build();
m_container.setUIInformation(info);
} catch (Throwable t) {
Throwable cause = t;
while ((cause.getCause() != null) && (cause.getCause() != cause)) {
cause = cause.getCause();
}
String error = "The selected node could not be created";
if (cause instanceof FileNotFoundException) {
error += " because a file could not be found: " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
} else if (cause instanceof IOException) {
error += " because of an I/O error: " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
} else if (cause instanceof InvalidSettingsException) {
error += " because the metanode contains invalid settings: " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
} else if (cause instanceof UnsupportedWorkflowVersionException) {
error += " because the metanode version is incompatible: " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
} else if ((cause instanceof CanceledExecutionException) || (cause instanceof InterruptedException)) {
LOGGER.info("Metanode loading was canceled by the user", cause);
} else {
LOGGER.error(String.format("Metanode loading failed with %s: %s", cause.getClass().getSimpleName(), cause.getMessage()), cause);
error += ": " + cause.getMessage();
MessageDialog.openError(Display.getDefault().getActiveShell(), "Node cannot be created.", error);
}
}
}
Aggregations