Class AbstractLazyDataView<T>

    • Constructor Detail

      • AbstractLazyDataView

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

      • getDataCommunicator

        protected DataCommunicator<T> getDataCommunicator()
        Returns the data communicator for the component and checks that the data provider is of the correct type.
        Returns:
        the data communicator
      • getItem

        public T getItem​(int index)
        Gets the item at the given index from the data available to the component. Data is filtered and sorted the same way as in the component.

        Calling this method with an index that is not currently active in the component will cause a query to the backend, so do not call this method carelessly. Use UI.beforeClientResponse(Component, SerializableConsumer) to access items that will be fetched later on.

        Specified by:
        getItem in interface DataView<T>
        Parameters:
        index - the index of the item to get
        Returns:
        item on index
        Throws:
        IndexOutOfBoundsException - requested index is outside of the filtered and sorted data set
      • getItems

        public Stream<T> getItems()
        Description copied from interface: DataView
        Get the full data available to the component. Data is filtered and sorted the same way as in the component.
        Specified by:
        getItems in interface DataView<T>
        Overrides:
        getItems in class AbstractDataView<T>
        Returns:
        filtered and sorted data set
      • setItemCountEstimate

        public void setItemCountEstimate​(int itemCountEstimate)
        Description copied from interface: LazyDataView
        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.

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

        public void setItemCountEstimateIncrease​(int itemCountEstimateIncrease)
        Description copied from interface: LazyDataView
        Sets how much the item count estimate is increased once the previous item count estimate has been reached. Use this when the user should be able to scroll down faster. The default value depends on the component.

        As an example, with an estimate of 1000 and an increase of 500, when scrolling down the item count will be: 1000, 1500, 2000, 2500... until the backend runs out of items.

        NOTE: the given increase should not be less than the setPageSize(int) set in the component, or there will be unnecessary backend requests.

        Specified by:
        setItemCountEstimateIncrease in interface LazyDataView<T>
        Parameters:
        itemCountEstimateIncrease - how much the item count estimate is increased
        See Also:
        LazyDataView.setItemCountEstimate(int)
      • setItemCountFromDataProvider

        public void setItemCountFromDataProvider()
        Description copied from interface: LazyDataView
        Switches the component to get the exact item count from the data provider's DataProvider.size(Query). Use this when it is cheap to get the exact item count and it is desired that the user sees the "full scrollbar size".
        Specified by:
        setItemCountFromDataProvider in interface LazyDataView<T>
      • setItemCountUnknown

        public void setItemCountUnknown()
        Description copied from interface: LazyDataView
        Switches the component to automatically extend the number of items as the previous end is almost reached. The component stops increasing the number of items once the backend has run out of items. Not getting the exact size of the backend upfront can improve performance with large sets of data.

        The default initial item count and how much the item count is increased depends on the component. These values can be customized with LazyDataView.setItemCountEstimate(int) and LazyDataView.setItemCountEstimateIncrease(int) when the backend has a lot of items and faster scrolling down is desired.

        Specified by:
        setItemCountUnknown in interface LazyDataView<T>