Interface HierarchicalDataProvider<T>

Type Parameters:
T - the data item type
All Superinterfaces:
DataProvider<T>

public interface HierarchicalDataProvider<T> extends DataProvider<T>
Extension of DataProvider for tree-structured data.

Provides methods for fetching child items, counting children, and checking whether an item has children. Used by tree grids, tree tables, and tree views.


 HierarchicalDataProvider<Department> provider = new HierarchicalDataProvider<Department>() {
     @Override
     public DataResult<Department> fetchChildren(Department parent, Query query) {
         List<Department> children = departmentDao.getChildren(
             parent == null ? null : parent.getId(),
             query.getOffset(), query.getLimit());
         int total = departmentDao.getChildCount(
             parent == null ? null : parent.getId());
         return DataResult.of(children, total);
     }

     @Override
     public int getChildCount(Department parent, Query query) {
         return departmentDao.getChildCount(
             parent == null ? null : parent.getId());
     }

     @Override
     public boolean hasChildren(Department item) {
         return departmentDao.hasChildren(item.getId());
     }
 };
 
Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Method Details

    • fetchChildren

      DataResult<T> fetchChildren(T parent, Query query)
      Fetches child items of the given parent.

      Pass null as the parent to fetch root-level items.

      Parameters:
      parent - the parent item, or null for root items
      query - the query with offset, limit, sorts, and filters
      Returns:
      the result containing child items and total child count
    • getChildCount

      int getChildCount(T parent, Query query)
      Returns the number of children for the given parent.
      Parameters:
      parent - the parent item, or null for root items
      query - the query (only filters are relevant)
      Returns:
      the number of child items
    • hasChildren

      boolean hasChildren(T item)
      Returns whether the given item has any children.

      Used by tree components to determine whether to show an expand indicator.

      Parameters:
      item - the item to check
      Returns:
      true if the item has children