Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Reference from one model to another?
Reference from one model to another? [message #430876] Mon, 15 June 2009 11:25 Go to next message
No real name is currently offline No real name
Messages: 61
Registered: July 2009
Member
Hi,

lets say I have a simple meta-model. It basically has only the EClass
"Person". "Person" has a name and a reference to another "Person", named
"father".

Lets say I generate two models from this meta-model:
- model A:
- Person "Anakin"
- model B:
- Person "Luke"

Now I want the father of Luke to reference Anakin. Is there a
standard-way to this, or do I have to work on that on my own (maybe by
introcing a boolean "isLink" property to "Person") ?

If there is a standard way, I would expect that to work:
- create a constraint which says a person can not have more then 5 children
- create the genmodel from the ecore
- create the editor from the ecore
- create a model B with one person "James"
- create a model A with 10 persons
- tell 6 of the 10 persons in model A that their father is "James"
- validate model B => get a validation error


Thank you for any help
Re: Reference from one model to another? [message #430878 is a reply to message #430876] Mon, 15 June 2009 12:12 Go to previous messageGo to next message
Eclipse User
Originally posted by: tim.baumgartner.innovations.de

Hi Usul,

> lets say I have a simple meta-model. It basically has only the EClass
> "Person". "Person" has a name and a reference to another "Person", named
> "father".
>
> Lets say I generate two models from this meta-model:
> - model A:
> - Person "Anakin"
> - model B:
> - Person "Luke"
>
> Now I want the father of Luke to reference Anakin.

You want Luke to be Anakin's father, right? What you wrote sounds a bit like
there are three persons involved.

> Is there a standard-way to this, or do I have to work on that on my own
> (maybe by introcing a boolean "isLink" property to "Person") ?

why not anakin.setFather(luke) ?

>
> If there is a standard way, I would expect that to work:
> - create a constraint which says a person can not have more then 5
> children

you could introduce a reference "children" from Person to Person and specify
4 as it's upper bound and "father" as it's opposite.


Best wishes,
Tim
Re: Reference from one model to another? [message #430886 is a reply to message #430876] Tue, 16 June 2009 07:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Usul,

Comments below.

Usul wrote:
> Hi,
>
> lets say I have a simple meta-model. It basically has only the EClass
> "Person". "Person" has a name and a reference to another "Person",
> named "father".
>
> Lets say I generate two models from this meta-model:
> - model A:
> - Person "Anakin"
> - model B:
> - Person "Luke"
>
> Now I want the father of Luke to reference Anakin. Is there a
> standard-way to this, or do I have to work on that on my own (maybe by
> introcing a boolean "isLink" property to "Person") ?
>
> If there is a standard way, I would expect that to work:
> - create a constraint which says a person can not have more then 5
> children
Set the multiplicity to 5.
> - create the genmodel from the ecore
Yes, create a new EMF Generator Model for it.
> - create the editor from the ecore
Generate All...
> - create a model B with one person "James"
> - create a model A with 10 persons
The generated editors will generally only create one root object per
resource but you could create 10 such resources.
> - tell 6 of the 10 persons in model A that their father is "James"
Yes, using the properties view.
> - validate model B => get a validation error
If you exceed the multiplicity it will validate as an error.
>
>
> Thank you for any help
>
Re: Reference from one model to another? [message #430894 is a reply to message #430886] Tue, 16 June 2009 15:41 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 61
Registered: July 2009
Member
Hi,

thank you for your reply. But I haven't been clear enough.

I mean, that I have two different models (that means, two different
files). Now I want to make a reference from one model-element in the one
model (file A) to a model-element in the other model (file B). I did not
find a way to do this.

thank you
Re: Reference from one model to another? [message #430896 is a reply to message #430894] Tue, 16 June 2009 17:10 Go to previous messageGo to next message
Mario Winterer is currently offline Mario Winterer
Messages: 136
Registered: July 2009
Senior Member
Usul schrieb:
> Hi,
>
> thank you for your reply. But I haven't been clear enough.
>
> I mean, that I have two different models (that means, two different
> files). Now I want to make a reference from one model-element in the
> one model (file A) to a model-element in the other model (file B). I
> did not find a way to do this.
>
> thank you
>

Hi!

(1) create a ResourceSet
ResourceSet resourceSet = new ResourceSetImpl();

(2) load both resources into this ResourceSet
Resource resource1 = resourceSet.getResource(uri1, true);
Resource resource2 = resourceSet.getResource(uri2, true);

(3) get persons "anakin" and "luke" from the two resources
Person anakin = (Person)resource1.getContents().get(0);
Person luke = (Person)resource2.getContents().get(1);

(4) set anakin as father of luke: luke.setFather(anakin)
luke.setFather(anakin);

(5) save both resources
resource1.save(null);
resource2.save(null);

Now, the second resource refers the first resource.

Mario
Re: Reference from one model to another? [message #430911 is a reply to message #430896] Wed, 17 June 2009 11:31 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 61
Registered: July 2009
Member
Thank you Mario.

I tried it and it works. So you can only do this programmaticly and not
with the generated editor, right? Because I tried to do this with the
editor. I opened one ressource, loaded the the one but then I did not
manage to create a reference from one ressource to the other.

But OK, it works, thank you.



> Usul schrieb:
>> Hi,
>>
>> thank you for your reply. But I haven't been clear enough.
>>
>> I mean, that I have two different models (that means, two different
>> files). Now I want to make a reference from one model-element in the
>> one model (file A) to a model-element in the other model (file B). I
>> did not find a way to do this.
>>
>> thank you
>>

> Hi!

> (1) create a ResourceSet
> ResourceSet resourceSet = new ResourceSetImpl();

> (2) load both resources into this ResourceSet
> Resource resource1 = resourceSet.getResource(uri1, true);
> Resource resource2 = resourceSet.getResource(uri2, true);

> (3) get persons "anakin" and "luke" from the two resources
> Person anakin = (Person)resource1.getContents().get(0);
> Person luke = (Person)resource2.getContents().get(1);

> (4) set anakin as father of luke: luke.setFather(anakin)
> luke.setFather(anakin);

> (5) save both resources
> resource1.save(null);
> resource2.save(null);

> Now, the second resource refers the first resource.

> Mario
Re: Reference from one model to another? [message #430912 is a reply to message #430911] Wed, 17 June 2009 12:01 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26050
Registered: July 2009
Senior Member
Usul,

It should work in the generated editors as well. Once a resource is
loaded, the objects in it should be available as choices in any of the
properties...


Usul wrote:
> Thank you Mario.
>
> I tried it and it works. So you can only do this programmaticly and
> not with the generated editor, right? Because I tried to do this with
> the editor. I opened one ressource, loaded the the one but then I did
> not manage to create a reference from one ressource to the other.
> But OK, it works, thank you.
>
>
>
>> Usul schrieb:
>>> Hi,
>>>
>>> thank you for your reply. But I haven't been clear enough.
>>>
>>> I mean, that I have two different models (that means, two different
>>> files). Now I want to make a reference from one model-element in
>>> the one model (file A) to a model-element in the other model (file
>>> B). I did not find a way to do this.
>>>
>>> thank you
>>>
>
>> Hi!
>
>> (1) create a ResourceSet
>> ResourceSet resourceSet = new ResourceSetImpl();
>
>> (2) load both resources into this ResourceSet
>> Resource resource1 = resourceSet.getResource(uri1, true);
>> Resource resource2 = resourceSet.getResource(uri2, true);
>
>> (3) get persons "anakin" and "luke" from the two resources
>> Person anakin = (Person)resource1.getContents().get(0);
>> Person luke = (Person)resource2.getContents().get(1);
>
>> (4) set anakin as father of luke: luke.setFather(anakin)
>> luke.setFather(anakin);
>
>> (5) save both resources
>> resource1.save(null);
>> resource2.save(null);
>
>> Now, the second resource refers the first resource.
>
>> Mario
>
>
Previous Topic:How to get model instance from other Plugin?
Next Topic:Using generated itemproviders from another plugin
Goto Forum:
  


Current Time: Thu Sep 18 17:47:08 GMT 2014

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

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