Bug 174421 - [DataBinding] BindList does not apply Converter
Summary: [DataBinding] BindList does not apply Converter
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks: 168225
  Show dependency tree
 
Reported: 2007-02-16 05:14 EST by Giulio Seregni CLA
Modified: 2007-07-29 09:21 EDT (History)
2 users (show)

See Also:


Attachments
Conversion support for ListBinding (2.61 KB, patch)
2007-02-27 16:12 EST, Peter Centgraf CLA
no flags Details | Diff
Patch to apply converter (2.63 KB, patch)
2007-03-04 16:09 EST, Giulio Seregni CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Giulio Seregni CLA 2007-02-16 05:14:29 EST
This method of SwtObservableList try to cast every object coming from the model  to String.

    public void add(int index, Object element) {
        int size = doGetSize();
        if (index < 0 || index > size)
            index = size;
        String[] newItems = new String[size + 1];
        System.arraycopy(getItems(), 0, newItems, 0, index);
        newItems[index] = (String) element;  <------------------------------------------  HERE
        System.arraycopy(getItems(), index, newItems, index + 1, size - index);
        setItems(newItems);
        fireListChange(Diffs.createListDiff(Diffs.createListDiffEntry(index,
                true, element)));
    } 

 

  so,   making something like this

        dbc.bindList(
                   SWTObservables.observeItems(usersList.getListViewer().getList()),
                     users, b);
 

    where users is an ObservableList based on an ArrayList<Integer> causes a ClassCastException 

Even applying a converter in BindSpec has no effects, i think that ListBinding is not caring about it.
Comment 1 Boris Bokowski CLA 2007-02-16 10:37:25 EST
ListBinding also does not work across realms, we can probably fix both at the same time.
Comment 2 Giulio Seregni CLA 2007-02-19 13:33:29 EST
i think that

newItems[index] = (String) element;

should be 

newItems[index] = element.toString;

you have to obtain a label from the element... or not?
Comment 3 Brad Reynolds CLA 2007-02-19 14:13:46 EST
(In reply to comment #2)
> i think that
> 
> newItems[index] = (String) element;
> 
> should be 
> 
> newItems[index] = element.toString;

I would prefer this not to change.  The reason being that the list returned specifies that it's contents are of type String.class.  I think the appropriate change is to support conversion in ListBinding as today we do not.  I was going to do this over the weekend but didn't get around to it.  If Boris doesn't get to it soon I'll try to do it some night this week.
Comment 4 Giulio Seregni CLA 2007-02-19 16:17:08 EST
I know that the appropriate way is to support convert.
I would like to contribute to the project, can i try do a patch?
there is a similar component that can i use as "model" ?
Comment 5 Brad Reynolds CLA 2007-02-19 16:35:51 EST
(In reply to comment #4)
> I know that the appropriate way is to support convert.
> I would like to contribute to the project, can i try do a patch?

Feel free.  We'd greatly appreciate it.

> there is a similar component that can i use as "model" ?

WritableList is an observable list that can be bound to the target.

Comment 6 Peter Centgraf CLA 2007-02-27 16:12:00 EST
Created attachment 59919 [details]
Conversion support for ListBinding

Am I correct in understanding that all we want here is for ListBinding to apply the modelToTargetConverter and targetToModelConverter already provided in the BindSpec?  If so, perhaps this patch will be sufficient.  Can someone test it for me and let me know?
Comment 7 Brad Reynolds CLA 2007-02-27 22:22:56 EST
(In reply to comment #6)
> Am I correct in understanding that all we want here is for ListBinding to apply
> the modelToTargetConverter and targetToModelConverter already provided in the
> BindSpec?  

Correct.

> If so, perhaps this patch will be sufficient.  Can someone test it
> for me and let me know?

I'm assuming with the info in bug 124683 comment 5 you will be able to do this on your own.  If not hollar and I can help out.

Comment 8 Brad Reynolds CLA 2007-02-27 22:24:10 EST
Adding Peter to the CC.  Peter, see comment 7.
Comment 9 Giulio Seregni CLA 2007-03-04 16:09:07 EST
Created attachment 60231 [details]
Patch to apply  converter
Comment 10 Giulio Seregni CLA 2007-03-04 16:10:29 EST
i moved IConverter conv = bindSpec.getModelToTargetConverter(); outside the for loop.




(In reply to comment #7)
> (In reply to comment #6)
> > Am I correct in understanding that all we want here is for ListBinding to apply
> > the modelToTargetConverter and targetToModelConverter already provided in the
> > BindSpec?  
> 
> Correct.
> 
> > If so, perhaps this patch will be sufficient.  Can someone test it
> > for me and let me know?
> 
> I'm assuming with the info in bug 124683 comment 5 you will be able to do this
> on your own.  If not hollar and I can help out.
> 

Comment 11 Boris Bokowski CLA 2007-03-05 17:33:03 EST
This will change when we move away from BindSpec. See bug 172193.
Comment 12 Boris Bokowski CLA 2007-03-19 16:36:39 EDT
This has been fixed as part of the refactoring to use UpdateListStrategy instead of BindSpec.
Comment 13 Boris Bokowski CLA 2007-03-23 09:00:37 EDT
Verified on Windows XP using I20070322-1800 by code inspection.
Comment 14 Eclipse Webmaster CLA 2007-07-29 09:21:46 EDT
Changing OS from Mac OS to Mac OS X as per bug 185991