Class ComboBoxDataView<T>

  • Type Parameters:
    T - the item type
    All Implemented Interfaces:
    DataView<T>, Serializable

    public class ComboBoxDataView<T>
    extends AbstractDataView<T>
    Implementation of generic data view for ComboBox. This implementation does not depend on a certain type of data provider, i.e. whether is it of in-memory or backend type. It can be used if the type of data provider is not either ListDataProvider or BackEndDataProvider.
    Since:
    See Also:
    Serialized Form
    • Constructor Detail

      • ComboBoxDataView

        public ComboBoxDataView​(DataCommunicator<T> dataCommunicator,
                                ComboBox<T> comboBox)
        Creates a new generic 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
        comboBox - the ComboBox
    • Method Detail

      • 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.

        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-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:
        getItems in interface DataView<T>
        Overrides:
        getItems in class AbstractDataView<T>
        Returns:
        items available on the server-side
      • setIdentifierProvider

        public void setIdentifierProvider​(IdentifierProvider<T> identifierProvider)
        Description copied from interface: DataView
        Sets an identifier provider, which returns an identifier for the given item. The identifier is used for comparing the equality of items. Usage example: dataView.setIdentifiedProvider(Item::getId);.
        Specified by:
        setIdentifierProvider in interface DataView<T>
        Overrides:
        setIdentifierProvider in class AbstractDataView<T>
        Parameters:
        identifierProvider - function that returns the non-null identifier for a given item
      • 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 adding or removing an item(s).

        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