Knut Arne Vedaa
knut.arne.vedaa at broadpark.no
Thu Jan 3 11:39:49 PST 2013
> In theory this is true, but there are always edge cases. What should
> happen when a user clicks on a TableColumn header and wants to modify
> the sort order - do we modify the sorted lists comparator or not? If we
> do, how do we return to the original state of a sorted list (we'd have
> to store the comparator and reapply it - but only if the list is a
> sorted list). If we do need to special case for a sorted list, how do we
> know that we've got a sorted list?
> This is another reason why TableView needs to know what kind of list it
> is dealing with - wrapping a SortedList (provided by the user) in
> another SortedList is redundant, and again the edge cases rear their
I'd say: don't special case, don't treat the items list as anything else
than an ObservableList, don't try to know what you're dealing with,
don't guess with the API user wants. If they provide a SortedList and
you wrap it with a new SortedList there will be redundancy - but that's
the user's responsibility. You provide the API, the user may use it or
abuse as they wish.
Let's look at a use case:
Say you (as API user) have three TableViews beside each other. They are
all backed by the same list, which happens to be a SortedList (for
reasons unknown). You want to view them as independently sorted. If now
the TableView says "aha! we already have a sorted list, so we can just
use that for sorting!", obviously all views will be effected by the
sorting, which is not what you want.
The main problem is, of course, that the current behaviour is
sort-in-place, i.e. mutation of the backing list. I think it's
unavoidable to change this behaviour, and I also think that is actually
a good thing, since with the current behaviour you are having a "view"
mutating the user's data without the API user explicitly asking for it.
If you actually *want* the TableView to be able to be a "sorter-of-data"
and not just a "displayer-of-data" (optionally sorted), you could have a
getSortedList() method that returns a reference to the internally sorted
Knut Arne Vedaa
More information about the openjfx-dev