Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Referencing model elements (generated editor vs. editor on the fly)
Referencing model elements (generated editor vs. editor on the fly) [message #416475] Mon, 04 February 2008 19:11 Go to next message
Eclipse UserFriend
Originally posted by: lists.miketech.net

Hi,

I have the following problem: I have two meta models (ecore models) A and
B. The metamodel B references elements of the metamodel A.

Now I wanna create instances. For metamodel A I generate the EMF editor.
For metamodel no editor is needed (the instance of the metamodel is
created in another way).

Ok, now I create an instance of the metamodel A with the generated EMF
editor. After that I load the created instance of the metamodel B in the
resource set. So now both, an instance of metamodel A (A_I) and metamodel
B (B_I) are visible within the editor. As I mentioned the metamodel B
references elements of the metamodel A. I wanna set some elements in B_I
to use elements of A_I, but this is not possible. The elements of A_I are
not available in B_I.

Is it because A_I is used with a generated EMF editor and B_I isn't?
Because if I generate an EMF editor for B too I can choose the elements.

And if I use no generated editor for both it is working too. Obviously
there is a mismatch of the metamodel package if I use a generated editor
and a editor on the fly.

Any idea how I can fix this issue?

Greetings

Michael
Re: Referencing model elements (generated editor vs. editor on the fly) [message #416478 is a reply to message #416475] Tue, 05 February 2008 04:49 Go to previous messageGo to next message
Marcelo Paternostro is currently offline Marcelo PaternostroFriend
Messages: 602
Registered: July 2009
Senior Member
Hi Michael,

I gave this a try and everything worked fine on my machine. This is
what I've done:

1. Defined a model A with a package A and a class CA in it
2. Generated the code (model, edit, and editor) for A
3. Launched a runtime workspace

-- from now on, everything is happening on the runtime workspace ---

4. Defined a model B with a package B and a class CB that has a
containment reference that can hold instances of CA (to do that I did a
"Load Resource" in the Ecore editor and pressed the button "Browse
Registered Packages..." and selected A.
5. Created an instance of CB (ob) from the Ecore editor (by right
clicking on the class B and using the "Creating Dynamic Instance..."
menu item)

6. Created an instance of CA (oa) using the generated wizard (which end
up opening the generated editor)

7. Loaded the resource containing ob in the oa's editor

8. Set ob as the container of oa by right-clicking ob and going through
the "New Child" menu

I am not a specialist on EMF.Edit but if I had to point you to a
direction, I would suggest checking if the constructor of the generated
editor (or the method initializeEditingDomain() ) executes this line:

adapterFactory.addAdapterFactory(new
ReflectiveItemProviderAdapterFactory());

It "enables" the editor to manipulate instances of EObject through
reflection.

Cheers,
Marcelo

Michael Gebhart wrote:
> Hi,
>
> I have the following problem: I have two meta models (ecore models) A and
> B. The metamodel B references elements of the metamodel A.
>
> Now I wanna create instances. For metamodel A I generate the EMF editor.
> For metamodel no editor is needed (the instance of the metamodel is
> created in another way).
>
> Ok, now I create an instance of the metamodel A with the generated EMF
> editor. After that I load the created instance of the metamodel B in the
> resource set. So now both, an instance of metamodel A (A_I) and metamodel
> B (B_I) are visible within the editor. As I mentioned the metamodel B
> references elements of the metamodel A. I wanna set some elements in B_I
> to use elements of A_I, but this is not possible. The elements of A_I are
> not available in B_I.
>
> Is it because A_I is used with a generated EMF editor and B_I isn't?
> Because if I generate an EMF editor for B too I can choose the elements.
>
> And if I use no generated editor for both it is working too. Obviously
> there is a mismatch of the metamodel package if I use a generated editor
> and a editor on the fly.
>
> Any idea how I can fix this issue?
>
> Greetings
>
> Michael
Re: Referencing model elements (generated editor vs. editor on the fly) [message #416496 is a reply to message #416478] Tue, 05 February 2008 14:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lists.miketech.net

Hi,

thanks for you help. Very interesting. When I use a containment reference
everything is working. But if I don't set containment to true I doesn't.
In the properties view the reference is listed, but I can't select the
element.

If I generate an editor for the second model it is working.

Any idea how I can make it working with a reference and no containment?

Greetings

Mike

On Mon, 04 Feb 2008 23:49:48 -0500, Marcelo Paternostro wrote:

> Hi Michael,
>
> I gave this a try and everything worked fine on my machine. This is
> what I've done:
>
> 1. Defined a model A with a package A and a class CA in it 2. Generated
> the code (model, edit, and editor) for A 3. Launched a runtime workspace
>
> -- from now on, everything is happening on the runtime workspace ---
>
> 4. Defined a model B with a package B and a class CB that has a
> containment reference that can hold instances of CA (to do that I did a
> "Load Resource" in the Ecore editor and pressed the button "Browse
> Registered Packages..." and selected A. 5. Created an instance of CB
> (ob) from the Ecore editor (by right clicking on the class B and using
> the "Creating Dynamic Instance..." menu item)
>
> 6. Created an instance of CA (oa) using the generated wizard (which end
> up opening the generated editor)
>
> 7. Loaded the resource containing ob in the oa's editor
>
> 8. Set ob as the container of oa by right-clicking ob and going through
> the "New Child" menu
>
> I am not a specialist on EMF.Edit but if I had to point you to a
> direction, I would suggest checking if the constructor of the generated
> editor (or the method initializeEditingDomain() ) executes this line:
>
> adapterFactory.addAdapterFactory(new
> ReflectiveItemProviderAdapterFactory());
>
> It "enables" the editor to manipulate instances of EObject through
> reflection.
>
> Cheers,
> Marcelo
>
> Michael Gebhart wrote:
>> Hi,
>>
>> I have the following problem: I have two meta models (ecore models) A
>> and B. The metamodel B references elements of the metamodel A.
>>
>> Now I wanna create instances. For metamodel A I generate the EMF
>> editor. For metamodel no editor is needed (the instance of the
>> metamodel is created in another way).
>>
>> Ok, now I create an instance of the metamodel A with the generated EMF
>> editor. After that I load the created instance of the metamodel B in
>> the resource set. So now both, an instance of metamodel A (A_I) and
>> metamodel B (B_I) are visible within the editor. As I mentioned the
>> metamodel B references elements of the metamodel A. I wanna set some
>> elements in B_I to use elements of A_I, but this is not possible. The
>> elements of A_I are not available in B_I.
>>
>> Is it because A_I is used with a generated EMF editor and B_I isn't?
>> Because if I generate an EMF editor for B too I can choose the
>> elements.
>>
>> And if I use no generated editor for both it is working too. Obviously
>> there is a mismatch of the metamodel package if I use a generated
>> editor and a editor on the fly.
>>
>> Any idea how I can fix this issue?
>>
>> Greetings
>>
>> Michael
Re: Referencing model elements (generated editor vs. editor on the fly) [message #416502 is a reply to message #416496] Tue, 05 February 2008 18:49 Go to previous messageGo to next message
David Steinberg is currently offline David SteinbergFriend
Messages: 489
Registered: July 2009
Senior Member
Hi Michael,

Non-containment references are realized by default as properties, and if
you look in ItemPropertyDescriptor.getReachableObjectsOfType(), you'll
see how we try to find the appropriate targets for a given object.

The first thing to point out is that it's searching for existing objects
accessible via the resource set. So, it's unlike creating a child object
under a containment reference in that an object must already exist and
be in, or referenced by, the contents of one of the resources being edited.

If that sounds obvious, apologies, and let's move on... ;)

The next thing to note is that we're searching for objects that are
type-compatible with the reference. If you look at
collectReachableObjectsOfType(), you'll see that it's simply calling
type.isInstance(object) to evaluate whether each object should be added
to the result.

I wonder if this could be an issue of having two different copies of
your package a around? If so, then this could be comparing two
different versions of the same EClass, which won't work.

Are you generating a model for package b or using the dynamic
implementation? In the latter case, perhaps the b.ecore file has
references to a of the form platform:/plugin/ABC/model/a.ecore instead
of http://www.example.com/a.ecore ? This would cause the a.ecore file
to be loaded and the dynamic implementation to be used. That would
leave you with two different versions of the package: the generated,
registered one that the editor is using and the dynamic one loaded into
the resource set.

Probably it would help if I could see your instance documents and, if
you are using dynamic EMF for package b, its Ecore file, too.

Cheers,
Dave


Michael Gebhart wrote:
> Hi,
>
> thanks for you help. Very interesting. When I use a containment reference
> everything is working. But if I don't set containment to true I doesn't.
> In the properties view the reference is listed, but I can't select the
> element.
>
> If I generate an editor for the second model it is working.
>
> Any idea how I can make it working with a reference and no containment?
>
> Greetings
>
> Mike
Re: Referencing model elements (generated editor vs. editor on the fly) [message #416606 is a reply to message #416502] Thu, 07 February 2008 15:35 Go to previous message
Eclipse UserFriend
Originally posted by: lists.miketech.net

Hi,

thanks for your help. The references were wrong. I wrote a script that
sets the local namespace to http://xy.ecore and now it is working.

Thanks!

Mike
Previous Topic:Common Navigator + EMF + Properties View
Next Topic:EMF C++ runtime support?
Goto Forum:
  


Current Time: Sat Apr 27 02:46:20 GMT 2024

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

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

Back to the top