diff options
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnPresentation.java | 99 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnPresentationTest.java | 27 |
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()); + + } +} |