Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » [DataBinding] JavaBeansObservable not updating
[DataBinding] JavaBeansObservable not updating [message #325566] Fri, 22 February 2008 03:37 Go to next message
Eclipse UserFriend
Hello,
during development with the databinding framework I found a strange
behaviour of the JavaBeansObservable (M20070822-0800):

Suppose we run the following simple code:

ModelBean modelBean = new ModelBean();
ModelBean targetBean = new ModelBean();

IObservableList modelBeanObservableList =
BeansObservables.observeList(Realm.getDefault(), modelBean, "list",
String.class);
IObservableList targetBeanObservableList =
BeansObservables.observeList(Realm.getDefault(), targetBean, "list",
String.class);

DataBindingContext bindingContext = new DataBindingContext();
bindingContext.bindList(targetBeanObservableList, modelBeanObservableList,
null, null);

modelBean.add("Str 1");
modelBean.clear();
targetBean.add("Str 2");
for(Object o : modelBean.getList()){
System.out.println(o);
}

ModelBean has a simple array list containing strings and clear() resets the
list. Any other modification of the list can be imagined.
One would expect the console to output: "Str2". But surprisingly there is no
output at all - the model was not updated.
When I debugged the code of JavaBeansObservable I found out the place, where
the underlying writeableList is updated:

public void add(int index, Object element) {
....
wrappedList.add(index, element);
....
}

But this line throws an exception (UnsupportedOperationException?) as
wrappedList is not of type ArrayList but Arrays$ArrayList.

I question myself, what did I wrong?

Nice Greetings,
Masroor
Re: [DataBinding] JavaBeansObservable not updating [message #325579 is a reply to message #325566] Fri, 22 February 2008 10:38 Go to previous messageGo to next message
Eclipse UserFriend
Arrays.asList returns a list that is *backed* by the passed in array.
Since arrays cannot change length, neither can the list. To make the
list fully modifiable, try using an ArrayList with the copy constructor:

list = new ArrayList(Arrays.asList(array));

Matthew

Masroor Ahmad wrote:
> Hello,
> during development with the databinding framework I found a strange
> behaviour of the JavaBeansObservable (M20070822-0800):
>
> Suppose we run the following simple code:
>
> ModelBean modelBean = new ModelBean();
> ModelBean targetBean = new ModelBean();
>
> IObservableList modelBeanObservableList =
> BeansObservables.observeList(Realm.getDefault(), modelBean, "list",
> String.class);
> IObservableList targetBeanObservableList =
> BeansObservables.observeList(Realm.getDefault(), targetBean, "list",
> String.class);
>
> DataBindingContext bindingContext = new DataBindingContext();
> bindingContext.bindList(targetBeanObservableList, modelBeanObservableList,
> null, null);
>
> modelBean.add("Str 1");
> modelBean.clear();
> targetBean.add("Str 2");
> for(Object o : modelBean.getList()){
> System.out.println(o);
> }
>
> ModelBean has a simple array list containing strings and clear() resets the
> list. Any other modification of the list can be imagined.
> One would expect the console to output: "Str2". But surprisingly there is no
> output at all - the model was not updated.
> When I debugged the code of JavaBeansObservable I found out the place, where
> the underlying writeableList is updated:
>
> public void add(int index, Object element) {
> ...
> wrappedList.add(index, element);
> ...
> }
>
> But this line throws an exception (UnsupportedOperationException?) as
> wrappedList is not of type ArrayList but Arrays$ArrayList.
>
> I question myself, what did I wrong?
>
> Nice Greetings,
> Masroor
>
>
Re: [DataBinding] JavaBeansObservable not updating [message #325580 is a reply to message #325566] Fri, 22 February 2008 10:45 Go to previous messageGo to next message
Eclipse UserFriend
> But this line throws an exception (UnsupportedOperationException?) as
> wrappedList is not of type ArrayList but Arrays$ArrayList.

Arrays.asList() returns an unmodifiable list. The question now is: did you
create this list, or did the data binding framework do that. If it's the
former, make sure you use modifiable lists in both model and target. If it's
the latter, would you mind filing a bug, ideally with an attached snippet
with which we can reproduce it?

http://wiki.eclipse.org/Platform_UI/FAQ#How_do_I_report_a_bu g.3F

Thanks
Boris
Re: [DataBinding] JavaBeansObservable not updating [message #325581 is a reply to message #325579] Fri, 22 February 2008 11:11 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the reply.

I see, to solve this one has to change API code or subclass.
The original API code:

public class JavaBeanObservableList extends ObservableList implements
IBeanObservable {
....
updateWrappedList(Arrays.asList(getValues()));
....
}

Regards,
Masroor

> Arrays.asList returns a list that is *backed* by the passed in array.
> Since arrays cannot change length, neither can the list. To make the list
> fully modifiable, try using an ArrayList with the copy constructor:
>
> list = new ArrayList(Arrays.asList(array));
>
> Matthew
>
> Masroor Ahmad wrote:
>> Hello,
>> during development with the databinding framework I found a strange
>> behaviour of the JavaBeansObservable (M20070822-0800):
>>
>> Suppose we run the following simple code:
>>
>> ModelBean modelBean = new ModelBean();
>> ModelBean targetBean = new ModelBean();
>>
>> IObservableList modelBeanObservableList =
>> BeansObservables.observeList(Realm.getDefault(), modelBean, "list",
>> String.class);
>> IObservableList targetBeanObservableList =
>> BeansObservables.observeList(Realm.getDefault(), targetBean, "list",
>> String.class);
>>
>> DataBindingContext bindingContext = new DataBindingContext();
>> bindingContext.bindList(targetBeanObservableList,
>> modelBeanObservableList, null, null);
>>
>> modelBean.add("Str 1");
>> modelBean.clear();
>> targetBean.add("Str 2");
>> for(Object o : modelBean.getList()){
>> System.out.println(o);
>> }
>>
>> ModelBean has a simple array list containing strings and clear() resets
>> the list. Any other modification of the list can be imagined.
>> One would expect the console to output: "Str2". But surprisingly there is
>> no output at all - the model was not updated.
>> When I debugged the code of JavaBeansObservable I found out the place,
>> where the underlying writeableList is updated:
>>
>> public void add(int index, Object element) {
>> ...
>> wrappedList.add(index, element);
>> ...
>> }
>>
>> But this line throws an exception (UnsupportedOperationException?) as
>> wrappedList is not of type ArrayList but Arrays$ArrayList.
>>
>> I question myself, what did I wrong?
>>
>> Nice Greetings,
>> Masroor
Re: [DataBinding] JavaBeansObservable not updating [message #325582 is a reply to message #325580] Fri, 22 February 2008 11:14 Go to previous messageGo to next message
Eclipse UserFriend
Roger this. It's the latter case.
Masroor

"Boris Bokowski" <Boris_Bokowski@ca.ibm.com> schrieb im Newsbeitrag
news:fpmqng$fe3$1@build.eclipse.org...
>> But this line throws an exception (UnsupportedOperationException?) as
>> wrappedList is not of type ArrayList but Arrays$ArrayList.
>
> Arrays.asList() returns an unmodifiable list. The question now is: did you
> create this list, or did the data binding framework do that. If it's the
> former, make sure you use modifiable lists in both model and target. If
> it's the latter, would you mind filing a bug, ideally with an attached
> snippet with which we can reproduce it?
>
> http://wiki.eclipse.org/Platform_UI/FAQ#How_do_I_report_a_bu g.3F
>
> Thanks
> Boris
>
>
Re: [DataBinding] JavaBeansObservable not updating [message #325583 is a reply to message #325582] Fri, 22 February 2008 11:27 Go to previous messageGo to next message
Eclipse UserFriend
I think this was fixed some time ago, possibly after the 3.3 release.
What version of DataBinding are you using?

Matthew

Masroor Ahmad wrote:
> Roger this. It's the latter case.
> Masroor
>
> "Boris Bokowski" <Boris_Bokowski@ca.ibm.com> schrieb im Newsbeitrag
> news:fpmqng$fe3$1@build.eclipse.org...
>>> But this line throws an exception (UnsupportedOperationException?) as
>>> wrappedList is not of type ArrayList but Arrays$ArrayList.
>> Arrays.asList() returns an unmodifiable list. The question now is: did you
>> create this list, or did the data binding framework do that. If it's the
>> former, make sure you use modifiable lists in both model and target. If
>> it's the latter, would you mind filing a bug, ideally with an attached
>> snippet with which we can reproduce it?
>>
>> http://wiki.eclipse.org/Platform_UI/FAQ#How_do_I_report_a_bu g.3F
>>
>> Thanks
>> Boris
>>
>>
>
>
Re: [DataBinding] JavaBeansObservable not updating [message #325585 is a reply to message #325583] Fri, 22 February 2008 11:44 Go to previous messageGo to next message
Eclipse UserFriend
1.0.1.M20070910-0800b

"Matthew Hall" <matthall@woodcraftmill.com> schrieb im Newsbeitrag
news:fpmt68$t5s$1@build.eclipse.org...
>I think this was fixed some time ago, possibly after the 3.3 release. What
>version of DataBinding are you using?
>
> Matthew
>
> Masroor Ahmad wrote:
>> Roger this. It's the latter case.
>> Masroor
>>
>> "Boris Bokowski" <Boris_Bokowski@ca.ibm.com> schrieb im Newsbeitrag
>> news:fpmqng$fe3$1@build.eclipse.org...
>>>> But this line throws an exception (UnsupportedOperationException?) as
>>>> wrappedList is not of type ArrayList but Arrays$ArrayList.
>>> Arrays.asList() returns an unmodifiable list. The question now is: did
>>> you create this list, or did the data binding framework do that. If it's
>>> the former, make sure you use modifiable lists in both model and target.
>>> If it's the latter, would you mind filing a bug, ideally with an
>>> attached snippet with which we can reproduce it?
>>>
>>> http://wiki.eclipse.org/Platform_UI/FAQ#How_do_I_report_a_bu g.3F
>>>
>>> Thanks
>>> Boris
>>>
>>>
>>
Re: [DataBinding] JavaBeansObservable not updating [message #325586 is a reply to message #325583] Fri, 22 February 2008 12:02 Go to previous messageGo to next message
Eclipse UserFriend
Already reported: 217558 and fixed.
Thanks for support.

"Matthew Hall" <matthall@woodcraftmill.com> schrieb im Newsbeitrag
news:fpmt68$t5s$1@build.eclipse.org...
>I think this was fixed some time ago, possibly after the 3.3 release. What
>version of DataBinding are you using?
>
> Matthew
>
> Masroor Ahmad wrote:
>> Roger this. It's the latter case.
>> Masroor
>>
>> "Boris Bokowski" <Boris_Bokowski@ca.ibm.com> schrieb im Newsbeitrag
>> news:fpmqng$fe3$1@build.eclipse.org...
>>>> But this line throws an exception (UnsupportedOperationException?) as
>>>> wrappedList is not of type ArrayList but Arrays$ArrayList.
>>> Arrays.asList() returns an unmodifiable list. The question now is: did
>>> you create this list, or did the data binding framework do that. If it's
>>> the former, make sure you use modifiable lists in both model and target.
>>> If it's the latter, would you mind filing a bug, ideally with an
>>> attached snippet with which we can reproduce it?
>>>
>>> http://wiki.eclipse.org/Platform_UI/FAQ#How_do_I_report_a_bu g.3F
>>>
>>> Thanks
>>> Boris
>>>
>>>
>>
Re: [DataBinding] JavaBeansObservable not updating [message #325588 is a reply to message #325585] Fri, 22 February 2008 12:09 Go to previous message
Eclipse UserFriend
The current version of DataBinding is compatible with Eclipse 3.3. Try
running your app with a recent build of JDB:

http://download.eclipse.org/eclipse/downloads/drops/S-3.4M5- 200802071530/index.php

You should only need to swap in the data binding plugins:

org.eclipse.core.databinding
org.eclipse.core.databinding.beans
org.eclipse.jface.databinding

If the error goes away with the 3.4 build, we'll still want to fix it in
the 3.3 maintenance stream. So please file a bug either way--this test
will just help us determine the scope of the bug.

Matthew

Masroor Ahmad wrote:
> 1.0.1.M20070910-0800b
>
> "Matthew Hall" <matthall@woodcraftmill.com> schrieb im Newsbeitrag
> news:fpmt68$t5s$1@build.eclipse.org...
>> I think this was fixed some time ago, possibly after the 3.3 release. What
>> version of DataBinding are you using?
>>
>> Matthew
>>
>> Masroor Ahmad wrote:
>>> Roger this. It's the latter case.
>>> Masroor
>>>
>>> "Boris Bokowski" <Boris_Bokowski@ca.ibm.com> schrieb im Newsbeitrag
>>> news:fpmqng$fe3$1@build.eclipse.org...
>>>>> But this line throws an exception (UnsupportedOperationException?) as
>>>>> wrappedList is not of type ArrayList but Arrays$ArrayList.
>>>> Arrays.asList() returns an unmodifiable list. The question now is: did
>>>> you create this list, or did the data binding framework do that. If it's
>>>> the former, make sure you use modifiable lists in both model and target.
>>>> If it's the latter, would you mind filing a bug, ideally with an
>>>> attached snippet with which we can reproduce it?
>>>>
>>>> http://wiki.eclipse.org/Platform_UI/FAQ#How_do_I_report_a_bu g.3F
>>>>
>>>> Thanks
>>>> Boris
>>>>
>>>>
>
Previous Topic:[forms] adding composites + scrolling
Next Topic:[forms] multi page in a view
Goto Forum:
  


Current Time: Tue Jul 22 15:34:50 EDT 2025

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

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

Back to the top