Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 177770 - [DataBinding] Mutators not implemented on JavaBeansObservableList
Summary: [DataBinding] Mutators not implemented on JavaBeansObservableList
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.3 RC1   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 180386 (view as bug list)
Depends on:
Blocks: 154132
  Show dependency tree
 
Reported: 2007-03-16 11:14 EDT by Dave Orme CLA
Modified: 2007-05-18 10:38 EDT (History)
4 users (show)

See Also:


Attachments
tests patch (14.32 KB, patch)
2007-04-29 16:48 EDT, Brad Reynolds CLA
no flags Details | Diff
tests patch along with bug fixes (20.50 KB, patch)
2007-04-30 21:33 EDT, Brad Reynolds CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Orme CLA 2007-03-16 11:14:38 EDT
final IObservableList currentGroupTradeObList = BeansObservables.observeDetailList(Realm.getDefault(),
    modelObValue, "trades", Order.class);

results in an UnsupportedOperation exception.
Comment 1 Brad Reynolds CLA 2007-04-01 12:27:41 EDT
*** Bug 180386 has been marked as a duplicate of this bug. ***
Comment 2 Brad Reynolds CLA 2007-04-03 14:18:12 EDT
Boris, do you have time to look at this for 3.3M7?  The reason I ask is that this is unexpected.  I would think that the default behavior when observing a list is for it to be mutable, not immutable.
Comment 3 Brad Reynolds CLA 2007-04-25 01:16:15 EDT
Boris, are you going to be able to get to this for M7?
Comment 4 Boris Bokowski CLA 2007-04-25 10:14:39 EDT
I can try...
Comment 5 Brad Reynolds CLA 2007-04-25 21:53:45 EDT
(In reply to comment #4)
> I can try...
> 

If you can't get to it let me know and I'll try to find the time.
Comment 6 Boris Bokowski CLA 2007-04-28 14:44:35 EDT
Implementation released >20070428.  Tests would be good... Brad?
Comment 7 Brad Reynolds CLA 2007-04-29 15:01:14 EDT
(continuation from IM about the patch...)

I raised the question to Boris on IM that when an item is added a new list is constructed and the bean will fire a change event for the property.  This is not conveying to the consumer that a value has changed at an index, it's saying that the entire list changed.  This comes from section 7.2 of the bean spec[1]...

"In order to change the size of the array you must use the array setter method to set a new (or 
updated) array. "

As a result it would throw a property change event.  My opinion is that we shouldn't try to mimic this when an item is added.  If wanting to fire a change event from the bean the consumer could set a new list as they would an array.  If the consumer wants the array behavior they could also just expose an array rather than a collection.

I'm not comfortable guessing at this and it could have performance issues as we'd be constructing new lists any time an item is added or removed.  We also have to make assumptions on the type of List that the consumer is exposing when we set a new list.

Thoughts?

[1] http://java.sun.com/products/javabeans/docs/spec.html
Comment 8 Brad Reynolds CLA 2007-04-29 16:48:27 EDT
Created attachment 65354 [details]
tests patch

This is a patch with tests that I've written for the mutable aspects.  Half of these tests fail.  The reason being that the bean list is not be mutated on change of the observable list.  This is occurring because I removed the code to set a new list on every change.  I'd attempt to fix this but I don't have anymore time today to do so.
Comment 9 Brad Reynolds CLA 2007-04-29 21:04:21 EDT
(In reply to comment #7)
> (continuation from IM about the patch...)
> 
> I raised the question to Boris on IM that when an item is added a new list is
> constructed and the bean will fire a change event for the property.  This is
> not conveying to the consumer that a value has changed at an index, it's saying
> that the entire list changed.  This comes from section 7.2 of the bean
> spec[1]...
> 
> "In order to change the size of the array you must use the array setter method
> to set a new (or 
> updated) array. "
> 
> As a result it would throw a property change event.  My opinion is that we
> shouldn't try to mimic this when an item is added.  If wanting to fire a change
> event from the bean the consumer could set a new list as they would an array. 
> If the consumer wants the array behavior they could also just expose an array
> rather than a collection.
> 
> I'm not comfortable guessing at this and it could have performance issues as
> we'd be constructing new lists any time an item is added or removed.  We also
> have to make assumptions on the type of List that the consumer is exposing when
> we set a new list.
> 
> Thoughts?
> 
> [1] http://java.sun.com/products/javabeans/docs/spec.html
> 

Also if this was the approach a setter would have to exist for the list to be mutable.
Comment 10 Dave Orme CLA 2007-04-29 22:43:28 EDT
Joe, you have experience with the Java Bean spec; what do you think we should do with comment #7?

Thanks in advance
Comment 11 Joe Winchester CLA 2007-04-30 04:49:31 EDT
(In reply to comment #10)
> Joe, you have experience with the Java Bean spec; what do you think we should
> do with comment #7?

Yes, this is a real problem with the JavaBeans spec right now which doesn't treat list properties at all well, probably because at the time of the spec collections didn't exist.

However, JSR 273 (Design time API for JavaBeans) does address this and provide really good support for list properties.  The spec isn't finalized yet but it is close to having a reference implementation.  It won't make the language till Java7 though.  What it does is allow you to tie together things like a getCollection() method, the add, and the remove, as well have property change events that are signalled with the index of the item(s) being added or removed.  It also supports generics,  arrays (for people who want to use arrays).

Joe
Comment 12 Brad Reynolds CLA 2007-04-30 10:19:39 EDT
Thanks for the input Joe.

So we need to make a decision on this if we want to get this into 3.3M7.  My vote is if a getCollection() method exists then we can adapt it to an IObservableList and it should be mutable.  In our applications we will expose a getter and not a setter.  We want to be able to mutate the list but we don't want someone to be able to set a new instance so we don't expose a setter.  I vote for this to be an adpater to an existing instance and it does not change that instance.
Comment 13 Brad Reynolds CLA 2007-04-30 11:23:50 EDT
(In reply to comment #12)
> I vote for this to be an adpater to an existing instance and it does not change
> that instance.
> 

That is confusing.  Make that...

I vote for this to be an adapter to an existing instance and it does not replace the instance on change.
Comment 14 Brad Reynolds CLA 2007-04-30 21:10:53 EDT
Since I haven't heard anything either way I'm just going to go with the way it was previous implemented as I think it's important to get this in.
Comment 15 Brad Reynolds CLA 2007-04-30 21:33:05 EDT
Created attachment 65447 [details]
tests patch along with bug fixes

Patch working as initially designed.
Comment 16 Boris Bokowski CLA 2007-05-09 14:26:25 EDT
Brad, we should get this in for RC1.
Comment 17 Boris Bokowski CLA 2007-05-15 23:01:55 EDT
+1 for the patch (I added another test class for the "standard" case where the property is an array type).  Released >20070515.
Comment 18 Boris Bokowski CLA 2007-05-15 23:08:47 EDT
Btw, the only real changes in the code were two places where a variable was not incremented properly.
Comment 19 Boris Bokowski CLA 2007-05-18 10:38:25 EDT
Verified by checking the test results for I20070517-1700.