Bug 325236 - [DataBinding] Provide a replaceWith method in WritableList/Set
Summary: [DataBinding] Provide a replaceWith method in WritableList/Set
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-14 07:53 EDT by Ulli Hafner CLA
Modified: 2014-06-26 12:26 EDT (History)
2 users (show)

See Also:


Attachments
An example implementation (1.60 KB, text/plain)
2010-09-14 07:58 EDT, Ulli Hafner CLA
no flags Details
Patch for writable set (2.98 KB, text/plain)
2010-09-14 08:33 EDT, Ulli Hafner CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ulli Hafner CLA 2010-09-14 07:53:14 EDT
Build Identifier: I20100608-0911

The WritableList and WritableSet classes have functions clear(), removeAll(Collection) and addAll(Collection) methods. It would be nice to also have some kind of replaceWith(Collection) method, that replaces the current content with the specified content. (Currently this could be done only when using the calls sequence clear() and addAll(Collection), however at the cost of firing two events.) Having a method that does this computation in one step would be better if the event listeners do some expensive operations.

Reproducible: Always
Comment 1 Ulli Hafner CLA 2010-09-14 07:58:07 EDT
Created attachment 178811 [details]
An example implementation

We use the attached class to provide that feature. Maybe you can reuse that code.
Comment 2 Thomas Schindl CLA 2010-09-14 08:00:32 EDT
Could you provide this as a patch for WritableList/WritableSet?
Comment 3 Ulli Hafner CLA 2010-09-14 08:33:12 EDT
Created attachment 178816 [details]
Patch for writable set
Comment 4 Ulli Hafner CLA 2010-09-14 08:36:24 EDT
Hmm, seems that I can't change the description anymore:

Instead of "using the calls sequence clear() and addAll(Collection)" it should be 
"using the calls sequence removeAll(Collection) and addAll(Collection)".

(In reply to comment #0)
> Build Identifier: I20100608-0911
> 
> The WritableList and WritableSet classes have functions clear(),
> removeAll(Collection) and addAll(Collection) methods. It would be nice to also
> have some kind of replaceWith(Collection) method, that replaces the current
> content with the specified content. (Currently this could be done only when
> using the calls sequence clear() and addAll(Collection), however at the cost of
> firing two events.) Having a method that does this computation in one step
> would be better if the event listeners do some expensive operations.
> 
> Reproducible: Always
Comment 5 Ulli Hafner CLA 2010-09-14 08:38:48 EDT
I don't have an implemention for WritableList yet. Should I provide one, too?
Comment 6 Matthew Hall CLA 2010-09-16 20:34:55 EDT
Ulli,

I think I have a workaround for your use case that doesn't require new API:

List backingList = ... // the original list contents
IObservableValue listHolder = new WritableValue(backingList, List.class);
IObservableList list = Properties.selfList(SomeElementType.class).observeDetail(listHolder);

You can now modify list at will.  If you want to batch replace the contents of the list, you can do so by calling listHolder.setValue(theNewList).

Does this achieve what you're looking for?
Comment 7 Ulli Hafner CLA 2010-09-17 04:33:05 EDT
This is not exactly what I want but that is still an interesting aproach!

The drawback of your approach is that you don't get the removed and new elements in the event, just the new list. And a second drawback: as an application programmer I would like to work with just one object, i.e., I would like to access the list as such. 

If you would like to keep the API as small as possible, then I'm ok with the current implementation. (Even when you are adding the new methods I still need to provide a sub-class. Since the writable list/set is not Java 5 ready we will provide a generic wrapper for our team anyway)