Class ComboBoxListDataView<T>

  • Type Parameters:
    T - the type of the items in ComboBox
    All Implemented Interfaces:
    com.vaadin.flow.data.provider.DataView<T>, com.vaadin.flow.data.provider.ListDataView<T,​com.vaadin.flow.data.provider.AbstractListDataView<T>>, Serializable

    public class ComboBoxListDataView<T>
    extends com.vaadin.flow.data.provider.AbstractListDataView<T>
    Data view implementation for ComboBox with in-memory list data. Provides information on the data and allows operations on it.
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class com.vaadin.flow.data.provider.AbstractDataView

        component, dataProviderSupplier, NULL_IDENTIFIER_ERROR_MESSAGE
    • Constructor Summary

      Constructors 
      Constructor Description
      ComboBoxListDataView​(com.vaadin.flow.data.provider.DataCommunicator<T> dataCommunicator, ComboBoxBase<?,​T,​?> comboBox, com.vaadin.flow.function.SerializableBiConsumer<com.vaadin.flow.function.SerializablePredicate<T>,​com.vaadin.flow.function.SerializableComparator<T>> filterOrSortingChangedCallback)
      Creates a new instance of ComboBox in-memory data view and verifies the passed data provider is compatible with this data view implementation.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ComboBoxListDataView<T> addFilter​(com.vaadin.flow.function.SerializablePredicate<T> filter)
      Adds a filter to be applied to all queries.
      com.vaadin.flow.shared.Registration addItemCountChangeListener​(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.data.provider.ItemCountChangeEvent<?>> listener)
      int getItemCount()
      Stream<T> getItems()
      Gets the items available on the ComboBox's server-side.
      ComboBoxListDataView<T> removeFilters()
      Removes all in-memory filters set or added.
      ComboBoxListDataView<T> setFilter​(com.vaadin.flow.function.SerializablePredicate<T> filter)
      Sets a filter to be applied to the data.
      void setIdentifierProvider​(com.vaadin.flow.data.provider.IdentifierProvider<T> identifierProvider)  
      • Methods inherited from class com.vaadin.flow.data.provider.AbstractListDataView

        addItem, addItemAfter, addItemBefore, addItems, addItemsAfter, addItemsBefore, addSortComparator, addSortOrder, contains, getDataProvider, getItem, getNextItem, getPreviousItem, getSupportedDataProviderType, removeItem, removeItems, removeSorting, setSortComparator, setSortOrder, validateItemIndex
      • Methods inherited from class com.vaadin.flow.data.provider.AbstractDataView

        addIdentifierProviderChangeListener, equals, getIdentifierProvider, refreshAll, refreshItem, verifyDataProviderType
      • Methods inherited from interface com.vaadin.flow.data.provider.DataView

        refreshAll, refreshItem
    • Constructor Detail

      • ComboBoxListDataView

        public ComboBoxListDataView​(com.vaadin.flow.data.provider.DataCommunicator<T> dataCommunicator,
                                    ComboBoxBase<?,​T,​?> comboBox,
                                    com.vaadin.flow.function.SerializableBiConsumer<com.vaadin.flow.function.SerializablePredicate<T>,​com.vaadin.flow.function.SerializableComparator<T>> filterOrSortingChangedCallback)
        Creates a new instance of ComboBox in-memory data view and verifies the passed data provider is compatible with this data view implementation.
        Parameters:
        dataCommunicator - the data communicator of the ComboBox, not null
        comboBox - the ComboBox component, not null
        filterOrSortingChangedCallback - callback, which is being invoked when the ComboBox's filtering or sorting changes, not null
    • Method Detail

      • getItems

        public Stream<T> getItems()
        Gets the items available on the ComboBox's server-side.

        Data is sorted the same way as in the ComboBox, but it does not take into account the ComboBox client-side filtering, since it doesn't change the item count on the server-side, but only makes it easier for users to search through the items in the UI. Only the server-side filtering considered, which is set by: setFilter(SerializablePredicate) or addFilter(SerializablePredicate).

        Specified by:
        getItems in interface com.vaadin.flow.data.provider.DataView<T>
        Overrides:
        getItems in class com.vaadin.flow.data.provider.AbstractListDataView<T>
        Returns:
        filtered and sorted items available in server-side
      • getItemCount

        public int getItemCount()

        This method takes into account only the server-side filtering, which is set by: setFilter(SerializablePredicate) or addFilter(SerializablePredicate). ComboBox's client-side filter is not considered, since it doesn't change the item count on the server-side, but only makes it easier for users to search through the items in the UI.

        Specified by:
        getItemCount in interface com.vaadin.flow.data.provider.ListDataView<T,​com.vaadin.flow.data.provider.AbstractListDataView<T>>
        Overrides:
        getItemCount in class com.vaadin.flow.data.provider.AbstractListDataView<T>
        Returns:
        filtered item count
      • setIdentifierProvider

        public void setIdentifierProvider​(com.vaadin.flow.data.provider.IdentifierProvider<T> identifierProvider)
        Specified by:
        setIdentifierProvider in interface com.vaadin.flow.data.provider.DataView<T>
        Overrides:
        setIdentifierProvider in class com.vaadin.flow.data.provider.AbstractDataView<T>
      • addItemCountChangeListener

        public com.vaadin.flow.shared.Registration addItemCountChangeListener​(com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.data.provider.ItemCountChangeEvent<?>> listener)

        Combo box fires ItemCountChangeEvent and notifies all the listeners added by this method, if the items count changed due to adding or removing an item(s), or by changing the server-side filtering with setFilter(SerializablePredicate) or addFilter(SerializablePredicate).

        ComboBox's client-side filter change won't fire ItemCountChangeEvent, since it doesn't change the item count on the server-side, but only makes it easier for users to search through the items in the UI.

        Specified by:
        addItemCountChangeListener in interface com.vaadin.flow.data.provider.DataView<T>
        Overrides:
        addItemCountChangeListener in class com.vaadin.flow.data.provider.AbstractDataView<T>
      • addFilter

        public ComboBoxListDataView<T> addFilter​(com.vaadin.flow.function.SerializablePredicate<T> filter)
        Adds a filter to be applied to all queries. The filter will be used in addition to any filter that has been set or added previously through setFilter(com.vaadin.flow.function.SerializablePredicate<T>) or addFilter(com.vaadin.flow.function.SerializablePredicate<T>). This filter is applied to data set permanently until it's changed through setFilter(com.vaadin.flow.function.SerializablePredicate<T>) or removeFilters(), in contrary with the client-side filter that can be typed in by user and does not modify the data set on server-side, but only defines which items are shown for a single request and erases on drop down close.

        This filter is bound to the component. Thus, any other component using the same DataProvider object would not be affected by setting a filter through data view of another component. A filter set by this method won't be retained when a new DataProvider is set to the component.

        Specified by:
        addFilter in interface com.vaadin.flow.data.provider.ListDataView<T,​com.vaadin.flow.data.provider.AbstractListDataView<T>>
        Overrides:
        addFilter in class com.vaadin.flow.data.provider.AbstractListDataView<T>
        Parameters:
        filter - the filter to add, not null
        Returns:
        ComboBoxListDataView instance
        See Also:
        setFilter(SerializablePredicate), removeFilters()
      • removeFilters

        public ComboBoxListDataView<T> removeFilters()
        Removes all in-memory filters set or added.
        Specified by:
        removeFilters in interface com.vaadin.flow.data.provider.ListDataView<T,​com.vaadin.flow.data.provider.AbstractListDataView<T>>
        Overrides:
        removeFilters in class com.vaadin.flow.data.provider.AbstractListDataView<T>
        Returns:
        ComboBoxListDataView instance
        See Also:
        addFilter(SerializablePredicate), setFilter(SerializablePredicate)
      • setFilter

        public ComboBoxListDataView<T> setFilter​(com.vaadin.flow.function.SerializablePredicate<T> filter)
        Sets a filter to be applied to the data. The filter replaces any filter that has been set or added previously. null will clear all filters. This filter is applied to data set permanently until it's changed through setFilter(com.vaadin.flow.function.SerializablePredicate<T>) or removeFilters(), in contrary with the client-side filter that can be typed in by user and does not modify the data set on server-side, but only defines which items are shown for a single request and erases on drop down close.

        This filter is bound to the component. Thus, any other component using the same DataProvider object would not be affected by setting a filter through data view of another component. A filter set by this method won't be retained when a new DataProvider is set to the component.

        Specified by:
        setFilter in interface com.vaadin.flow.data.provider.ListDataView<T,​com.vaadin.flow.data.provider.AbstractListDataView<T>>
        Overrides:
        setFilter in class com.vaadin.flow.data.provider.AbstractListDataView<T>
        Parameters:
        filter - filter to be set, or null to clear any previously set filters
        Returns:
        ComboBoxListDataView instance
        See Also:
        addFilter(SerializablePredicate), removeFilters()