FilteredList/SortedList
Jonathan Giles
jonathan.giles at oracle.com
Wed Jan 2 10:56:17 PST 2013
Hi Martin,
These lists have always been driven by the requirements of TableView,
but I'm having a hard time understanding how the newly proposed API will
fit in (and what will be required of me and / or end users of the
TableView control). It would be great if you could show some examples of
how a developer would instantiate a TableView that is:
1) always in a sorted state
2) able to filtered based on a user typing
3) is always sorted and able to be filtered based on user input
I'm also particularly interested in knowing how sorting would change.
Presently the code simply runs a comparator over the ObservableList,
modifying the list in place. This is ok, but not ideal as it loses the
original sort order which means it is not possible to go back to an
unsorted state. I'm going to presume I would want to add special-case
support in TableView so that, where possible, I can return the user back
to an unsorted state by grabbing the original source from the
transformation list. The alternative is for me to maintain a SortedList
internally so that the original ObservableList is not modified, but then
that is troublesome as it changes the behavior of the API. Any thoughts
here would be much appreciated.
Thanks,
-- Jonathan
On 3/01/2013 4:58 a.m., Martin Sladecek wrote:
> Hello,
>
> I would like to start discussion about a new API for ObservableLists
> that are filtered/sorted. This API was already in the repository
> before 2.0 was released, but was withdrawn (
> http://javafx-jira.kenai.com/browse/RT-15302).
> In the original API, there were 3 new classes: FilteredList,
> SortedList and TransformationList (parent of the previous two). These
> 2 lists took a different (Observable)List, acting as a view for that
> list, firing change notifications when the view changed.
>
> Since we have a different situation now, due to new (overlapping)
> features in JDK 8, I'd like to propose a different API for
> FilteredList and SortedList.
>
> First of all, I don't think we need separate FilteredList and
> SortedList classes anymore. With defender methods, we can have a
> similar approach to JDK's stream(), having e.g. transform() method on
> ObservableList, that would allow filtering & sorting of the list.
> The original API allowed "batch" mode, but this is now basically
> covered with List's stream(), although it's more cumbersome as you
> won't get a List directly of a Stream, not to mention ObservableList,
> which is what you need to pass as a model to various controls, like
> TableView.
> Still, I'm not in favour of having this also in FX, but maybe
> something like Iterable to ObservableList conversion method would ease
> the FX development when using JDK 8 steams...
>
> I want to keep TransformationList to serve both as a common parent for
> all current and future "transformation" lists, but also returning
> TransformationList on transform() call, having methods like filtered()
> and sorted() directly on the TransformationList.
>
> So overall, the new API would look like this:
>
> public abstract class TransformationList<E, F> implements
> ObservableList<E> {
>
> protected TransformationList(ObservableList<? extends F> source);
>
> public final ObservableList<? extends F> getDirectSource();
>
> // The first non-transformation list in the chain.
> public final ObservableList<?> getOriginalSource();
>
> // Called when a change from the source is triggered.
> protected abstract void onSourceChanged(Change<? extends F> c);
>
> // Maps the index of this list's element to an index in the direct
> source list.
> public abstract int getSourceIndex(int index);
>
> public final int getOriginalSourceIndex(int index);
>
> public final TransformationList<E, E> filtered(Predicate<? super
> E> predicate);
>
> public final TransformationList<E, E> sorted(Comparator<? super E>
> comparator);
>
> }
>
> ObservableList<E> interface would get a new defender method:
>
> public TransformationList<E, E> transform();
>
> this would return TransformationList representation of the current list.
>
> Another appoach would be to have filtered(), sorted() directly on
> ObservableList as a defender methods, which would remove the necessity
> of calling transform() before filtered()/sorted(), but I find the
> first one more consistent with JDK API.
>
> Any comments?
>
> Thanks,
> -Martin
>
More information about the openjfx-dev
mailing list