Class HierarchicalDataCommunicator<T>

java.lang.Object
com.vaadin.flow.data.provider.DataCommunicator<T>
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicator<T>
Type Parameters:
T - the bean type
All Implemented Interfaces:
Serializable

public class HierarchicalDataCommunicator<T> extends DataCommunicator<T>
Data communicator that handles requesting hierarchical data from HierarchicalDataProvider and sending it to client side.
Since:
1.2
Author:
Vaadin Ltd
See Also:
  • Constructor Details

  • Method Details

    • reset

      public void reset()
      Resets all the data.

      It effectively resends all available data.

      Overrides:
      reset in class DataCommunicator<T>
    • handleDataRefreshEvent

      protected void handleDataRefreshEvent(DataChangeEvent.DataRefreshEvent<T> event)
      Overrides:
      handleDataRefreshEvent in class DataCommunicator<T>
    • fetchFromProvider

      public Stream<T> fetchFromProvider(int offset, int limit)
      Description copied from class: DataCommunicator
      Fetches a list of items from the DataProvider.

      NOTE: the limit parameter shows how many items the client wants to fetch, but the actual number of results may be greater, and vary from 0 to pages * pageSize.

      Overrides:
      fetchFromProvider in class DataCommunicator<T>
      Parameters:
      offset - the starting index of the range
      limit - the desired number of results
      Returns:
      the list of items in given range
    • setParentRequestedRange

      @Deprecated(since="24.9", forRemoval=true) public void setParentRequestedRange(int start, int length, T parentItem)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25 where HierarchicalDataCommunicator will be refactored to handle hierarchy management entirely on the server side and DataCommunicator.setViewportRange(int, int) will be the method responsible for managing the entire viewport range.
    • getDataProvider

      public HierarchicalDataProvider<T,?> getDataProvider()
      Description copied from class: DataCommunicator
      Gets the current data provider from this DataCommunicator.
      Overrides:
      getDataProvider in class DataCommunicator<T>
      Returns:
      the data provider
    • 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

      @Deprecated(since="24.9", forRemoval=true) protected <F> HierarchyMapper<T,F> createHierarchyMapper(HierarchicalDataProvider<T,F> dataProvider)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25 where HierarchicalDataCommunicator will be refactored to handle hierarchy management entirely on the server side, requiring data to be stored in a different cache structure.
      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
    • confirmUpdate

      @Deprecated(since="24.9", forRemoval=true) public void confirmUpdate(int id, String parentKey)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25 where HierarchicalDataCommunicator will be refactored to handle hierarchy management entirely on the server side and DataCommunicator.confirmUpdate(int) will be the only method called for confirming updates.
    • 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.

      Changes are synchronized to the client.

      Parameters:
      item - the item to collapse
    • collapse

      @Deprecated(since="24.9", forRemoval=true) protected void collapse(T item, boolean syncClient)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25. Use collapse(T) instead.
      Collapses the given item and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed. syncClient indicates whether the changes should be synchronized to the client.
      Parameters:
      item - the item to collapse
      syncClient - true if the changes should be synchronized to the client, false otherwise.
    • collapse

      public Collection<T> collapse(Collection<T> items)
      Collapses the given items and removes its sub-hierarchy. Calling this method will have no effect if the row is already collapsed.

      Changes are synchronized to the client.

      Parameters:
      items - the items to collapse
      Returns:
      the collapsed items
    • 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.

      Changes are synchronized to the client.

      Parameters:
      item - the item to expand
    • expand

      public Collection<T> expand(Collection<T> items)
      Expands the given items. Calling this method will have no effect if the item is already expanded or if it has no children.

      Changes are synchronized to the client.

      Parameters:
      items - the items to expand
      Returns:
      the expanded items
    • expand

      @Deprecated(since="24.9", forRemoval=true) protected void expand(T item, boolean syncClient)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25. Use expand(T) instead.
      Expands the given item. Calling this method will have no effect if the item is already expanded or if it has no children. syncClient indicates whether the changes should be synchronized to the client.
      Parameters:
      item - the item to expand
      syncClient - true if the changes should be synchronized to the client, false otherwise.
    • 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
    • getParentIndex

      @Deprecated(since="24.9", forRemoval=true) public Integer getParentIndex(T item)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25. Use direct queries to the data source instead.
      Returns parent index for the row or null.
      Parameters:
      item - the item to find the parent of
      Returns:
      the parent index or null for top-level items
    • getIndex

      @Deprecated(since="24.9", forRemoval=true) public Integer getIndex(T item)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25. Use direct queries to the data source instead.
      Returns index for the row or null.
      Parameters:
      item - the target item
      Returns:
      the index or null for top-level and non-existing items
    • getParentItem

      @Deprecated(since="24.9", forRemoval=true) public T getParentItem(T item)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25. Use direct queries to the data source instead.
      Returns parent item for the row or null.
      Parameters:
      item - the item to find the parent of
      Returns:
      the parent item or null for top-level items
    • getDepth

      public int getDepth(T item)
      Returns depth of item in the tree starting from zero representing a root.
      Parameters:
      item - Target item
      Returns:
      depth of item in the tree or -1 if item is null
    • getDataProviderSize

      public int getDataProviderSize()
      Description copied from class: DataCommunicator
      Getter method for determining the item count of the data.

      This method should be used only with defined size, i.e. when DataCommunicator.isDefinedSize() returns true.

      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)
      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
    • setInMemorySorting

      public void setInMemorySorting(SerializableComparator<T> comparator)
      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
    • setFilter

      @Deprecated(since="24.9", forRemoval=true) protected <F> void setFilter(F filter)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25. To control the filter from HierarchicalDataCommunicator, override setDataProvider(HierarchicalDataProvider, Object) and store the returned filter consumer.
    • hasExpandedItems

      public boolean hasExpandedItems()
      Returns true if there is any expanded items.
      Returns:
      true if there is any expanded items.
    • getHierarchyMapper

      @Deprecated(since="24.9", forRemoval=true) protected HierarchyMapper<T,?> getHierarchyMapper()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will be removed in Vaadin 25 where HierarchicalDataCommunicator will be refactored to handle hierarchy management entirely on the server side, requiring data to be stored in a different cache structure.
      Returns the HierarchyMapper used by this data communicator.
      Returns:
      the hierarchy mapper used by this data communicator
    • getPassivatedKeys

      @Deprecated(since="24.9", forRemoval=true) protected Set<String> getPassivatedKeys(Set<String> oldActive)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will no longer be called in Vaadin 25 where HierarchicalDataCommunicator will be refactored to handle hierarchy management entirely on the server side.
      Overrides:
      getPassivatedKeys in class DataCommunicator<T>
    • doUnregister

      @Deprecated(since="24.9", forRemoval=true) protected void doUnregister(Integer updateId)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 24.9 and will no longer be called in Vaadin 25 where HierarchicalDataCommunicator will be refactored to handle hierarchy management entirely on the server side.
      Overrides:
      doUnregister in class DataCommunicator<T>
    • setItemCountEstimate

      public void setItemCountEstimate(int itemCountEstimate)
      Estimates are not supported in HierarchicalDataCommunicator
      Overrides:
      setItemCountEstimate in class DataCommunicator<T>
      Parameters:
      itemCountEstimate - the item count estimate to be used
    • getItemCountEstimate

      public int getItemCountEstimate()
      Estimates are not supported in HierarchicalDataCommunicator
      Overrides:
      getItemCountEstimate in class DataCommunicator<T>
      Returns:
      the item count estimate used
    • setItemCountEstimateIncrease

      public void setItemCountEstimateIncrease(int itemCountEstimateIncrease)
      Estimates are not supported in HierarchicalDataCommunicator
      Overrides:
      setItemCountEstimateIncrease in class DataCommunicator<T>
      Parameters:
      itemCountEstimateIncrease - the item count estimate step to use
    • getItemCountEstimateIncrease

      public int getItemCountEstimateIncrease()
      Estimates are not supported in HierarchicalDataCommunicator
      Overrides:
      getItemCountEstimateIncrease in class DataCommunicator<T>
      Returns:
      the item count estimate increase
    • setDefinedSize

      public void setDefinedSize(boolean definedSize)
      Estimates are not supported in HierarchicalDataCommunicator
      Overrides:
      setDefinedSize in class DataCommunicator<T>
      Parameters:
      definedSize - true for defined size, false for undefined size
    • isDefinedSize

      public boolean isDefinedSize()
      Estimates are not supported in HierarchicalDataCommunicator. Therefore this method will always return true
      Overrides:
      isDefinedSize in class DataCommunicator<T>
      Returns:
      true for defined size, false for undefined size