Class HierarchyMapper<T,F>

java.lang.Object
com.vaadin.flow.data.provider.hierarchy.HierarchyMapper<T,F>
Type Parameters:
T - the data type
F - the filter type
All Implemented Interfaces:
Serializable

public class HierarchyMapper<T,F> extends Object implements Serializable
Mapper for hierarchical data.

Keeps track of the expanded nodes, and size of of the subtrees for each expanded node.

This class is framework internal implementation details, and can be changed / moved at any point. This means that you should not directly use this for anything.

Since:
1.2
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • HierarchyMapper

      public HierarchyMapper(HierarchicalDataProvider<T,F> provider)
      Constructs a new HierarchyMapper.
      Parameters:
      provider - the hierarchical data provider for this mapper
  • Method Details

    • getTreeSize

      public int getTreeSize()
      Returns the size of the currently expanded hierarchy.
      Returns:
      the amount of available data
    • getRootSize

      public int getRootSize()
      Returns the size of root level.
      Returns:
      the amount of available root data
    • getParentIndex

      public Integer getParentIndex(T item)
      Finds the index of the parent of the item in given target index.
      Parameters:
      item - the item to get the parent of
      Returns:
      the parent index or a negative value if the parent is not found
    • getIndex

      public Integer getIndex(T item)
      Finds the index of the item in active tree.
      Parameters:
      item - the target item
      Returns:
      the index or a negative value if item is not found
    • isExpanded

      public boolean isExpanded(T item)
      Returns whether the given item is expanded.
      Parameters:
      item - the item to test
      Returns:
      true if item is expanded; false if not
    • expand

      public boolean expand(T item)
      Expands the given item.
      Parameters:
      item - the item to expand
      Returns:
      true if this method expanded the item, false otherwise
    • expand

      public Range expand(T item, Integer position)
      Expands the given item.
      Parameters:
      item - the item to expand
      position - the index of the item
      Returns:
      range of rows added by expanding the item
    • collapse

      public boolean collapse(T item)
      Collapses the given item.
      Parameters:
      item - the item to collapse
      Returns:
      true if item has been collapsed, false if item is empty or already collapsed
    • collapse

      public Range collapse(T item, Integer position)
      Collapses the given item.
      Parameters:
      item - the item to collapse
      position - the index of the item
      Returns:
      range of rows removed by collapsing the item
    • getInMemorySorting

      public Comparator<T> getInMemorySorting()
      Gets the current in-memory sorting.
      Returns:
      the in-memory sorting
    • setInMemorySorting

      public void setInMemorySorting(Comparator<T> inMemorySorting)
      Sets the current in-memory sorting. This will cause the hierarchy to be constructed again.
      Parameters:
      inMemorySorting - the in-memory sorting
    • getBackEndSorting

      public List<QuerySortOrder> getBackEndSorting()
      Gets the current back-end sorting.
      Returns:
      the back-end sorting
    • setBackEndSorting

      public void setBackEndSorting(List<QuerySortOrder> backEndSorting)
      Sets the current back-end sorting. This will cause the hierarchy to be constructed again.
      Parameters:
      backEndSorting - the back-end sorting
    • getFilter

      public F getFilter()
      Gets the current filter.
      Returns:
      the filter
    • setFilter

      public void setFilter(Object filter)
      Sets the current filter. This will cause the hierarchy to be constructed again.
      Parameters:
      filter - the filter
    • getDataProvider

      public HierarchicalDataProvider<T,F> getDataProvider()
      Gets the HierarchicalDataProvider for this HierarchyMapper.
      Returns:
      the hierarchical data provider
    • hasChildren

      public boolean hasChildren(T item)
      Returns whether given item has children.
      Parameters:
      item - the node to test
      Returns:
      true if node has children; false if not
    • fetchHierarchyItems

      public Stream<T> fetchHierarchyItems(Range range)
      Gets a stream of items in the form of a flattened hierarchy from the back-end and filter the wanted results from the list.
      Parameters:
      range - the requested item range
      Returns:
      the stream of items
    • fetchHierarchyItems

      public Stream<T> fetchHierarchyItems(T parent, Range range)
      Gets a stream of children for the given item in the form of a flattened hierarchy from the back-end and filter the wanted results from the list.
      Parameters:
      parent - the parent item for the fetch
      range - the requested item range
      Returns:
      the stream of items
    • fetchRootItems

      public Stream<T> fetchRootItems(Range range)
      Gets a stream of root items from the back-end and filter the wanted results from the list.
      Parameters:
      range - the requested item range
      Returns:
      the stream of items
    • fetchChildItems

      public Stream<T> fetchChildItems(T parent, Range range)
    • countChildItems

      public int countChildItems(T parent)
    • 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
    • getParentOfItem

      protected T getParentOfItem(T item)
      Find parent for the given item among open folders.
      Parameters:
      item - the item
      Returns:
      parent item or null for root items or if the parent is closed
    • removeChildren

      protected void removeChildren(Object id)
      Removes all children of an item identified by a given id. Items removed by this method as well as the original item are all marked to be collapsed. May be overridden in subclasses for removing obsolete data to avoid memory leaks.
      Parameters:
      id - the item id
    • getIndexOf

      public Optional<Integer> getIndexOf(T target)
      Finds the current index of given object. This is based on a search in flattened version of the hierarchy.
      Parameters:
      target - the target object to find
      Returns:
      optional index of given object
    • registerChildren

      protected void registerChildren(T parent, List<T> childList)
      Register parent and children items into inner structures. May be overridden in subclasses.
      Parameters:
      parent - the parent item
      childList - list of parents children to be registered.
    • destroyAllData

      public void destroyAllData()
    • hasExpandedItems

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

      public Collection<T> getExpandedItems()
      Returns the expanded items in form of an unmodifiable collection.
      Returns:
      an unmodifiable Collection<T> containing the expanded items.