summaryrefslogtreecommitdiffstats
path: root/server/src/main
diff options
context:
space:
mode:
authorTatu Lund <tatu@vaadin.com>2020-01-16 02:25:46 +0200
committerAnna Koskinen <Ansku@users.noreply.github.com>2020-01-16 02:25:46 +0200
commit1076cb016206553aa017b5e479d5679107b14409 (patch)
treee870cc52edba67f79325cfe000aa1e7182d64306 /server/src/main
parent2bf0b02220ea96ee959b766a32bf1a79ae968317 (diff)
downloadvaadin-framework-1076cb016206553aa017b5e479d5679107b14409.tar.gz
vaadin-framework-1076cb016206553aa017b5e479d5679107b14409.zip
TreeDataProvider: Apply filters to children (#11868)
Fixes: https://github.com/vaadin/framework/issues/9933 Cherry pick from: https://github.com/vaadin/flow/pull/7317
Diffstat (limited to 'server/src/main')
-rw-r--r--server/src/main/java/com/vaadin/data/provider/TreeDataProvider.java15
1 files changed, 13 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/data/provider/TreeDataProvider.java b/server/src/main/java/com/vaadin/data/provider/TreeDataProvider.java
index 5436685e58..6fcd029003 100644
--- a/server/src/main/java/com/vaadin/data/provider/TreeDataProvider.java
+++ b/server/src/main/java/com/vaadin/data/provider/TreeDataProvider.java
@@ -172,9 +172,20 @@ public class TreeDataProvider<T>
private Stream<T> getFilteredStream(Stream<T> stream,
Optional<SerializablePredicate<T>> queryFilter) {
+ final Optional<SerializablePredicate<T>> combinedFilter;
if (filter != null) {
- stream = stream.filter(filter);
+ combinedFilter = Optional
+ .of(queryFilter.map(filter::and).orElse(filter));
+ } else {
+ combinedFilter = queryFilter;
}
- return queryFilter.map(stream::filter).orElse(stream);
+ return combinedFilter.map(
+ f -> stream.filter(element -> flatten(element).anyMatch(f)))
+ .orElse(stream);
+ }
+
+ private Stream<T> flatten(T element) {
+ return Stream.concat(Stream.of(element), getTreeData()
+ .getChildren(element).stream().flatMap(this::flatten));
}
}