aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-11-21 16:37:10 +0200
committerTeemu Suo-Anttila <teemusa@vaadin.com>2016-11-21 16:37:10 +0200
commita8f5b1fb08b4eba5918aadb936030842aa9d9aed (patch)
tree32c662b54f18b746ee8472940a2770fe27d58f1a /server/src/main
parentdd907e839d2a3f2da2ce04d59b4e9e94cc7a634f (diff)
downloadvaadin-framework-a8f5b1fb08b4eba5918aadb936030842aa9d9aed.tar.gz
vaadin-framework-a8f5b1fb08b4eba5918aadb936030842aa9d9aed.zip
Add Filter parameter to DataProvider
Change-Id: Ic65b8decb3ac8d4dde9bca6cfb40a2a70f461e91
Diffstat (limited to 'server/src/main')
-rw-r--r--server/src/main/java/com/vaadin/data/Listing.java10
-rw-r--r--server/src/main/java/com/vaadin/server/data/AbstractDataProvider.java17
-rw-r--r--server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java23
-rw-r--r--server/src/main/java/com/vaadin/server/data/DataChangeEvent.java12
-rw-r--r--server/src/main/java/com/vaadin/server/data/DataCommunicator.java6
-rw-r--r--server/src/main/java/com/vaadin/server/data/DataProvider.java30
-rw-r--r--server/src/main/java/com/vaadin/server/data/ListDataProvider.java15
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractListing.java4
-rw-r--r--server/src/main/java/com/vaadin/ui/CheckBoxGroup.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/ComboBox.java6
-rw-r--r--server/src/main/java/com/vaadin/ui/ListSelect.java2
-rw-r--r--server/src/main/java/com/vaadin/ui/NativeSelect.java14
-rw-r--r--server/src/main/java/com/vaadin/ui/RadioButtonGroup.java6
-rw-r--r--server/src/main/java/com/vaadin/ui/TwinColSelect.java5
14 files changed, 83 insertions, 69 deletions
diff --git a/server/src/main/java/com/vaadin/data/Listing.java b/server/src/main/java/com/vaadin/data/Listing.java
index c866187518..8f94296057 100644
--- a/server/src/main/java/com/vaadin/data/Listing.java
+++ b/server/src/main/java/com/vaadin/data/Listing.java
@@ -24,7 +24,7 @@ import com.vaadin.server.data.DataProvider;
* A generic interface for components that show a list of data.
*
* @author Vaadin Ltd.
- *
+ *
* @param <T>
* the item data type
* @since 8.0
@@ -36,16 +36,16 @@ public interface Listing<T> extends Serializable {
*
* @return the data provider, not null
*/
- DataProvider<T> getDataProvider();
+ DataProvider<T, ?> getDataProvider();
/**
- * Sets the data provider for this listing. The data provider is
- * queried for displayed items as needed.
+ * Sets the data provider for this listing. The data provider is queried for
+ * displayed items as needed.
*
* @param dataProvider
* the data provider, not null
*/
- void setDataProvider(DataProvider<T> dataProvider);
+ void setDataProvider(DataProvider<T, ?> dataProvider);
/**
* Sets the collection of data items of this listing.
diff --git a/server/src/main/java/com/vaadin/server/data/AbstractDataProvider.java b/server/src/main/java/com/vaadin/server/data/AbstractDataProvider.java
index 531d77e44c..adb1bed36d 100644
--- a/server/src/main/java/com/vaadin/server/data/AbstractDataProvider.java
+++ b/server/src/main/java/com/vaadin/server/data/AbstractDataProvider.java
@@ -22,14 +22,19 @@ import com.vaadin.event.EventRouter;
import com.vaadin.shared.Registration;
/**
- * Abstract data provider implementation which takes care of refreshing data from
- * the underlying data provider.
- *
+ * Abstract data provider implementation which takes care of refreshing data
+ * from the underlying data provider.
+ *
+ * @param <T>
+ * data type
+ * @param <F>
+ * filter type
+ *
* @author Vaadin Ltd
* @since 8.0
*
*/
-public abstract class AbstractDataProvider<T> implements DataProvider<T> {
+public abstract class AbstractDataProvider<T, F> implements DataProvider<T, F> {
private EventRouter eventRouter;
@@ -60,8 +65,8 @@ public abstract class AbstractDataProvider<T> implements DataProvider<T> {
* the activation method.
*
*/
- protected void addListener(Class<?> eventType, DataProviderListener listener,
- Method method) {
+ protected void addListener(Class<?> eventType,
+ DataProviderListener listener, Method method) {
if (eventRouter == null) {
eventRouter = new EventRouter();
}
diff --git a/server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java b/server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java
index 8d267f1230..0f83710d90 100644
--- a/server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java
+++ b/server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java
@@ -27,11 +27,13 @@ import com.vaadin.server.SerializableFunction;
*
* @param <T>
* data provider data type
+ * @param <F>
+ * data provider filter type
*/
-public class BackEndDataProvider<T> extends AbstractDataProvider<T> {
+public class BackEndDataProvider<T, F> extends AbstractDataProvider<T, F> {
- private final SerializableFunction<Query<?>, Stream<T>> request;
- private final SerializableFunction<Query<?>, Integer> sizeCallback;
+ private final SerializableFunction<Query<F>, Stream<T>> request;
+ private final SerializableFunction<Query<F>, Integer> sizeCallback;
/**
* Constructs a new DataProvider to request data from an arbitrary back end
@@ -43,8 +45,8 @@ public class BackEndDataProvider<T> extends AbstractDataProvider<T> {
* function that return the amount of data in back end for query
*/
public BackEndDataProvider(
- SerializableFunction<Query<?>, Stream<T>> request,
- SerializableFunction<Query<?>, Integer> sizeCallback) {
+ SerializableFunction<Query<F>, Stream<T>> request,
+ SerializableFunction<Query<F>, Integer> sizeCallback) {
Objects.requireNonNull(request, "Request function can't be null");
Objects.requireNonNull(sizeCallback, "Size callback can't be null");
this.request = request;
@@ -52,12 +54,12 @@ public class BackEndDataProvider<T> extends AbstractDataProvider<T> {
}
@Override
- public Stream<T> fetch(Query query) {
+ public Stream<T> fetch(Query<F> query) {
return request.apply(query);
}
@Override
- public int size(Query query) {
+ public int size(Query<F> query) {
return sizeCallback.apply(query);
}
@@ -69,14 +71,15 @@ public class BackEndDataProvider<T> extends AbstractDataProvider<T> {
* directions
* @return new data provider with modified sorting
*/
- public BackEndDataProvider<T> sortingBy(
+ public BackEndDataProvider<T, F> sortingBy(
List<SortOrder<String>> sortOrders) {
return new BackEndDataProvider<>(query -> {
List<SortOrder<String>> queryOrder = new ArrayList<>(
query.getSortOrders());
queryOrder.addAll(sortOrders);
- return request.apply(new Query<>(query.getLimit(),
- query.getOffset(), queryOrder, query.getFilter()));
+ return request
+ .apply(new Query<>(query.getLimit(), query.getOffset(),
+ queryOrder, query.getFilter().orElse(null)));
}, sizeCallback);
}
diff --git a/server/src/main/java/com/vaadin/server/data/DataChangeEvent.java b/server/src/main/java/com/vaadin/server/data/DataChangeEvent.java
index 94d28fc9d3..6d7d2e8bfb 100644
--- a/server/src/main/java/com/vaadin/server/data/DataChangeEvent.java
+++ b/server/src/main/java/com/vaadin/server/data/DataChangeEvent.java
@@ -19,10 +19,10 @@ import java.util.EventObject;
/**
* An event fired when the data of a {@code DataProvider} changes.
- *
- *
+ *
+ *
* @see DataProviderListener
- *
+ *
* @author Vaadin Ltd
* @since 8.0
*
@@ -36,13 +36,13 @@ public class DataChangeEvent extends EventObject {
* @param source
* the data provider, not null
*/
- public DataChangeEvent(DataProvider<?> source) {
+ public DataChangeEvent(DataProvider<?, ?> source) {
super(source);
}
@Override
- public DataProvider<?> getSource() {
- return (DataProvider<?>) super.getSource();
+ public DataProvider<?, ?> getSource() {
+ return (DataProvider<?, ?>) super.getSource();
}
}
diff --git a/server/src/main/java/com/vaadin/server/data/DataCommunicator.java b/server/src/main/java/com/vaadin/server/data/DataCommunicator.java
index 46b8fa079a..fc66185aee 100644
--- a/server/src/main/java/com/vaadin/server/data/DataCommunicator.java
+++ b/server/src/main/java/com/vaadin/server/data/DataCommunicator.java
@@ -180,7 +180,7 @@ public class DataCommunicator<T> extends AbstractExtension {
private final Collection<DataGenerator<T>> generators = new LinkedHashSet<>();
private final ActiveDataHandler handler = new ActiveDataHandler();
- private DataProvider<T> dataProvider = DataProvider.create();
+ private DataProvider<T, ?> dataProvider = DataProvider.create();
private final DataKeyMapper<T> keyMapper;
private boolean reset = false;
@@ -462,7 +462,7 @@ public class DataCommunicator<T> extends AbstractExtension {
*
* @return the data provider
*/
- public DataProvider<T> getDataProvider() {
+ public DataProvider<T, ?> getDataProvider() {
return dataProvider;
}
@@ -472,7 +472,7 @@ public class DataCommunicator<T> extends AbstractExtension {
* @param dataProvider
* the data provider to set, not null
*/
- public void setDataProvider(DataProvider<T> dataProvider) {
+ public void setDataProvider(DataProvider<T, ?> dataProvider) {
Objects.requireNonNull(dataProvider, "data provider cannot be null");
this.dataProvider = dataProvider;
detachDataProviderListener();
diff --git a/server/src/main/java/com/vaadin/server/data/DataProvider.java b/server/src/main/java/com/vaadin/server/data/DataProvider.java
index b99cbe5d75..441a57b559 100644
--- a/server/src/main/java/com/vaadin/server/data/DataProvider.java
+++ b/server/src/main/java/com/vaadin/server/data/DataProvider.java
@@ -23,20 +23,22 @@ import java.util.stream.Stream;
import com.vaadin.shared.Registration;
/**
- * Minimal DataProvider API for communication between the DataProvider and a back
- * end service.
+ * Minimal DataProvider API for communication between the DataProvider and a
+ * back end service.
*
* @author Vaadin Ltd.
- *
+ *
* @param <T>
* data type
+ * @param <F>
+ * filter type
*
* @see ListDataProvider
* @see BackEndDataProvider
*
* @since 8.0
*/
-public interface DataProvider<T> extends Serializable {
+public interface DataProvider<T, F> extends Serializable {
/**
* Gets whether the DataProvider content all available in memory or does it
@@ -53,17 +55,17 @@ public interface DataProvider<T> extends Serializable {
* query with sorting and filtering
* @return the size of the data provider
*/
- int size(Query t);
+ int size(Query<F> t);
/**
* Fetches data from this DataProvider using given {@code query}.
- *
+ *
* @param query
* given query to request data
* @return the result of the query request: a stream of data objects, not
* {@code null}
*/
- Stream<T> fetch(Query query);
+ Stream<T> fetch(Query<F> query);
/**
* Refreshes all data based on currently available data in the underlying
@@ -87,10 +89,10 @@ public interface DataProvider<T> extends Serializable {
Registration addDataProviderListener(DataProviderListener listener);
/**
- * This method creates a new {@link ListDataProvider} from a given Collection.
- * The ListDataProvider creates a protective List copy of all the contents in
- * the Collection.
- *
+ * This method creates a new {@link ListDataProvider} from a given
+ * Collection. The ListDataProvider creates a protective List copy of all
+ * the contents in the Collection.
+ *
* @param <T>
* the data item type
* @param items
@@ -103,9 +105,9 @@ public interface DataProvider<T> extends Serializable {
/**
* This method creates a new {@link ListDataProvider} from given objects.The
- * ListDataProvider creates a protective List copy of all the contents in the
- * array.
- *
+ * ListDataProvider creates a protective List copy of all the contents in
+ * the array.
+ *
* @param <T>
* the data item type
* @param items
diff --git a/server/src/main/java/com/vaadin/server/data/ListDataProvider.java b/server/src/main/java/com/vaadin/server/data/ListDataProvider.java
index 14527749a5..a67ce42eab 100644
--- a/server/src/main/java/com/vaadin/server/data/ListDataProvider.java
+++ b/server/src/main/java/com/vaadin/server/data/ListDataProvider.java
@@ -21,6 +21,8 @@ import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Stream;
+import com.vaadin.server.SerializablePredicate;
+
/**
* {@link DataProvider} wrapper for {@link Collection}s. This class does not
* actually handle the {@link Query} parameters.
@@ -28,7 +30,8 @@ import java.util.stream.Stream;
* @param <T>
* data type
*/
-public class ListDataProvider<T> extends AbstractDataProvider<T> {
+public class ListDataProvider<T>
+ extends AbstractDataProvider<T, SerializablePredicate<T>> {
private Comparator<T> sortOrder;
private final Collection<T> backend;
@@ -50,7 +53,7 @@ public class ListDataProvider<T> extends AbstractDataProvider<T> {
* Chaining constructor for making modified {@link ListDataProvider}s. This
* Constructor is used internally for making sorted and filtered variants of
* a base data provider with actual data.
- *
+ *
* @param items
* the backend data from the original list data provider
* @param sortOrder
@@ -72,8 +75,8 @@ public class ListDataProvider<T> extends AbstractDataProvider<T> {
}
/**
- * Creates a new list data provider based on this list data provider with the
- * given sort order.
+ * Creates a new list data provider based on this list data provider with
+ * the given sort order.
* <p>
* <b>NOTE</b>: this data provider is not modified in any way.
*
@@ -86,8 +89,8 @@ public class ListDataProvider<T> extends AbstractDataProvider<T> {
}
/**
- * Creates a new list data provider based on this list data provider with the
- * given sort order.
+ * Creates a new list data provider based on this list data provider with
+ * the given sort order.
* <p>
* <b>NOTE</b>: this data provider is not modified in any way.
* <p>
diff --git a/server/src/main/java/com/vaadin/ui/AbstractListing.java b/server/src/main/java/com/vaadin/ui/AbstractListing.java
index 99dd6e5eb1..f49d8715de 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractListing.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractListing.java
@@ -133,12 +133,12 @@ public abstract class AbstractListing<T> extends AbstractComponent
}
@Override
- public void setDataProvider(DataProvider<T> dataProvider) {
+ public void setDataProvider(DataProvider<T, ?> dataProvider) {
getDataCommunicator().setDataProvider(dataProvider);
}
@Override
- public DataProvider<T> getDataProvider() {
+ public DataProvider<T, ?> getDataProvider() {
return getDataCommunicator().getDataProvider();
}
diff --git a/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java b/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java
index a3f99e7b27..eb61d2242d 100644
--- a/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java
+++ b/server/src/main/java/com/vaadin/ui/CheckBoxGroup.java
@@ -64,7 +64,7 @@ public class CheckBoxGroup<T> extends AbstractMultiSelect<T>
* the data provider, not null
* @see Listing#setDataProvider(DataProvider)
*/
- public CheckBoxGroup(String caption, DataProvider<T> dataProvider) {
+ public CheckBoxGroup(String caption, DataProvider<T, ?> dataProvider) {
this(caption);
setDataProvider(dataProvider);
}
diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java
index 60a229ba55..2270c1a181 100644
--- a/server/src/main/java/com/vaadin/ui/ComboBox.java
+++ b/server/src/main/java/com/vaadin/ui/ComboBox.java
@@ -158,8 +158,8 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
}
/**
- * Constructs a combo box with a static in-memory data provider with the given
- * options.
+ * Constructs a combo box with a static in-memory data provider with the
+ * given options.
*
* @param caption
* the caption to show in the containing layout, null for no
@@ -180,7 +180,7 @@ public class ComboBox<T> extends AbstractSingleSelect<T> implements HasValue<T>,
* @param dataProvider
* the data provider to use, not null
*/
- public ComboBox(String caption, DataProvider<T> dataProvider) {
+ public ComboBox(String caption, DataProvider<T, ?> dataProvider) {
this(caption);
setDataProvider(dataProvider);
}
diff --git a/server/src/main/java/com/vaadin/ui/ListSelect.java b/server/src/main/java/com/vaadin/ui/ListSelect.java
index e616fa2af3..00e0d9912d 100644
--- a/server/src/main/java/com/vaadin/ui/ListSelect.java
+++ b/server/src/main/java/com/vaadin/ui/ListSelect.java
@@ -61,7 +61,7 @@ public class ListSelect<T> extends AbstractMultiSelect<T> {
* @param dataProvider
* the data provider, not {@code null}
*/
- public ListSelect(String caption, DataProvider<T> dataProvider) {
+ public ListSelect(String caption, DataProvider<T, ?> dataProvider) {
this(caption);
setDataProvider(dataProvider);
}
diff --git a/server/src/main/java/com/vaadin/ui/NativeSelect.java b/server/src/main/java/com/vaadin/ui/NativeSelect.java
index 2a696c75d4..46e72b02c6 100644
--- a/server/src/main/java/com/vaadin/ui/NativeSelect.java
+++ b/server/src/main/java/com/vaadin/ui/NativeSelect.java
@@ -34,12 +34,12 @@ import com.vaadin.shared.ui.nativeselect.NativeSelectState;
* A simple drop-down select component. Represented on the client side by a
* "native" HTML {@code <select>} element. Lacks advanced features such as lazy
* loading, filtering, and adding new items.
- *
+ *
* @author Vaadin Ltd.
- *
+ *
* @param <T>
* the data item type
- *
+ *
* @see com.vaadin.ui.ComboBox
*/
public class NativeSelect<T> extends AbstractSingleSelect<T>
@@ -56,7 +56,7 @@ public class NativeSelect<T> extends AbstractSingleSelect<T>
/**
* Creates a new {@code NativeSelect} with the given caption and no items.
- *
+ *
* @param caption
* the component caption to set, null for no caption
*/
@@ -68,7 +68,7 @@ public class NativeSelect<T> extends AbstractSingleSelect<T>
/**
* Creates a new {@code NativeSelect} with the given caption, containing the
* data items in the given collection.
- *
+ *
* @param caption
* the component caption to set, null for no caption
* @param items
@@ -82,13 +82,13 @@ public class NativeSelect<T> extends AbstractSingleSelect<T>
/**
* Creates a new {@code NativeSelect} with the given caption, using the
* given {@code DataProvider} as the source of data items.
- *
+ *
* @param caption
* the component caption to set, null for no caption
* @param dataProvider
* the source of data items to use, not null
*/
- public NativeSelect(String caption, DataProvider<T> dataProvider) {
+ public NativeSelect(String caption, DataProvider<T, ?> dataProvider) {
this(caption);
setDataProvider(dataProvider);
}
diff --git a/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java b/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java
index 8949493d6f..13b8fedc72 100644
--- a/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java
+++ b/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java
@@ -77,14 +77,14 @@ public class RadioButtonGroup<T> extends AbstractSingleSelect<T>
* the data provider, not null
* @see Listing#setDataProvider(DataProvider)
*/
- public RadioButtonGroup(String caption, DataProvider<T> dataProvider) {
+ public RadioButtonGroup(String caption, DataProvider<T, ?> dataProvider) {
this(caption);
setDataProvider(dataProvider);
}
/**
- * Constructs a new RadioButtonGroup with caption and DataProvider containing
- * given items.
+ * Constructs a new RadioButtonGroup with caption and DataProvider
+ * containing given items.
*
* @param caption
* the caption text
diff --git a/server/src/main/java/com/vaadin/ui/TwinColSelect.java b/server/src/main/java/com/vaadin/ui/TwinColSelect.java
index 0858a76830..2d6b97a99a 100644
--- a/server/src/main/java/com/vaadin/ui/TwinColSelect.java
+++ b/server/src/main/java/com/vaadin/ui/TwinColSelect.java
@@ -50,14 +50,15 @@ public class TwinColSelect<T> extends AbstractMultiSelect<T> {
}
/**
- * Constructs a new TwinColSelect with caption and data provider for options.
+ * Constructs a new TwinColSelect with caption and data provider for
+ * options.
*
* @param caption
* the caption to set, can be {@code null}
* @param dataProvider
* the data provider, not {@code null}
*/
- public TwinColSelect(String caption, DataProvider<T> dataProvider) {
+ public TwinColSelect(String caption, DataProvider<T, ?> dataProvider) {
this(caption);
setDataProvider(dataProvider);
}