|
Re: Reference from one model to another? [message #430878 is a reply to message #430876] |
Mon, 15 June 2009 12:12 |
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 #430911 is a reply to message #430896] |
Wed, 17 June 2009 11:31 |
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 |
Ed Merks Messages: 33140 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
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03692 seconds