Class ComboBoxLazyDataView<T>

  • Type Parameters:
    T - the type of the items in ComboBox
    All Implemented Interfaces:
    DataView<T>, LazyDataView<T>, Serializable

    public class ComboBoxLazyDataView<T>
    extends AbstractLazyDataView<T>
    Data view implementation for ComboBox with lazy data fetching. Provides information on the data and allows operations on it.
    See Also:
    Serialized Form
    • Constructor Detail

      • ComboBoxLazyDataView

        public ComboBoxLazyDataView​(DataCommunicator<T> dataCommunicator,
                                    Component component)
        Creates a new lazy data view for ComboBox and verifies the passed data provider is compatible with this data view implementation.
        Parameters:
        dataCommunicator - the data communicator of the component
        component - the ComboBox
    • Method Detail

      • setItemCountEstimate

        public void setItemCountEstimate​(int itemCountEstimate)
        Sets the estimated item count for the component. The component will automatically fetch more items once the estimate is reached or adjust the count if the backend runs out of items before the end. Use this when the backend will have a lot more items than shown by default and it should be shown to the user.

        The given estimate is discarded if it is less than the currently shown range or if the actual number of items has been determined. The estimate shouldn't be less than two pages (see setPageSize(int) in the component) or it causes unnecessary backend requests.

        Calling this method will clear any previously set count callback setItemCountCallback(CallbackDataProvider.CountCallback).

        Specified by:
        setItemCountEstimate in interface LazyDataView<T>
        Overrides:
        setItemCountEstimate in class AbstractLazyDataView<T>
        Parameters:
        itemCountEstimate - estimated item count of the backend
        See Also:
        LazyDataView.setItemCountUnknown(), LazyDataView.setItemCountEstimateIncrease(int)
      • addItemCountChangeListener

        public Registration addItemCountChangeListener​(ComponentEventListener<ItemCountChangeEvent<?>> listener)
        Add an item count change listener that is fired when the item count changes. This can happen for instance when filtering the items.

        Item count change listener is bound to the component and will be retained even if the data changes by setting of a new items or DataProvider to component.

        NOTE: when the component supports lazy loading (implements HasLazyDataView) and a count callback has not been provided, an estimate of the item count is used and increased until the actual count has been reached. When the estimate is used, the event is fired with the ItemCountChangeEvent.isItemCountEstimated() returning true.

        Combo box fires ItemCountChangeEvent and notifies all the listeners added by this method, if the items count changed, for instance, due to fetching more items while scrolling with unknown item count.

        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 DataView<T>
        Overrides:
        addItemCountChangeListener in class AbstractDataView<T>
        Parameters:
        listener - item count change listener to register
        Returns:
        registration for removing the listener
      • getItem

        public T getItem​(int index)
        Gets the item at the given index from the data available in the ComboBox's server-side.

        This method 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.

        Specified by:
        getItem in interface DataView<T>
        Overrides:
        getItem in class AbstractLazyDataView<T>
        Parameters:
        index - item index number
        Returns:
        item on index
        Throws:
        IndexOutOfBoundsException - requested index is outside of the data set
      • getItems

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

        This method does not take into account the ComboBox client-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.

        Specified by:
        getItems in interface DataView<T>
        Overrides:
        getItems in class AbstractLazyDataView<T>
        Returns:
        items available on the server-side