Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Add EContentAdapter(How to correctly add listener)
Add EContentAdapter [message #538518] Mon, 07 June 2010 19:58 Go to next message
No real name is currently offline No real nameFriend
Messages: 18
Registered: October 2009
Location: denmark
Junior Member
Hi,

Maybe this is a dumb question.

I have a model which has two classes, A and B.
A has a reference to B. I would like A instance listens to the corresponding referenced B instance. Based on B's specific changes, the A instance will modify it's attributes.

I would like to ask where should I add my EContentAdapter in the generated code. I have tried to add the adapter in the setB method. But this method is called only if the reference is set.

Thank you for your advices!

Ayia
Re: Add EContentAdapter [message #538561 is a reply to message #538518] Tue, 08 June 2010 00:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ayia,

Comments below.

wg@mci.sdu.dk wrote:
> Hi,
>
> Maybe this is a dumb question.
> I have a model which has two classes, A and B.
> A has a reference to B. I would like A instance listens to the
> corresponding referenced B instance. Based on B's specific changes,
> the A instance will modify it's attributes.
>
> I would like to ask where should I add my EContentAdapter in the
> generated code. I have tried to add the adapter in the setB method.
> But this method is called only if the reference is set.
If the reference isn't set, is there anything listen to?

If you look in EContentAdapter and ECrossReferenceAdapter you see that
they generally hook things up based on notification, i.e., you might
listen to A to see when it's B(s) change and use that to add and remove
adapters.
> Thank you for your advices!
>
> Ayia


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Add EContentAdapter [message #538654 is a reply to message #538561] Tue, 08 June 2010 10:54 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 18
Registered: October 2009
Location: denmark
Junior Member
Thank you Ed, your reply enlightened me.

I stuck with this problem in a scenario like:
If I have created a model containing A and B instances, In one A instance I have set the reference to certain B instance (during set I was able to add adapter), and then closed the editor with a serialized model, next time when I open the editor with the model again, I would like A directly response to possible changes of the referenced B (which I failed to achieve).

I think what I should do is adding an EContentaAdapter in the createModel() method inside the generated editor plugin, so that interested modifications will be notified. Is this approach correct or some better solutions are available.

Thank you very much for your reply!
Ayia
Re: Add EContentAdapter [message #538771 is a reply to message #538654] Tue, 08 June 2010 15:09 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Ayia,

Such a content adapter can definitely get notifications for all objects
in the entire resource set so you could definitely find out about all
changes that happen to all B instances. I'm not sure if given a B, you
immediately know which A instance(s) refer to it, i.e., if it has an
opposite, or is a containment reference and hence EObject.eContainer is
an implicit opposite. You might want to use an ECrossReferenceAdapter
which actually helps to track inverses references for references that
don't have opposites..


wg@mci.sdu.dk wrote:
> Thank you Ed, your reply enlightened me.
>
> I stuck with this problem in a scenario like: If I have created a
> model containing A and B instances, In one A instance I have set the
> reference to certain B instance (during set I was able to add
> adapter), and then closed the editor with a serialized model, next
> time when I open the editor with the model again, I would like A
> directly response to possible changes of the referenced B (which I
> failed to achieve).
>
> I think what I should do is adding an EContentaAdapter in the
> createModel() method inside the generated editor plugin, so that
> interested modifications will be notified. Is this approach correct or
> some better solutions are available.
>
> Thank you very much for your reply!
> Ayia


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF and GEF, possible values of an EAttribute according to another EAttribute value
Next Topic:Loading model instances from different ecore projects
Goto Forum:
  


Current Time: Fri Sep 20 16:56:14 GMT 2024

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

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

Back to the top