Class AbstractDataProvider<T,F>

java.lang.Object
com.vaadin.flow.data.provider.AbstractDataProvider<T,F>
Type Parameters:
T - data type
F - filter type
All Implemented Interfaces:
DataProvider<T,F>, Serializable
Direct Known Subclasses:
AbstractBackEndDataProvider, AbstractHierarchicalDataProvider, ListDataProvider

public abstract class AbstractDataProvider<T,F> extends Object implements DataProvider<T,F>
Abstract data provider implementation which takes care of refreshing data from the underlying data provider.
Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • AbstractDataProvider

      public AbstractDataProvider()
  • Method Details

    • 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:
    • 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>
    • 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
    • refreshItem

      public void refreshItem(T item, boolean refreshChildren)
      Description copied from interface: DataProvider
      Refreshes the given item and its children when refreshChildren is true.

      This method will reset the item's cached hierarchy which can cause a content shift if the item also contains expanded children: their descendants aren't guaranteed to be re-fetched eagerly if they aren't visible, which may affect the overall size of the rendered hierarchy, leading to content shifts.

      This method is only supported for hierarchical data providers that use HierarchicalDataProvider.HierarchyFormat.NESTED.

      Specified by:
      refreshItem in interface DataProvider<T,F>
      Parameters:
      item - the item to refresh
      refreshChildren - whether or not to refresh child items
    • 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:
    • addListener

      protected <E> com.vaadin.flow.shared.Registration addListener(Class<E> eventType, com.vaadin.flow.function.SerializableConsumer<E> method)
      Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.
      Type Parameters:
      E - the event type
      Parameters:
      eventType - the type of the listened event. Events of this type or its subclasses activate the listener.
      method - the consumer to receive the event.
      Returns:
      a registration for the listener
    • fireEvent

      protected void fireEvent(EventObject event)
      Sends the event to all listeners.
      Parameters:
      event - the Event to be sent to all listeners.