protected Diagram intializeNewDiagram() throws ExecutionException {
Diagram d = ViewService.createDiagram(getDiagramDomainElement(),
getDiagramKind(), getPreferencesHint());
if (d == null) {
throw new ExecutionException(
"Can't create diagram of '"+ getDiagramKind()
+ "' kind"
);
}
diagramFacet.setDiagramLink(d);
assert diagramFacet.eResource() != null;
diagramFacet.eResource().getContents().add(d);
try {
new WorkspaceModifyOperation() {
protected void execute(IProgressMonitor monitor)
throws CoreException, InvocationTargetException,
InterruptedException {
try {
for (
Iterator<Resource> it =
diagramFacet.eResource()
.getResourceSet().getResources()
.iterator();
it.hasNext();
) {
Resource nextResource = it.next();
if (nextResource.isLoaded()
&& !getEditingDomain().isReadOnly(
nextResource)) {
nextResource.save(UMLDiagramEditorUtil
.getSaveOptions());
}
}
} catch (IOException ex) {
throw new InvocationTargetException(
ex,
"Save operation failed"
);
}
}
}.run(null);
} catch (InvocationTargetException e) {
throw new ExecutionException(
"Can't create diagram of '"
+ getDiagramKind()
+ "' kind",
e
);
} catch (InterruptedException e) {
throw new ExecutionException(
"Can't create diagram of '"
+ getDiagramKind()
+ "' kind",
e
);