Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EContentAdapter not fired for containment relation
EContentAdapter not fired for containment relation [message #991769] Thu, 20 December 2012 01:46 Go to next message
Deepak P is currently offline Deepak P
Messages: 20
Registered: January 2012
Junior Member
Hello All,
I am very much new to EMF concepts. So i have a doubt regarding adding an EContentAdapter.

We have "MySystem" object in the Ecore. And "MySystem" has a containment relationship to "MyElements". So when i add a EContentAdapter to "MySystem", If there are any changes in "MyElements" , the notifier should be notified right ?

The code snippet is as given below

public class MySystemCreator {

private void create() {
mySystem = myFactory.createMySystem();
MySystemChangeContentAdapter mySystemChangeContentAdapter = new MySystemChangeContentAdapter();
mySystem.eAdapters().add(mySystemChangeContentAdapter );
}
}

public class MySystemChangeContentAdapter extends EContentAdapter {

@Override
public void notifyChanged(final Notification notification) {
super.notifyChanged(notification);
System.out.println("Executed");
}
}

public class CreateMyElements {

public Object[] create(){

...
mySystem.getElements().add(myElement);
}
}

So when we add "myElement" to "mySystem", the notifier is not fired.

Is it the correct way of writing a EcontentAdapter ?


Re: EContentAdapter not fired for containment relation [message #991791 is a reply to message #991769] Thu, 20 December 2012 02:54 Go to previous messageGo to next message
Ruben Faelens is currently offline Ruben Faelens
Messages: 3
Registered: December 2012
Junior Member
The notifier should really be fired. Your usage is correct.

* Check whether the mySystem element is the same in both cases (adding the eAdapter, adding the child)
* Check whether the eAdapters field of mySystem contains your custom adapter.
* Is the elements list an EList / NotifyingList? Debug inside to see whether events get fired due to an element being added.
Re: EContentAdapter not fired for containment relation [message #994077 is a reply to message #991791] Wed, 26 December 2012 05:20 Go to previous messageGo to next message
Deepak P is currently offline Deepak P
Messages: 20
Registered: January 2012
Junior Member
Hello Ruben,
Thanks for your reply.

The problem was that "mySystem" object were different.
Because of which even though custom adapter was added to "mySystem" it was not getting fired.

Regarding "elements", Yes it is a EList.

Regards,
Deepak P
Re: EContentAdapter not fired for containment relation [message #994237 is a reply to message #994077] Wed, 26 December 2012 14:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
Deepak,

Nothing looks wrong from what you described so use the debugger to see
what's actually happening.


On 26/12/2012 11:20 AM, Deepak P wrote:
> Hello Ruben,
> Thanks for your reply.
>
> The problem was that "mySystem" object were different.
> Because of which even though custom adapter was added to "mySystem" it
> was not getting fired.
>
> Regarding "elements", Yes it is a EList.
>
> Regards,
> Deepak P
Re: EContentAdapter not fired for containment relation [message #995857 is a reply to message #994237] Mon, 31 December 2012 05:07 Go to previous message
Deepak P is currently offline Deepak P
Messages: 20
Registered: January 2012
Junior Member
Hello Ed Merks,

Actually the object "mySystem" used in the class "MySystemCreator" and the one used in "CreateMyElements" are different instances.
Hence the notifier wasn't getting fired.

Thanks for your reply

Regards,
Deepak P
Previous Topic:Locking Mechanism in CDO
Next Topic:[XCore] Generating artifacts
Goto Forum:
  


Current Time: Sun Aug 31 02:41:08 EDT 2014

Powered by FUDForum. Page generated in 0.02024 seconds