Store EMF model and Graphiti diagram seperately [message #718014] |
Mon, 22 August 2011 23:00  |
Eclipse User |
|
|
|
Hi, I'm looking for a way to store the EMF model separately from the Graphiti diagram and can't seems to find anything about this. I've got specific needs like to be able to edit the model using XML or transform it to another kind of notation using another tool.
I don't quite understand how Graphiti store the ResourceSet. I've tried to extend the Graphiti DiagramEditor.doSave function, but it seems it isn't even called.
Any help?
[Updated on: Mon, 22 August 2011 23:01] by Moderator
|
|
|
|
Re: Store EMF model and Graphiti diagram seperately [message #718122 is a reply to message #718014] |
Tue, 23 August 2011 06:20   |
Eclipse User |
|
|
|
Hi Maxime,
the Domain model resource and the diagram resource have to be in the same resource set.
I create my domain model and diagram via a wizard that calls the following method. This method is my adapted version of org.eclipse.graphiti.examples.common.FileService.createEmfFileForDiagram
public static TransactionalEditingDomain createEmfFileForDiagram(URI diagramResourceUri, URI modelResourceUri, final Diagram diagram, final EObject... modelRoots) {
final TransactionalEditingDomain editingDomain = DiagramEditorFactory.createResourceSetAndEditingDomain();
final ResourceSet resourceSet = editingDomain.getResourceSet();
final Resource modelResource = resourceSet.createResource(modelResourceUri);
final Resource diagramResource = resourceSet.createResource(diagramResourceUri);
final CommandStack commandStack = editingDomain.getCommandStack();
commandStack.execute(new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
modelResource.setTrackingModification(true);
diagramResource.setTrackingModification(true);
for(EObject modelRoot : modelRoots) {
modelResource.getContents().add(modelRoot);
}
diagramResource.getContents().add(diagram);
try {
modelResource.save(Collections.EMPTY_MAP);
diagramResource.save(Collections.EMPTY_MAP);
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
});
return editingDomain;
}
The linking is done with org.eclipse.graphiti.features.impl.AbstractFeatureProvider.link, the link method can be called in every add feature as this inherits from AbstractFeature that provides a link method delegating to AbstractFeatureProvider's link method. As it seems to me this link method only stores business objects inside the diagram file I do not use it anymore but create and set the link on my own:
PictogramLink link = PictogramsFactory.eINSTANCE.createPictogramLink();
getDiagram().setLink(link);
link.getBusinessObjects().addAll(
Arrays.asList(businessObjects));
containerShape.setLink(link);
I think that might be a bug, as the corresponding code in the link method looks like this:
EObject bo = (EObject) businessObjects[i];
Resource resource = bo.eResource();
Assert.isNotNull(resource, " Business object " + bo + " is not contained in a resource"); //$NON-NLS-1$ //$NON-NLS-2$
ResourceSet resourceSet = resource.getResourceSet();
Assert.isNotNull(resourceSet, " Resource " + resource + " is not contained in a resource set"); //$NON-NLS-1$ //$NON-NLS-2$
TransactionalEditingDomain editingDomain = getDiagramTypeProvider().getDiagramEditor().getEditingDomain();
ResourceSet editorResourceSet = editingDomain.getResourceSet();
if (!resourceSet.equals(editorResourceSet)) {
URI boUri = EcoreUtil.getURI(bo);
bo = editorResourceSet.getEObject(boUri, true);
}
if (bo != null) {
link.getBusinessObjects().add(bo);
}
Should it not be:
URI boUri = EcoreUtil.getURI(bo);
bo = resourceSet.getEObject(boUri, true); // instead of editorResourceSet?
Cheers
Joerg
|
|
|
|
|
|
|
|
Re: Store EMF model and Graphiti diagram seperately [message #757563 is a reply to message #720772] |
Sat, 19 November 2011 05:21  |
Eclipse User |
|
|
|
Michael,
have you ever found out how to do this? Currently, I have exactly the same issue. I would like to reuse the same editing domain for all editors/diagrams opened from the same project.
I would be grateful about any hints you can give me. Thanks!
Best Regards,
Marcus
|
|
|
Powered by
FUDForum. Page generated in 0.06008 seconds