aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-03-02 23:20:10 +0200
committerPekka Hyvönen <pekka@vaadin.com>2017-03-02 23:20:10 +0200
commit45921980b2ce44b6e9642aca6da33cea6da24cc0 (patch)
treef0bfdd1c6a8f3cae1ba66131aeb36974813e8b2e /server
parent55530edec19e2bdf478a1e0dc782012754866adf (diff)
downloadvaadin-framework-45921980b2ce44b6e9642aca6da33cea6da24cc0.tar.gz
vaadin-framework-45921980b2ce44b6e9642aca6da33cea6da24cc0.zip
Add Column.getValueProvider to Grid (#8732)
* Add Column.getValueProvider to Grid Fixes #8680
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java19
-rw-r--r--server/src/test/java/com/vaadin/tests/components/grid/GridValueProvider.java48
2 files changed, 63 insertions, 4 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index c464acb8fc..d5d0a30bd1 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -645,8 +645,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
.hasKey(diffStateKey) : "Field name has changed";
Type type = null;
try {
- type = getState(false).getClass()
- .getField(diffStateKey).getGenericType();
+ type = getState(false).getClass().getField(diffStateKey)
+ .getGenericType();
} catch (NoSuchFieldException | SecurityException e) {
e.printStackTrace();
}
@@ -887,7 +887,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
if (hasCommonComparableBaseType(a, b)) {
return compareComparables(a, b);
} else {
- return compareComparables(Objects.toString(a, ""), Objects.toString(b, ""));
+ return compareComparables(Objects.toString(a, ""),
+ Objects.toString(b, ""));
}
}
@@ -907,7 +908,7 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
}
}
if ((a == null && b instanceof Comparable<?>)
- || (b == null && a instanceof Comparable<?>)) {
+ || (b == null && a instanceof Comparable<?>)) {
return true;
}
@@ -1076,6 +1077,16 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
}
/**
+ * Gets the function used to produce the value for data in this column
+ * based on the row item.
+ *
+ * @return the value provider function
+ */
+ public SerializableFunction<T, ? extends V> getValueProvider() {
+ return valueProvider;
+ }
+
+ /**
* Sets whether the user can sort this column or not.
*
* @param sortable
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
new file mode 100644
index 0000000000..09108b6746
--- /dev/null
+++ b/server/src/test/java/com/vaadin/tests/components/grid/GridValueProvider.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.tests.data.bean.Sex;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.Column;
+
+public class GridValueProvider {
+
+ @Test
+ public void getExplicitValueProvider() {
+ Grid<Person> grid = new Grid<>();
+ Column<Person, String> col = grid.addColumn(
+ person -> person.getFirstName() + " " + person.getLastName());
+ Person person = new Person("first", "last", "email", 123, Sex.UNKNOWN,
+ null);
+ Assert.assertEquals("first last", col.getValueProvider().apply(person));
+ }
+
+ @Test
+ public void getBeanColumnValueProvider() {
+ Grid<Person> grid = new Grid<>(Person.class);
+ Column<Person, String> col = (Column<Person, String>) grid
+ .getColumn("email");
+ Person person = new Person("first", "last", "eeemaaail", 123,
+ Sex.UNKNOWN, null);
+ Assert.assertEquals("eeemaaail", col.getValueProvider().apply(person));
+
+ }
+}