Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Store EMF model and Graphiti diagram seperately
Store EMF model and Graphiti diagram seperately [message #718014] Tue, 23 August 2011 03:00 Go to next message
Maxime Carey is currently offline Maxime CareyFriend
Messages: 3
Registered: June 2011
Junior Member
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: Tue, 23 August 2011 03:01]

Report message to a moderator

Re: Store EMF model and Graphiti diagram seperately [message #718106 is a reply to message #718014] Tue, 23 August 2011 09:37 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
Hi Maxime,

not being sure what would be "the official" way (I can think of various scenarios), I am currently using the following approach.

I have a symbol for a "logical function" in the create method I have:

@
Override
	public Object[] create(ICreateContext context) {

		LogicalFunction logicalfunction = FunctionnetworkFactory.eINSTANCE
				.createLogicalFunction();

		logicalfunction.setName("Initial");
		FunctionNetworkProject functionNetworkProject = FunctionNetworkUtil
				.getFunctionNetworkProject(getDiagram());


Where FunctionNetworkUtil.getFunctionNetworkProject() does the following:

It checks if I have a "model.functionnetwork" in the same directory as my diagram. If not, it creates one. If so, it opens it and returns the root element, which will have my model element added.

You can think of various strategies to seperate the model. One would be to link the diagram to a domain object, but then you would have to set up the linking first...

Re: Store EMF model and Graphiti diagram seperately [message #718122 is a reply to message #718014] Tue, 23 August 2011 10:20 Go to previous messageGo to next message
Joerg Reichert is currently offline Joerg ReichertFriend
Messages: 80
Registered: July 2009
Location: Leipzig
Member
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


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Re: Store EMF model and Graphiti diagram seperately [message #718408 is a reply to message #718014] Wed, 24 August 2011 08:12 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Besides to what already has been written, there is an entry (the first one)
in our FAQ at http://www.eclipse.org/graphiti/developers/faq.php that
targets this.

Michael

"Maxime Carey" <forums-noreply@eclipse.org> wrote in message
news:j2v4g1$h6q$1@news.eclipse.org...
> Hi, I've been search a way how I could 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?
Re: Store EMF model and Graphiti diagram seperately [message #718479 is a reply to message #718408] Wed, 24 August 2011 13:19 Go to previous messageGo to next message
Maxime Carey is currently offline Maxime CareyFriend
Messages: 3
Registered: June 2011
Junior Member
Shame on me for not reading the FAQ! But how come this doesn't gets atop Google search?

Anyhow, thanks a lot!

[Updated on: Wed, 24 August 2011 13:19]

Report message to a moderator

Re: Store EMF model and Graphiti diagram seperately [message #720224 is a reply to message #718479] Tue, 30 August 2011 07:31 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
Dear all,

am I right that with the examples above a new ResourceSet/Editing Domain is created for each diagram? Is there any example of code where we would create a new diagram and add it to an existing resource set (e.g. an existing diagram and the corresponding model file).

Regards,

Andreas
Re: Store EMF model and Graphiti diagram seperately [message #720256 is a reply to message #720224] Tue, 30 August 2011 08:25 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Andreas,

this is more a question on EMF and how you maintain your editing domains
(e.g. how you make them available from where you would need to add the new
diagram). From Graphiti point of view you can simply add the diagram or the
model data to an existing EMF resource (and also to an already instantiated
domain).

HTH,
Michael


"Andreas Graf" schrieb im Newsbeitrag news:j3i30m$uai$1@news.eclipse.org...

Dear all,

am I right that with the examples above a new ResourceSet/Editing Domain is
created for each diagram? Is there any example of code where we would create
a new diagram and add it to an existing resource set (e.g. an existing
diagram and the corresponding model file).

Regards,

Andreas
Re: Store EMF model and Graphiti diagram seperately [message #720772 is a reply to message #720256] Wed, 31 August 2011 08:31 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
Hi Michael,

would you have some pointers which classes of Graphiti would be affected?
E.g. it seems to me, that when double clicking on a .diagram file in Eclipse explorer, the diagram is always opened with a resource set / editingdomain of its own.
DiagramEditorFactory calls createResourceSetAndEditingDomain(). Could you give a rough overview on which parts of the Graphiti Framework would be affected when putting more than one diagram / model resources into the same resource set / editing domain?

Thanks very much,

Andreas
Re: Store EMF model and Graphiti diagram seperately [message #757563 is a reply to message #720772] Sat, 19 November 2011 10:21 Go to previous message
Marcus Rickert is currently offline Marcus RickertFriend
Messages: 3
Registered: November 2011
Junior Member
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
Previous Topic:Load Domain Model (File) into Diagram
Next Topic:grid settings should be controlled by preferences rather than being diagram properties
Goto Forum:
  


Current Time: Fri Apr 19 15:31:38 GMT 2024

Powered by FUDForum. Page generated in 0.02902 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top