aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
diff options
context:
space:
mode:
authorLeif Åstrand <legioth@gmail.com>2017-01-20 10:34:33 +0200
committerGitHub <noreply@github.com>2017-01-20 10:34:33 +0200
commitcb264dacfe74cba1266b54df8ce8c6ded1510004 (patch)
treedef7d7988d42ce2add93391a002399a4ce2949ff /server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
parent1fb40df8742791803e0a08328028bbbd67deb78b (diff)
downloadvaadin-framework-cb264dacfe74cba1266b54df8ce8c6ded1510004.tar.gz
vaadin-framework-cb264dacfe74cba1266b54df8ce8c6ded1510004.zip
Add a data provider wrapper with a configurable filter (#8280)
* Add a data provider wrapper with a configurable filter This is one of many steps towards #8245
Diffstat (limited to 'server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java')
-rw-r--r--server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java b/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
index 96d5e54394..199d0b64fe 100644
--- a/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
+++ b/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
@@ -18,6 +18,8 @@ package com.vaadin.data.provider;
import java.util.Collections;
import java.util.List;
+import com.vaadin.server.SerializableBiFunction;
+
/**
* A data provider that lazy loads items from a back end.
*
@@ -71,4 +73,44 @@ public interface BackEndDataProvider<T, F> extends DataProvider<T, F> {
default boolean isInMemory() {
return false;
}
+
+ /**
+ * Wraps this data provider to create a data provider that supports
+ * programmatically setting a filter that will be combined with a filter
+ * provided through the query.
+ *
+ * @see #withConfigurableFilter()
+ *
+ * @param filterCombiner
+ * a callback for combining and the configured filter with the
+ * filter from the query to get a filter to pass to the wrapped
+ * provider. Will only be called if the query contains a filter.
+ *
+ * @return a data provider with a configurable filter, not <code>null</code>
+ */
+ public default <C> ConfigurableFilterDataProvider<T, C, F> withConfigurableFilter(
+ SerializableBiFunction<F, C, F> filterCombiner) {
+ return new ConfigurableFilterDataProviderWrapper<T, C, F>(this) {
+ @Override
+ protected F combineFilters(F configuredFilter, C queryFilter) {
+ return filterCombiner.apply(configuredFilter, queryFilter);
+ }
+ };
+ }
+
+ /**
+ * Wraps this data provider to create a data provider that supports
+ * programmatically setting a filter but no filtering through the query.
+ *
+ * @see #withConfigurableFilter(SerializableBiFunction)
+ *
+ * @return a data provider with a configurable filter, not <code>null</code>
+ */
+ public default ConfigurableFilterDataProvider<T, Void, F> withConfigurableFilter() {
+ return withConfigurableFilter((configuredFilter, queryFilter) -> {
+ assert queryFilter == null : "Filter from Void query must be null";
+
+ return configuredFilter;
+ });
+ }
}