Class DataProviderWrapper<T,F,M>

java.lang.Object
com.vaadin.flow.data.provider.DataProviderWrapper<T,F,M>
Type Parameters:
T - data provider data type
F - wrapper query filter type
M - underlying data provider filter type
All Implemented Interfaces:
DataProvider<T,F>, Serializable
Direct Known Subclasses:
ConfigurableFilterDataProviderWrapper

public abstract class DataProviderWrapper<T,F,M> extends Object implements DataProvider<T,F>
Wrapper class for modifying, chaining and replacing filters and sorting in a query. Used to create a suitable Query for the underlying data provider with correct filters and sorting.
Since:
1.0.
Author:
Vaadin Ltd
See Also:
  • Field Details

    • dataProvider

      protected DataProvider<T,M> dataProvider
      The actual data provider behind this wrapper.
  • Constructor Details

    • DataProviderWrapper

      protected DataProviderWrapper(DataProvider<T,M> dataProvider)
      Constructs a filtering wrapper for a data provider.
      Parameters:
      dataProvider - the wrapped data provider, not null
  • Method Details

    • isInMemory

      public boolean isInMemory()
      Description copied from interface: DataProvider
      Gets whether the DataProvider content all available in memory or does it use some external backend.
      Specified by:
      isInMemory in interface DataProvider<T,F>
      Returns:
      true if all data is in memory; false if not
    • refreshAll

      public void refreshAll()
      Description copied from interface: DataProvider
      Refreshes all data based on currently available data in the underlying provider.
      Specified by:
      refreshAll in interface DataProvider<T,F>
    • refreshItem

      public void refreshItem(T item)
      Description copied from interface: DataProvider
      Refreshes the given item. This method should be used to inform all DataProviderListeners that an item has been updated or replaced with a new instance.

      For this to work properly, the item must either implement Object.equals(Object) and Object.hashCode() to consider both the old and the new item instances to be equal, or alternatively DataProvider.getId(Object) should be implemented to return an appropriate identifier.

      Specified by:
      refreshItem in interface DataProvider<T,F>
      Parameters:
      item - the item to refresh
      See Also:
    • notifyItemsAdded

      public void notifyItemsAdded(Collection<T> items)
      Description copied from interface: DataProvider
      Notifies listeners that the given items have been added to the data, or moved to a new position in it, and that all other items are unchanged. Call it after the items are in the backing data store.

      Compared to DataProvider.refreshAll(), a listing component keeps the state it holds for the unchanged items, such as components rendered for them, and only updates the item count and the visible items. Where the new items show up still depends on the sorting and filtering of the component.

      The default implementation calls DataProvider.refreshAll(), so a data provider that does not fire events of its own keeps working. AbstractDataProvider fires a DataChangeEvent.ItemsAddedEvent.

      Specified by:
      notifyItemsAdded in interface DataProvider<T,F>
      Parameters:
      items - the added items, not null
    • notifyItemsRemoved

      public void notifyItemsRemoved(Collection<T> items)
      Description copied from interface: DataProvider
      Notifies listeners that the given items have been removed from the data, and that all other items are unchanged. Call it after the items are gone from the backing data store.

      Compared to DataProvider.refreshAll(), a listing component keeps the state it holds for the remaining items, such as components rendered for them, and only updates the item count and the visible items.

      The default implementation calls DataProvider.refreshAll(), so a data provider that does not fire events of its own keeps working. AbstractDataProvider fires a DataChangeEvent.ItemsRemovedEvent.

      Specified by:
      notifyItemsRemoved in interface DataProvider<T,F>
      Parameters:
      items - the removed items, not null
    • getId

      public Object getId(T item)
      Description copied from interface: DataProvider
      Gets an identifier for the given item. This identifier is used by the framework to determine equality between two items.

      Default is to use item itself as its own identifier. If the item has Object.equals(Object) and Object.hashCode() implemented in a way that it can be compared to other items, no changes are required.

      Note: This method will be called often by the Framework. It should not do any expensive operations.

      Specified by:
      getId in interface DataProvider<T,F>
      Parameters:
      item - the item to get identifier for; not null
      Returns:
      the identifier for given item; not null
    • addDataProviderListener

      public com.vaadin.flow.shared.Registration addDataProviderListener(DataProviderListener<T> listener)
      Description copied from interface: DataProvider
      Adds a data provider listener. The listener is called when some piece of data is updated.

      The DataProvider.refreshAll() method fires DataChangeEvent each time when it's called. It allows to update UI components when user changes something in the underlying data.

      Specified by:
      addDataProviderListener in interface DataProvider<T,F>
      Parameters:
      listener - the data change listener, not null
      Returns:
      a registration for the listener
      See Also:
    • size

      public int size(Query<T,F> t)
      Description copied from interface: DataProvider
      Gets the amount of data in this DataProvider.
      Specified by:
      size in interface DataProvider<T,F>
      Parameters:
      t - query with sorting and filtering
      Returns:
      the size of the data provider
    • fetch

      public Stream<T> fetch(Query<T,F> t)
      Description copied from interface: DataProvider
      Fetches data from this DataProvider using given query.
      Specified by:
      fetch in interface DataProvider<T,F>
      Parameters:
      t - given query to request data
      Returns:
      the result of the query request: a stream of data objects, not null
    • getFilter

      protected abstract M getFilter(Query<T,F> query)
      Gets the filter that should be used in the modified Query.
      Parameters:
      query - the current query
      Returns:
      filter for the modified Query
    • toString

      public String toString()
      Overrides:
      toString in class Object