com.vaadin.data.provider.

Class HierarchicalDataCommunicator<T>

    • Constructor Detail

      • HierarchicalDataCommunicator

        public HierarchicalDataCommunicator()

        Construct a new hierarchical data communicator backed by a TreeDataProvider.

    • Method Detail

      • getState

        protected HierarchicalDataCommunicatorState getState()

        Description copied from class: AbstractClientConnector

        Returns the shared state for this connector. The shared state object is shared between the server connector and the client connector. Changes are only communicated from the server to the client and not in the other direction.

        As a side effect, marks the connector dirty so any changes done to the state will be sent to the client. Use getState(false) to avoid marking the connector as dirty.

        Overrides:

        getState in class DataCommunicator<T>

        Returns:

        The shared state for this connector. Never null.

      • fetchItemsWithRange

        public List<T> fetchItemsWithRange​(int offset,
                                           int limit)

        Description copied from class: DataCommunicator

        Fetches a list of items from the DataProvider.

        Overrides:

        fetchItemsWithRange in class DataCommunicator<T>

        Parameters:

        offset - the starting index of the range

        limit - the max number of results

        Returns:

        the list of items in given range

      • setDataProvider

        public <F> SerializableConsumer<F> setDataProvider​(HierarchicalDataProvider<T,​F> dataProvider,
                                                           F initialFilter)

        Set the current hierarchical data provider for this communicator.

        Type Parameters:

        F - the filter type

        Parameters:

        dataProvider - the data provider to set, not null

        initialFilter - the initial filter value to use, or null to not use any initial filter value

        Returns:

        a consumer that accepts a new filter value to use

      • createHierarchyMapper

        protected <F> HierarchyMapper<T,​F> createHierarchyMapper​(HierarchicalDataProvider<T,​F> dataProvider)

        Create new HierarchyMapper for the given data provider. May be overridden in subclasses.

        Type Parameters:

        F - Query type

        Parameters:

        dataProvider - the data provider

        Returns:

        new HierarchyMapper

      • setDataProvider

        public <F> SerializableConsumer<F> setDataProvider​(DataProvider<T,​F> dataProvider,
                                                           F initialFilter)

        Set the current hierarchical data provider for this communicator.

        Overrides:

        setDataProvider in class DataCommunicator<T>

        Type Parameters:

        F - the filter type

        Parameters:

        dataProvider - the data provider to set, must extend HierarchicalDataProvider, not null

        initialFilter - the initial filter value to use, or null to not use any initial filter value

        Returns:

        a consumer that accepts a new filter value to use

      • sendDataToClient

        protected void sendDataToClient​(boolean initial)

        Description copied from class: DataCommunicator

        Send the needed data and updates to the client side.

        Overrides:

        sendDataToClient in class DataCommunicator<T>

        Parameters:

        initial - true if initial data load, false if not

      • collapse

        public void collapse​(T item)

        Collapses the given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed.

        Parameters:

        item - the item to collapse

      • collapse

        public void collapse​(T item,
                             boolean syncAndRefresh)

        Collapses the given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed. syncAndRefresh indicates whether the changes should be synchronised to the client and the data provider be notified.

        Parameters:

        item - the item to collapse

        syncAndRefresh - true if the changes should be synchronised to the client and the data provider should be notified of the changes, false otherwise.

      • collapse

        public void collapse​(T item,
                             Integer index)

        Collapses the given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed.

        Parameters:

        item - the item to collapse

        index - the index of the item

      • doCollapse

        @Deprecated
        public void doCollapse​(T item,
                               Optional<Integer> index)
        Deprecated.

        Collapses given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed. The index is provided by the client-side or calculated from a full data request.

        Parameters:

        item - the item to collapse

        index - the index of the item

      • onDropRows

        protected void onDropRows​(elemental.json.JsonArray keys)

        Description copied from class: DataCommunicator

        Triggered when rows have been dropped from the client side cache.

        Overrides:

        onDropRows in class DataCommunicator<T>

        Parameters:

        keys - the keys of the rows that have been dropped

      • expand

        public void expand​(T item)

        Expands the given item. Calling this method will have no effect if the item is already expanded or if it has no children.

        Parameters:

        item - the item to expand

      • expand

        public void expand​(T item,
                           boolean syncAndRefresh)

        Expands the given item. Calling this method will have no effect if the item is already expanded or if it has no children. syncAndRefresh indicates whether the changes should be synchronised to the client and the data provider be notified.

        Parameters:

        item - the item to expand

        syncAndRefresh - true if the changes should be synchronised to the client and the data provider should be notified of the changes, false otherwise.

      • expand

        public void expand​(T item,
                           Integer index)

        Expands the given item at the given index. Calling this method will have no effect if the item is already expanded.

        Parameters:

        item - the item to expand

        index - the index of the item

      • doExpand

        @Deprecated
        public void doExpand​(T item,
                             Optional<Integer> index)
        Deprecated.

        Expands the given item at given index. Calling this method will have no effect if the row is already expanded. The index is provided by the client-side or calculated from a full data request.

        Parameters:

        item - the item to expand

        index - the index of the item

        See Also:

        expand(Object)

      • hasChildren

        public boolean hasChildren​(T item)

        Returns whether given item has children.

        Parameters:

        item - the item to test

        Returns:

        true if item has children; false if not

      • isExpanded

        public boolean isExpanded​(T item)

        Returns whether given item is expanded.

        Parameters:

        item - the item to test

        Returns:

        true if item is expanded; false if not

      • setItemCollapseAllowedProvider

        public void setItemCollapseAllowedProvider​(ItemCollapseAllowedProvider<T> provider)

        Sets the item collapse allowed provider for this HierarchicalDataCommunicator. The provider should return true for any item that the user can collapse.

        Note: This callback will be accessed often when sending data to the client. The callback should not do any costly operations.

        Parameters:

        provider - the item collapse allowed provider, not null

      • getParentIndex

        public Integer getParentIndex​(T item)

        Returns parent index for the row or a negative value.

        Parameters:

        item - the item to find the parent of

        Returns:

        the parent index or a negative value for top-level items

      • getItemCollapseAllowedProvider

        public ItemCollapseAllowedProvider<T> getItemCollapseAllowedProvider()

        Gets the item collapse allowed provider.

        Returns:

        the item collapse allowed provider

      • getDataProviderSize

        public int getDataProviderSize()

        Description copied from class: DataCommunicator

        Getter method for finding the size of DataProvider. Can be overridden by a subclass that uses a specific type of DataProvider and/or query.

        Overrides:

        getDataProviderSize in class DataCommunicator<T>

        Returns:

        the size of data provider with current filter

      • setBackEndSorting

        public void setBackEndSorting​(List<QuerySortOrder> sortOrder,
                                      boolean immediateReset)

        Description copied from class: DataCommunicator

        Sets the QuerySortOrders to use with backend sorting.

        Overrides:

        setBackEndSorting in class DataCommunicator<T>

        Parameters:

        sortOrder - list of sort order information to pass to a query

        immediateReset - true if an internal reset should be performed immediately after updating the comparator (unless full reset is already pending), false if you are going to trigger reset separately later

      • setInMemorySorting

        public void setInMemorySorting​(Comparator<T> comparator,
                                       boolean immediateReset)

        Description copied from class: DataCommunicator

        Sets the Comparator to use with in-memory sorting.

        Overrides:

        setInMemorySorting in class DataCommunicator<T>

        Parameters:

        comparator - comparator used to sort data

        immediateReset - true if an internal reset should be performed immediately after updating the comparator (unless full reset is already pending), false if you are going to trigger reset separately later

      • getHierarchyMapper

        protected HierarchyMapper<T,​?> getHierarchyMapper()

        Returns the HierarchyMapper used by this data communicator.

        Returns:

        the hierarchy mapper used by this data communicator