Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to propagate element changes to WritableList's listener?
How to propagate element changes to WritableList's listener? [message #558320] Sat, 11 September 2010 08:47 Go to next message
Frank is currently offline FrankFriend
Messages: 23
Registered: July 2010
Junior Member
I found that the listener of WritableList can only be notified if there is any "add", "remove" or "set" operation occurs on the list.

Sometimes, I want to add observable beans to the WritableList, and I want the listener of this WritableList can be notified if the list's element - observable bean - fired property changed event.

I've noticed that this snippet used a observable Person class, which can emit PropertyChangeEvent to listeners. But I cannot understand how the final listener (the TableViewer intance) is able to perceive that event.

Can any body show me a right way to do this? Thanks.
Re: How to propagate element changes to WritableList's listener? [message #558326 is a reply to message #558320] Sat, 11 September 2010 09:21 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5463
Registered: July 2009
Senior Member
Then you need to create an ObservableMap from the WritableList.

IObservableList l = new WritableList();
IBeanValueProperty p = BeanProperties.value("myattribute");
IObservableMap map = p.observeDetail(l);
map.addMapChangeListener( new IMapChangeListener() {
public void handleMapChange(MapChangeEvent event) {
// ...
}
});

Tom

Am 11.09.10 10:47, schrieb Frank:
> I found that the listener of WritableList can only be notified if there
> is any "add", "remove" or "set" operation occurs on the list.
>
> Sometimes, I want to add observable beans to the WritableList, and I
> want the listener of this WritableList can be notified if the list's
> element - observable bean - fired property changed event.
>
> I've noticed that this
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.e xamples.databinding/src/org/eclipse/jface/examples/databindi ng/snippets/Snippet009TableViewer.java?view=markup
> used a observable Person class, which can emit PropertyChangeEvent to
> listeners. But I cannot understand how the final listener (the
> TableViewer intance) is able to perceive that event.
>
> Can any body show me a right way to do this? Thanks.
Re: How to propagate element changes to WritableList's listener? [message #558332 is a reply to message #558326] Sat, 11 September 2010 09:56 Go to previous messageGo to next message
Frank is currently offline FrankFriend
Messages: 23
Registered: July 2010
Junior Member
Thanks, Tom.
p.observeDetail(I) returns IObservableList, right?why IObservableMap?

Tom Schindl wrote on Sat, 11 September 2010 05:21
Then you need to create an ObservableMap from the WritableList.

IObservableList l = new WritableList();
IBeanValueProperty p = BeanProperties.value("myattribute");
IObservableMap map = p.observeDetail(l);
map.addMapChangeListener( new IMapChangeListener() {
public void handleMapChange(MapChangeEvent event) {
// ...
}
});

Tom

Am 11.09.10 10:47, schrieb Frank:
> I found that the listener of WritableList can only be notified if there
> is any "add", "remove" or "set" operation occurs on the list.
>
> Sometimes, I want to add observable beans to the WritableList, and I
> want the listener of this WritableList can be notified if the list's
> element - observable bean - fired property changed event.
>
> I've noticed that this
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.e xamples.databinding/src/org/eclipse/jface/examples/databindi ng/snippets/Snippet009TableViewer.java?view=markup
> used a observable Person class, which can emit PropertyChangeEvent to
> listeners. But I cannot understand how the final listener (the
> TableViewer intance) is able to perceive that event.
>
> Can any body show me a right way to do this? Thanks.

Re: How to propagate element changes to WritableList's listener? [message #558336 is a reply to message #558332] Sat, 11 September 2010 10:18 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5463
Registered: July 2009
Senior Member
Oh sorry.

You need to translate the IObservableList into an IObservableSet in case
of a Viewer you can get the set from
ObservableListContentProvider#getKnownElements().

The IObservableMap is informed when *any* of the lists-elements
myproperty changes. If you are not using an
ObservableListContentProvider you can transform an IObservableList using
ListToSetAdapter and the code below reads:

IObservableMap map = p.observeDetail(new ListToSetAdapter(l));

Tom

Am 11.09.10 11:56, schrieb Frank:
> Thanks, Tom.
> p.observeDetail(I) returns IObservableList, right?why IObservableMap?
>
> Tom Schindl wrote on Sat, 11 September 2010 05:21
>> Then you need to create an ObservableMap from the WritableList.
>>
>> IObservableList l = new WritableList();
>> IBeanValueProperty p = BeanProperties.value("myattribute");
>> IObservableMap map = p.observeDetail(l);
>> map.addMapChangeListener( new IMapChangeListener() {
>> public void handleMapChange(MapChangeEvent event) {
>> // ...
>> }
>> });
>>
>> Tom
>>
>> Am 11.09.10 10:47, schrieb Frank:
>> > I found that the listener of WritableList can only be notified if there
>> > is any "add", "remove" or "set" operation occurs on the list.
>> > > Sometimes, I want to add observable beans to the WritableList, and I
>> > want the listener of this WritableList can be notified if the list's
>> > element - observable bean - fired property changed event.
>> > > I've noticed that this
>> > http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.e
>> xamples.databinding/src/org/eclipse/jface/examples/databindi
>> ng/snippets/Snippet009TableViewer.java?view=markup
>> > used a observable Person class, which can emit PropertyChangeEvent to
>> > listeners. But I cannot understand how the final listener (the
>> > TableViewer intance) is able to perceive that event.
>> > > Can any body show me a right way to do this? Thanks.
>
>
Re: How to propagate element changes to WritableList's listener? [message #558340 is a reply to message #558336] Sat, 11 September 2010 11:09 Go to previous messageGo to next message
Frank is currently offline FrankFriend
Messages: 23
Registered: July 2010
Junior Member
What if I want the final listener get notified not only on "myproperty" property, but any property of the underlying bean?


Re: How to propagate element changes to WritableList's listener? [message #558346 is a reply to message #558340] Sat, 11 September 2010 11:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5463
Registered: July 2009
Senior Member
You need to create an IObservableMap for every attribute.

Tom

Am 11.09.10 13:09, schrieb Frank:
> What if I want the final listener get notified not only on "myproperty"
> property, but any property of the underlying bean?
>
>
>
Re: How to propagate element changes to WritableList's listener? [message #558356 is a reply to message #558346] Sat, 11 September 2010 15:23 Go to previous message
Frank is currently offline FrankFriend
Messages: 23
Registered: July 2010
Junior Member
Smile
Thank you!
Previous Topic:why ComboViewer starts with blank selection?
Next Topic:Zoom funtion in a RCP View?
Goto Forum:
  


Current Time: Mon Nov 24 01:27:19 GMT 2014

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

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