// count of images exported
int exported = 0;
// we collect up all uninitialisable diagrams, so we can
// quickly see which ones were unable to open
MultiStatus errorResult = new MultiStatus(DocToolsPlugin.PLUGIN_ID, Status.ERROR, "Could not export example images: multiple errors occured", null);
for (EClass cls : classes) {
monitor.beginTask("Exporting class " + cls.getName(), 105);
monitor.subTask("Finding file for class " + cls.getName());
IFile file = getFileFor(cls);
if (getFileFor(cls) == null)
continue; // skip
monitor.worked(10);
InitialiseDiagram init = new InitialiseDiagram();
IFile diagram;
try {
diagram = init.initialize(project, file, true /* open new diagram */, new SubProgressMonitor(monitor, 50));
} catch (InitializeDiagramException e) {
// if we couldn't initialise it, skip it
errorResult.add(errorStatus("Class '" + cls.getName() + "'", e));
continue;
}
// the diagram should now be opened
monitor.subTask("Exporting root image");
// get the active workbench editor part
// based on IamlDiagramEditorUtil#openDiagram()
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
DiagramDocumentEditor editor = (DiagramDocumentEditor) page.getActiveEditor();
// export only one image
exportDiagramThenClose(cls, editor, new SubProgressMonitor(monitor, 40));
// finally, delete the diagram file
monitor.subTask("Deleting diagram file");
diagram.delete(true, new SubProgressMonitor(monitor, 5));
monitor.done();
exported++;
}
// any errors in initialising?
if (errorResult.getChildren().length != 0) {
return errorResult;
}
// done
if (exported == 0) {