summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLeif Åstrand <legioth@gmail.com>2017-03-31 15:48:13 +0300
committerPekka Hyvönen <pekka@vaadin.com>2017-03-31 15:48:13 +0300
commit0a257471c7c948a78cfc2b01961e8a604f4ec1bf (patch)
tree3b0431e3ee945586231e778d39b869c13b1fbb16 /server
parentb56732af18f75d210248e08d6899ef47ed55437f (diff)
downloadvaadin-framework-0a257471c7c948a78cfc2b01961e8a604f4ec1bf.tar.gz
vaadin-framework-0a257471c7c948a78cfc2b01961e8a604f4ec1bf.zip
Make getValueProvider return ValueProvider (#8983)
* Make getValueProvider return ValueProvider The instance can only be a ValueProvider, but the getter previously returned a less specific type. Making the getter return ValueProvider makes it easier to reuse the provider in other contexts that require ValueProvider, e.g. when adding filters to a ListDataProvider.
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java5
-rw-r--r--server/src/test/java/com/vaadin/tests/components/grid/GridValueProvider.java29
2 files changed, 31 insertions, 3 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index 872e14a44f..d90539c778 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -69,7 +69,6 @@ import com.vaadin.server.EncodeResult;
import com.vaadin.server.Extension;
import com.vaadin.server.JsonCodec;
import com.vaadin.server.SerializableComparator;
-import com.vaadin.server.SerializableFunction;
import com.vaadin.server.SerializableSupplier;
import com.vaadin.server.Setter;
import com.vaadin.server.VaadinServiceClassLoaderUtil;
@@ -820,7 +819,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
*/
public static class Column<T, V> extends AbstractGridExtension<T> {
- private final SerializableFunction<T, ? extends V> valueProvider;
+ private final ValueProvider<T, V> valueProvider;
private SortOrderProvider sortOrderProvider = direction -> {
String id = getId();
@@ -1126,7 +1125,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
*
* @since 8.0.3
*/
- public SerializableFunction<T, ? extends V> getValueProvider() {
+ public ValueProvider<T, V> getValueProvider() {
return valueProvider;
}
diff --git a/server/src/test/java/com/vaadin/tests/components/grid/GridValueProvider.java b/server/src/test/java/com/vaadin/tests/components/grid/GridValueProvider.java
index 09108b6746..27ba971127 100644
--- a/server/src/test/java/com/vaadin/tests/components/grid/GridValueProvider.java
+++ b/server/src/test/java/com/vaadin/tests/components/grid/GridValueProvider.java
@@ -15,9 +15,16 @@
*/
package com.vaadin.tests.components.grid;
+import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
+
import org.junit.Assert;
import org.junit.Test;
+import com.vaadin.data.provider.DataProvider;
+import com.vaadin.data.provider.ListDataProvider;
+import com.vaadin.data.provider.Query;
import com.vaadin.tests.data.bean.Person;
import com.vaadin.tests.data.bean.Sex;
import com.vaadin.ui.Grid;
@@ -45,4 +52,26 @@ public class GridValueProvider {
Assert.assertEquals("eeemaaail", col.getValueProvider().apply(person));
}
+
+ @Test
+ public void reuseValueProviderForFilter() {
+ Grid<Person> grid = new Grid<>(Person.class);
+ Column<Person, String> col = (Column<Person, String>) grid
+ .getColumn("email");
+
+ Person lowerCasePerson = new Person("first", "last", "email", 123,
+ Sex.UNKNOWN, null);
+ Person upperCasePerson = new Person("FIRST", "LAST", "EMAIL", 123,
+ Sex.UNKNOWN, null);
+ ListDataProvider<Person> persons = DataProvider.ofItems(lowerCasePerson,
+ upperCasePerson);
+
+ persons.addFilter(col.getValueProvider(),
+ value -> value.toUpperCase(Locale.ENGLISH).equals(value));
+
+ List<Person> queryPersons = persons.fetch(new Query<>())
+ .collect(Collectors.toList());
+ Assert.assertEquals(1, queryPersons.size());
+ Assert.assertSame(upperCasePerson, queryPersons.get(0));
+ }
}