aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2017-05-18 15:48:02 +0300
committerPekka Hyvönen <pekka@vaadin.com>2017-05-19 11:21:33 +0300
commitded683a75f5923274952a0a173ca09b61c834c82 (patch)
tree9f146d2ee294b04c1accee53a4764a5bb3c4ef37
parent84c0bee7e90091b2b86c6c452d1bd87a27d98c7d (diff)
downloadvaadin-framework-ded683a75f5923274952a0a173ca09b61c834c82.tar.gz
vaadin-framework-ded683a75f5923274952a0a173ca09b61c834c82.zip
Add shorthand for adding a column with ComponentRenderer
-rw-r--r--documentation/components/components-grid.asciidoc4
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java21
-rw-r--r--server/src/test/java/com/vaadin/tests/components/grid/GridComponentRendererTest.java5
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java6
4 files changed, 28 insertions, 8 deletions
diff --git a/documentation/components/components-grid.asciidoc b/documentation/components/components-grid.asciidoc
index 1195a1c79a..160b97f077 100644
--- a/documentation/components/components-grid.asciidoc
+++ b/documentation/components/components-grid.asciidoc
@@ -576,12 +576,12 @@ the height of all rows in the Grid.
Use [classname]#Button# in [classname]#Grid#:
+
----
-grid.addColumn(person -> {
+grid.addComponentColumn(person -> {
Button button = new Button("Click me!");
button.addClickListener(click ->
Notification.show("Clicked: " + person.toString()));
return button;
-}, new ComponentRenderer());
+});
// make sure the buttons fit in the cells of the Grid
grid.setRowHeight(40);
----
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index 463e475a44..845a61a42a 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -2421,6 +2421,25 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
}
/**
+ * Adds a column that shows components.
+ * <p>
+ * This is a shorthand for {@link #addColum()} with a
+ * {@link ComponentRenderer}.
+ *
+ * @param componentProvider
+ * a value provider that will return a component for the given
+ * item
+ * @return the new column
+ * @param <V>
+ * the column value type, extends component
+ * @since 8.1
+ */
+ public <V extends Component> Column<T, V> addComponentColumn(
+ ValueProvider<T, V> componentProvider) {
+ return addColumn(componentProvider, new ComponentRenderer());
+ }
+
+ /**
* Creates a column instance from a value provider and a renderer.
*
* @param valueProvider
@@ -2428,6 +2447,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
* @param renderer
* the renderer
* @return a new column instance
+ * @param <V>
+ * the column value type
*
* @since 8.0.3
*/
diff --git a/server/src/test/java/com/vaadin/tests/components/grid/GridComponentRendererTest.java b/server/src/test/java/com/vaadin/tests/components/grid/GridComponentRendererTest.java
index 9e6eb33704..d0b2b11dca 100644
--- a/server/src/test/java/com/vaadin/tests/components/grid/GridComponentRendererTest.java
+++ b/server/src/test/java/com/vaadin/tests/components/grid/GridComponentRendererTest.java
@@ -15,7 +15,6 @@ import com.vaadin.tests.util.AlwaysLockedVaadinSession;
import com.vaadin.tests.util.MockUI;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Label;
-import com.vaadin.ui.renderers.ComponentRenderer;
/**
* Test to validate clean detaching in Grid with ComponentRenderer.
@@ -37,11 +36,11 @@ public class GridComponentRendererTest {
dataProvider = DataProvider.ofCollection(backend);
grid = new Grid<>();
grid.setDataProvider(dataProvider);
- grid.addColumn(p -> {
+ grid.addComponentColumn(p -> {
oldComponent = testComponent;
testComponent = new Label();
return testComponent;
- }, new ComponentRenderer());
+ });
new MockUI() {
@Override
public Future<Void> access(Runnable runnable) {
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java
index 1a546a767d..dce85d3be9 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridComponents.java
@@ -24,9 +24,9 @@ public class GridComponents extends AbstractTestUIWithLog {
@Override
protected void setup(VaadinRequest request) {
- Grid<String> grid = new Grid<String>();
+ Grid<String> grid = new Grid<>();
grid.addColumn(string -> new Label(string), new ComponentRenderer());
- grid.addColumn(string -> {
+ grid.addComponentColumn(string -> {
if (textFields.containsKey(string)) {
log("Reusing old text field for: " + string);
return textFields.get(string);
@@ -41,7 +41,7 @@ public class GridComponents extends AbstractTestUIWithLog {
textFields.put(string, textField);
});
return textField;
- }, new ComponentRenderer());
+ });
grid.addColumn(string -> {
Button button = new Button("Click Me!",
e -> Notification.show(