aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/data/provider/HierarchicalDataProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/main/java/com/vaadin/data/provider/HierarchicalDataProvider.java')
-rw-r--r--server/src/main/java/com/vaadin/data/provider/HierarchicalDataProvider.java82
1 files changed, 75 insertions, 7 deletions
diff --git a/server/src/main/java/com/vaadin/data/provider/HierarchicalDataProvider.java b/server/src/main/java/com/vaadin/data/provider/HierarchicalDataProvider.java
index ec54a3a138..8dabdce2cc 100644
--- a/server/src/main/java/com/vaadin/data/provider/HierarchicalDataProvider.java
+++ b/server/src/main/java/com/vaadin/data/provider/HierarchicalDataProvider.java
@@ -15,25 +15,93 @@
*/
package com.vaadin.data.provider;
+import java.util.stream.Stream;
+
/**
- *
+ * A common interface for fetching hierarchical data from a data source, such as
+ * an in-memory collection or a backend database.
+ *
* @author Vaadin Ltd
* @since 8.1
- *
+ *
* @param <T>
+ * data type
* @param <F>
+ * filter type
*/
public interface HierarchicalDataProvider<T, F> extends DataProvider<T, F> {
- public int getDepth(T item);
+ /**
+ * Get the number of immediate child data items for the parent item returned
+ * by a given query.
+ *
+ * @param query
+ * given query to request the count for
+ * @return the count of child data items for the data item
+ * {@link HierarchicalQuery#getParent()}
+ *
+ * @throws IllegalArgumentException
+ * if the query is not of type HierarchicalQuery
+ */
+ @Override
+ public default int size(Query<T, F> query) {
+ if (query instanceof HierarchicalQuery<?, ?>) {
+ return getChildCount((HierarchicalQuery<T, F>) query);
+ }
+ throw new IllegalArgumentException(
+ "Hierarchical data provider doesn't support non-hierarchical queries");
+ }
- public boolean isRoot(T item);
+ /**
+ * Fetches data from this HierarchicalDataProvider using given
+ * {@code query}. Only the immediate children of
+ * {@link HierarchicalQuery#getParent()} will be returned.
+ *
+ * @param query
+ * given query to request data with
+ * @return a stream of data objects resulting from the query
+ *
+ * @throws IllegalArgumentException
+ * if the query is not of type HierarchicalQuery
+ */
+ @Override
+ public default Stream<T> fetch(Query<T, F> query) {
+ if (query instanceof HierarchicalQuery<?, ?>) {
+ return fetchChildren((HierarchicalQuery<T, F>) query);
+ }
+ throw new IllegalArgumentException(
+ "Hierarchical data provider doesn't support non-hierarchical queries");
+ }
- public T getParent(T item);
+ /**
+ * Get the number of immediate child data items for the parent item returned
+ * by a given query.
+ *
+ * @param query
+ * given query to request the count for
+ * @return the count of child data items for the data item
+ * {@link HierarchicalQuery#getParent()}
+ */
+ public int getChildCount(HierarchicalQuery<T, F> query);
- public boolean isCollapsed(T item);
+ /**
+ * Fetches data from this HierarchicalDataProvider using given
+ * {@code query}. Only the immediate children of
+ * {@link HierarchicalQuery#getParent()} will be returned.
+ *
+ * @param query
+ * given query to request data with
+ * @return a stream of data objects resulting from the query
+ */
+ public Stream<T> fetchChildren(HierarchicalQuery<T, F> query);
+ /**
+ * Check whether a given item has any children associated with it.
+ *
+ * @param item
+ * the item to check for children
+ * @return whether the given item has children
+ */
public boolean hasChildren(T item);
- public void setCollapsed(T item, boolean b);
}