Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EContentAdapter does not always see map values changes
EContentAdapter does not always see map values changes [message #1053559] Mon, 06 May 2013 10:20 Go to next message
David Michonneau is currently offline David Michonneau
Messages: 85
Registered: July 2009
Member
I have an issue with EContentAdapter. When I have maps with lists as values, it does not detect that new list instances are added as values. And so no notification is triggered when the list changes. Here is an example that demonstrates it:

Note that if the EContentAdapter is registered after the new BasicEList() is added to the map, it gets the notification correctly

Any idea if this is a bug, or there is a way to do it that would work?

---- xcore
package test

class A {
contains TestMap[] items
}
class ItemValue {}
class TestMap wraps java.util.Map$Entry{
String key
contains ItemValue [0..*] value
}

---- test
A a = TestFactory.eINSTANCE.createA();
Adapter listener = new EContentAdapter() {
@Override
public void notifyChanged(Notification notification) {
System.out.println(notification);
}
};
a.eAdapters().add(listener);
a.getItems().put("key" , new BasicEList<ItemValue>()); // this seems to go unnoticed by EContentAdapter
ItemValue value = TestFactory.eINSTANCE.createItemValue();
a.getItems().get("key").add(value ); // EContentAdapter not notified

[Updated on: Mon, 06 May 2013 10:21]

Report message to a moderator

Re: EContentAdapter does not always see map values changes [message #1053565 is a reply to message #1053559] Mon, 06 May 2013 10:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26014
Registered: July 2009
Senior Member
David,

Comments below.

On 06/05/2013 4:20 PM, David Michonneau wrote:
> I have an issue with EContentAdapter. When I have maps with lists as
> values, it does not detect that new list instances are added as values.
I think that's not true. When I run your test case there is one
notification, i.e., for the map entry being added to the items list...
> And so no notification is triggered when the list changes. Here is an
> example that demonstrates it:
>
> Note that if the EContentAdapter is registered after the new
> BasicEList() is added to the map, it gets the notification correctly
>
> Any idea if this is a bug, or there is a way to do it that would work?
>
> ---- xcore
> package test
>
> class A {
> contains TestMap[] items
> }
> class ItemValue {}
> class TestMap wraps java.util.Map$Entry{
> String key
> contains ItemValue [0..*] value
> }
>
> ---- test
> A a = TestFactory.eINSTANCE.createA();
> Adapter listener = new EContentAdapter() {
> @Override
> public void notifyChanged(Notification notification) {
> System.out.println(notification);
You're not calling super, so the content adapter doesn't attach itself
to the newly added map entry...
> }
> };
> a.eAdapters().add(listener); a.getItems().put("key" , new
> BasicEList<ItemValue>()); // this seems to go unnoticed by
> EContentAdapter
> ItemValue value = TestFactory.eINSTANCE.createItemValue();
> a.getItems().get("key").add(value ); // EContentAdapter not notified
Re: EContentAdapter does not always see map values changes [message #1053566 is a reply to message #1053565] Mon, 06 May 2013 10:43 Go to previous messageGo to next message
David Michonneau is currently offline David Michonneau
Messages: 85
Registered: July 2009
Member
No Message Body
Re: EContentAdapter does not always see map values changes [message #1053567 is a reply to message #1053566] Mon, 06 May 2013 10:44 Go to previous message
David Michonneau is currently offline David Michonneau
Messages: 85
Registered: July 2009
Member
Yes I just realised that too...

Thanks,

David
Previous Topic:Backslashes and spaces in EMF URI's
Next Topic:[Teneo] Using ChangeRecorder and persisting ChangeDescription models
Goto Forum:
  


Current Time: Mon Sep 01 03:34:37 EDT 2014

Powered by FUDForum. Page generated in 0.02337 seconds