summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-06-27 15:42:01 +0300
committerHenri Sara <henri.sara@gmail.com>2017-06-27 15:42:01 +0300
commite4e2328a3a78d652cd09ef8293f233d31d899415 (patch)
tree26d0b17179952e662ab8559269154715ba10c265 /uitest
parent65ac37ae63f65d17731dafdab85f0be53158ae78 (diff)
downloadvaadin-framework-e4e2328a3a78d652cd09ef8293f233d31d899415.tar.gz
vaadin-framework-e4e2328a3a78d652cd09ef8293f233d31d899415.zip
Add presentation value providers for Grid (#9553)
This patch changes Grid Columns, so they can have different value and presentation types. A presentation provider can be given when setting the renderer for a column. This provider takes the value of the column on a row and chooses what to present for this value. Using this approach it is easier to have an editor for the actual backing data instead of the presentation of it. Fixes #8656 Resolves #9588
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnPresentation.java99
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnPresentationTest.java27
2 files changed, 126 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnPresentation.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnPresentation.java
new file mode 100644
index 0000000000..2f099982a6
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnPresentation.java
@@ -0,0 +1,99 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.data.HasValue;
+import com.vaadin.server.ErrorMessage;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.Registration;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.data.bean.Address;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.ui.Composite;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.renderers.TextRenderer;
+
+/**
+ * An example for using a different value and presentation types in a Grid
+ * column.
+ */
+public class GridColumnPresentation extends AbstractTestUI {
+
+ /**
+ * Dummy HasValue for Address.
+ */
+ private static class AddressField extends Composite
+ implements HasValue<Address> {
+
+ Address address;
+ private Label label;
+
+ public AddressField() {
+ super();
+
+ label = new Label();
+ setCompositionRoot(label);
+ }
+
+ @Override
+ public void setValue(Address value) {
+ Address oldAddress = address;
+ address = value;
+ label.setValue(String.valueOf(address));
+ fireEvent(new ValueChangeEvent<>(this, oldAddress, false));
+ }
+
+ @Override
+ public Address getValue() {
+ return address;
+ }
+
+ @Override
+ public Registration addValueChangeListener(
+ ValueChangeListener<Address> listener) {
+ return addListener(ValueChangeEvent.class, listener,
+ ValueChangeListener.VALUE_CHANGE_METHOD);
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly();
+ }
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ }
+
+ @Override
+ public boolean isRequiredIndicatorVisible() {
+ return super.isRequiredIndicatorVisible();
+ }
+
+ @Override
+ public void setRequiredIndicatorVisible(boolean visible) {
+ super.setRequiredIndicatorVisible(visible);
+ }
+
+ @Override
+ public void setComponentError(ErrorMessage componentError) {
+ label.setComponentError(componentError);
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid<Person> personGrid = new Grid<>();
+ personGrid.setItems(Person.createTestPerson1(),
+ Person.createTestPerson2());
+ personGrid.addColumn(Person::getAddress)
+ .setRenderer(
+ address -> address.getCity() + " "
+ + address.getCountry().name(),
+ new TextRenderer())
+ .setCaption("Address")
+ .setEditorComponent(new AddressField(), Person::setAddress);
+ personGrid.getEditor().setEnabled(true);
+ addComponent(personGrid);
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnPresentationTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnPresentationTest.java
new file mode 100644
index 0000000000..79233dc50d
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnPresentationTest.java
@@ -0,0 +1,27 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.parallel.TestCategory;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+@TestCategory("grid")
+public class GridColumnPresentationTest extends SingleBrowserTest {
+
+ @Test
+ public void presenterAndEditor() {
+ openTestURL();
+ GridElement grid = $(GridElement.class).get(0);
+ assertEquals("Turku FINLAND", grid.getCell(0, 0).getText());
+ assertEquals("Amsterdam NETHERLANDS", grid.getCell(1, 0).getText());
+ //Activate editor
+ GridElement.GridCellElement cell = grid.getCell(1, 0);
+ cell.doubleClick();
+
+ assertEquals("Address [streetAddress=Red street, postalCode=12, city=Amsterdam, country=Netherlands]",
+ grid.getEditor().getField(0).getText());
+
+ }
+}