EContentAdapter does not always see map values changes [message #1053559] |
Mon, 06 May 2013 10:20  |
Eclipse User |
|
|
|
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] by Moderator
|
|
|
Re: EContentAdapter does not always see map values changes [message #1053565 is a reply to message #1053559] |
Mon, 06 May 2013 10:39   |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.23891 seconds