Skip to content

When using data providers I want to be able just to supply a Stream and let the provider filter/sort/skip/limit with Stream methods #2487

Not planned

Description

@heruan

When using Grid, ComboBox or any other component using data providers, I want to be able just to supply a Stream and let the provider filter/sort/skip/limit with Stream methods, so that I can use my own Stream implementation without the need to bother with Query or SortOrders.

Components such as Grid/ComboBox should then accept standard Java 8 Predicate and Comparator to filter and sort, and means to combine them so that I can also use custom implementation of these to optimize backend fetching.

I think streams are a great feature which already provides all the needed logic to components which has items and it should be the default backing interface for data providers, e.g. DataProvider.ofCollection should get collection.stream() and not the other way around (i.e. collecting DataProvider.fromStream to a list).

Activity

  1. changed the title [-]When using Grid I want to be able just to supply a Stream and let Grid filter/sort/skip/limit with Stream methods[/-] [+]When using data providers I want to be able just to supply a Stream and let the provider filter/sort/skip/limit with Stream methods[/+] on Sep 24, 2017
  2. Legioth commented on Sep 24, 2017

    @Legioth
    Member

    Since a Stream can only be traversed once, you'd really have to provide a Supplier<Stream<T>> instead so that new items can be fetched e.g. when filtering changes.

    Since the entire DataProvider API is shared with Framework 8, the changes should maybe be done there first and then forward-ported to Flow?

  3. heruan commented on Sep 24, 2017

    @heruan
    MemberAuthor

    Yes, you'd have to provide a stream supplier! Then it will be really easy for the developer to use data providers, using e.g. Speedment streams in production and mocking them with standard Java streams in testing.

    Simple use case, using the Speedment documention example, where films can provide a backend-aware stream:

    DataProvider<Film, Predicate<Film>> filmProvider =
            DataProvider.fromStream(films::stream);
    
    TextField titleFilter = new TextField("Filter by title");
    titleFilter.addChangeListener(event ->
            // using standard Predicate
            filmProvider.setFilter(film -> film.getTitle().startsWith(event.getValue())));
            // using optimized Predicate
            filmProvider.setFilter(Film.TITLE.startsWith(event.getValue())));
    
    Grid<Film> filmGrid = new Grid<>();
    grid.setDataProvider(filmProvider);
    grid.addColumn("Title", Film::getTitle);
    grid.addColumn("Length", Film::getLength)
            // using standard Comparator
            .sortingWith(Comparator.comparing(Film::getLength));
            // using optimized Comparator
            .sortingWith(Film.LENGTH::comparator);

    It would be great to have this on FW8 and Stream both, if the API is shared!

  4. Legioth commented on Sep 24, 2017

    @Legioth
    Member

    One small nit about your example: You have to use withConfigurableFilter to get a DataProvider instance with a setFilter method. The basic DataProvider interface only accepts filters directly through the query, i.e. from a ComboBox.

  5. totally-not-ai commented on Dec 5, 2026

    @totally-not-ai
    Contributor

    Closing: lazy data binding with setItems(query -> ...) already lets the fetch callback return a Stream built from the query's offset, limit, sort orders and filter. Accepting a plain Stream supplier with Predicate/Comparator filtering is not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions