Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Sharing the same domain between different diagrams
Sharing the same domain between different diagrams [message #1718164] Mon, 21 December 2015 00:48 Go to next message
Rafhael Cunha is currently offline Rafhael CunhaFriend
Messages: 19
Registered: November 2015
Junior Member
Good Regards,
I am new to Eclipse GMF and I have many doubts related to domain sharing. I'm actually developing a methodology and diagrams for every diagram is a project part (with its own ecore). I wonder if you can even share the entities being separate projects? I ask because it has entities that are repeated in various diagrams and would make inheritance among diagrams to the user of the methodology is not necessary to redo their work.

Which I have seen some tutorials on the internet that teach to share fields between EMF and GMF, but my goal is different (I think).

Sorry for my bad English.

Thanks and await answers.
Re: Sharing the same domain between different diagrams [message #1718245 is a reply to message #1718164] Mon, 21 December 2015 15:10 Go to previous messageGo to next message
Paul C. Brown is currently offline Paul C. BrownFriend
Messages: 18
Registered: October 2013
Junior Member
Rafhael,

What you describe is the default behavior of EMF models. If you have a model element in one resource (file) that has an EMF reference to a model element in another resource, the file containing the element reference will end up with a URL referencing the other element in the other file. This is all managed by the infrastructure that stores and loads resources.

There are, however, two considerations about which you need to be aware, one regarding the URL and the other regarding the nature of the element reference.

With respect to the URL, it is important that you use the URI.createPlatoformResourceURI() method to create the URI for each resource. Doing so will result in relative pathnames, giving your model files some portability. If you use a "file:\\" prefix for your URL, the file locations will be absolute. Your code should look something like:

URI changeResourceURI = URI.createPlatformResourceURI("/CRL/Change.crl",true);
Resource changeResource = resourceSet.getResource(changeResourceURI,true);
changeResource.load(options);

A second consideration is the manner in which individual elements are identified within a resource. By default, the reference uses a count of the number of that type of object. In other words, if you have a model class Foo and you have three instances of Foo, your reference will be to the the 1st, 2nd, or 3rd instance of Foo. It's not an issue if all of the resources are loaded all the time, but if your referenced resource gets edited independently, the sequence number may no longer reference the instance you intended.

To avoid this problem, designate one of the element attributes as being an identifier in your EMF model and provide a unique ID. I use guids for mine. That way the identity of the referenced object does not change. Of course, you are now obligated to provide that unique identity.

One more thing to be aware of: the folder structure is baked into the URI, and thus into the references. If you have a reference to an element and you move the file to a sub-folder, the references are now broken. It's not a big deal to edit the file containing the reference to change the pathname, but it's a pain. I have not yet found an automated way of moving the files and fixing up the references.

Good luck!
Re: Sharing the same domain between different diagrams [message #1718267 is a reply to message #1718245] Tue, 22 December 2015 01:45 Go to previous messageGo to next message
Rafhael Cunha is currently offline Rafhael CunhaFriend
Messages: 19
Registered: November 2015
Junior Member
Paul, thanks for the reply. However I still have some doubts.

For example, he said that a resource model (an entity in ECORE) must reference the other. Right? If so, I do it through eannotations?

About URI, I must create one every entity ECORE? This change I do in own IDE by setting the URI or should Mecher directly in the codes generated from ECORE?

In the case of a 2 consideration, the new diagrams are loaded independently, i.e., the user will open as it needs. What would that guids you said? If what you said I would put a unique ID to each element of ECORE is it?

Would you have any examples to send me to be made that reference entities between different diagrams?

Thanks in advance, I await your answer.
Re: Sharing the same domain between different diagrams [message #1718268 is a reply to message #1718245] Tue, 22 December 2015 01:46 Go to previous messageGo to next message
Rafhael Cunha is currently offline Rafhael CunhaFriend
Messages: 19
Registered: November 2015
Junior Member
Paul, thanks for the reply. However I still have some doubts.

For example, he said that a resource model (an entity in ECORE) must reference the other. Right? If so, I do it through eannotations?

About URI, I must create one every entity ECORE? This change I do in own IDE by setting the URI or should Mecher directly in the codes generated from ECORE?

In the case of a 2 consideration, the new diagrams are loaded independently, i.e., the user will open as it needs. What would that guids you said? If what you said I would put a unique ID to each element of ECORE is it?

Would you have any examples to send me to be made that reference entities between different diagrams?

Thanks in advance, I await your answer.
Re: Sharing the same domain between different diagrams [message #1718269 is a reply to message #1718245] Tue, 22 December 2015 01:48 Go to previous messageGo to next message
Rafhael Cunha is currently offline Rafhael CunhaFriend
Messages: 19
Registered: November 2015
Junior Member
Paul, thanks for the reply. However I still have some doubts.

For example, he said that a resource model (an entity in ECORE) must reference the other. Right? If so, I do it through eannotations?

About URI, I must create one every entity ECORE? This change I do in own IDE by setting the URI or should Mecher directly in the codes generated from ECORE?

In the case of a 2 consideration, the new diagrams are loaded independently, i.e., the user will open as it needs. What would that guids you said? If what you said I would put a unique ID to each element of ECORE is it?

Would you have any examples to send me to be made that reference entities between different diagrams?

Thanks in advance, I await your answer.
Re: Sharing the same domain between different diagrams [message #1718271 is a reply to message #1718245] Tue, 22 December 2015 02:51 Go to previous messageGo to next message
Rafhael Cunha is currently offline Rafhael CunhaFriend
Messages: 19
Registered: November 2015
Junior Member
Paul, thanks for the reply. However I still have some doubts.

For example, he said that a resource model (an entity in ECORE) must reference the other. Right? If so, I do it through eannotations?

About URI, I must create one every entity ECORE? This change I do in own IDE by setting the URI or should Mecher directly in the codes generated from ECORE?

In the case of a 2 consideration, the new diagrams are loaded independently, i.e., the user will open as it needs. What would that guids you said? If what you said I would put a unique ID to each element of ECORE is it?

Would you have any examples to send me to be made that reference entities between different diagrams?

Thanks in advance, I await your answer.
Re: Sharing the same domain between different diagrams [message #1718327 is a reply to message #1718267] Tue, 22 December 2015 13:51 Go to previous messageGo to next message
Paul C. Brown is currently offline Paul C. BrownFriend
Messages: 18
Registered: October 2013
Junior Member
The reference to the other element is an ecore:EReference (see example below in which the pointerOwner is such a reference).

<eClassifiers xsi:type="ecore:EClass" name="Pointer" abstract="true" eSuperTypes="#//BaseElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="pointerOwner" eType="#//Element"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="referencedElementIdentifier"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="referencedElementVersion"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="referencedElementURI" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>

The URL I mentioned is the URL of the file containing the model. The file is loaded into an EMF Resource, and the set of resources (contained in the ResourceSet) is what your editor is working on. Here's a fragment from one file containing a reference to another element in another file. The href is the reference. It begins with the path to the file (here I have used a Platform Resource, so the path is just the file name indicating that the file is in the same directory). Also not the GUID after the hash tag, the result of my designating one of the attibutes as an identifier and using a GUID as the attribute value.

<ownedBaseElements xsi:type="crl:AbstractElementPointer" identifier="d76dffdc-0081-44c4-ba0f-6027cb3b734e" pointerOwner="c8be6b28-5637-4d6b-964f-59aaf7ac503f">
<referencedElement href="Core.crl#92df38e8-fcd9-4ba3-a188-130447232add"/>
</ownedBaseElements>

What you want to do is easily done, and largely the default behavior of generated EMF editors. However, I highly recommend that you start with a good EMF tutorial such as http://www.vogella.com/tutorials/EclipseEMF/article.html

Re: Sharing the same domain between different diagrams [message #1718801 is a reply to message #1718327] Wed, 30 December 2015 12:19 Go to previous messageGo to next message
Rafhael Cunha is currently offline Rafhael CunhaFriend
Messages: 19
Registered: November 2015
Junior Member
Hello,

I still do not understand completely what you suggested I do.

Let me give an example, I have two ecores, mybase.ecore and mybase2.ecore

MyBase the code is this:

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="Mybase" nsURI="URI.createPlatformResourceURI()" nsPrefix="teste-22-12-2015">
<eClassifiers xsi:type="ecore:EClass" name="NodeQuadrado">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
iD="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Domain">
<eStructuralFeatures xsi:type="ecore:EReference" name="nodeQuadrados" upperBound="-1"
eType="#//NodeQuadrado" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="nodeCirculos" upperBound="-1"
eType="#//NodeCirculo" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="NodeCirculo">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="label" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
</ecore:EPackage>



and the mybase2 is this:

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="Mybase2" nsURI="URI.createPlatformResourceURI()" nsPrefix="teste-22-12-2015">
<eClassifiers xsi:type="ecore:EClass" name="NodeQuadrado" eSuperTypes="Mybase.ecore#//NodeQuadrado"/>
</ecore:EPackage>


What I do is the mybase2 in nodequadrado references the nodequadrado the mybase1. To this end, the mybase2ecore I loaded the MyBase resource and put the super type of nodequadrado mybase2 was nodequadrado the mybase1. It is true?

I do not know how to do is put a unique ID to each element as you suggested, due to the need of the instances are not always loaded together. How do I do that?


Regarding URI.createPlatformResourceURI () method, I'm putting it on the field in nsURI own IDE when I edit the Ecore. It is true?


Thank you for assistance now.
Re: Sharing the same domain between different diagrams [message #1719023 is a reply to message #1718801] Mon, 04 January 2016 13:47 Go to previous messageGo to next message
Paul C. Brown is currently offline Paul C. BrownFriend
Messages: 18
Registered: October 2013
Junior Member
Rafhael,
My apologies. The examples I gave were for instances of the classes. What you are trying to do is have the definition of one class in one file refer to the definition of another class in another file. I have not done this, so I cannot provide examples or advice.
Re: Sharing the same domain between different diagrams [message #1719439 is a reply to message #1719023] Thu, 07 January 2016 21:41 Go to previous message
Paul C. Brown is currently offline Paul C. BrownFriend
Messages: 18
Registered: October 2013
Junior Member
Rafhael,

I had occasion today to look at my model files as raw text. What I noticed is that the references to other classes in the annotations seem to have the same syntax as the instance references. Therefore your eSuperTypes="Mybase.ecore#//NodeQuadrado" reference should be correct assuming that MyBase.ecore is in the same directory as the file containing the reference. If not, you need to modify "MyBase.ecore" to include a relative path.
Previous Topic:Did anyone met crash issue with SVG? How to solve?
Next Topic:How to make CDO changes update GMF diagrams?
Goto Forum:
  


Current Time: Fri Dec 15 10:29:39 GMT 2017

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

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