FilteredList/SortedList
Richard Bair
richard.bair at oracle.com
Mon Jan 7 10:25:33 PST 2013
> I find it really strange that TableView modifies the list I put into it
> when I sort it.
>
> Say I have an Domain model like this:
>
> Person {
> private ObservableList<Address> addresses;
> }
>
> Address {
> private String street;
> ....
> }
>
> and I put the a persons address list into a table view, I would not
> expect you to modify it when the table gets sorted. I think you need to
> keep a sorted/filtered copy internally but leave the original list in
> place. BTW what would happen if I pushed an immutable-list into it, it
> would fail on sorting right?
On the other hand, maintaining an internal data model inside the table view means that we must expose API allowing you to map from selected indexes to "natural" indexes, and vice versa. And not just selection but any API associated with indexes now needs to be defined in terms of view / model and conversions, AND every single use of these APIs in every single application has to take into account that the model / view indexes might not be the same (and I can guarantee that a sizable number of applications will get this wrong).
That's the basic problem with handling the mapping within the control. There will be many applications which don't care whether their original list is sorted, and for the others you can wrap the list in an intermediate sorted / filtered wrapper (which then has all the API on it for mapping from source -> destination indexes and back again). This seems much cleaner to me. From a theoretical perspective you have to decide whether model data is what is set on a control, or view-model data is what is set on the control. We decided on view-model data (which sometimes maps directly to model data, and sometimes doesn't).
Richard
More information about the openjfx-dev
mailing list