diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-01-29 15:51:33 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-02-02 18:22:57 +0200 |
commit | 918ad6f8bf40fda89c60b8b680e02d5c79efdffd (patch) | |
tree | b3ced303cfed47f3188e1d72901887d43ea6969b /uitest/src/com | |
parent | d366c3d35160d7c7b8f9cbdd374b0f760beac908 (diff) | |
download | vaadin-framework-918ad6f8bf40fda89c60b8b680e02d5c79efdffd.tar.gz vaadin-framework-918ad6f8bf40fda89c60b8b680e02d5c79efdffd.zip |
Add simple data add/remove support to DataProvider
Removal is currently based on the content of the object. Multiple
objects with same content will cause problems. This should be fixed by
adding a simple key mapping for objects.
Change-Id: Ie6fd1c6bcb7e8eaa73469f8f794f5365b1590fe2
Diffstat (limited to 'uitest/src/com')
-rw-r--r-- | uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java | 48 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DummyDataConnector.java | 8 |
2 files changed, 50 insertions, 6 deletions
diff --git a/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java b/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java index 85ff2e7398..62aa8c2241 100644 --- a/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java +++ b/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java @@ -15,8 +15,9 @@ */ package com.vaadin.tests.dataprovider; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedHashSet; +import java.util.List; import java.util.Random; import com.vaadin.annotations.Widgetset; @@ -27,6 +28,10 @@ import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.fieldgroup.ComplexPerson; import com.vaadin.tests.widgetset.TestingWidgetSet; import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.HorizontalLayout; import elemental.json.JsonObject; @@ -36,8 +41,10 @@ public class DummyDataProviderUI extends AbstractTestUI { public static class DummyDataComponent extends AbstractComponent { private DataProvider<ComplexPerson> dataProvider; + private Collection<ComplexPerson> data; public DummyDataComponent(Collection<ComplexPerson> data) { + this.data = data; dataProvider = DataProvider.create(data, this); dataProvider .addDataGenerator(new TypedDataGenerator<ComplexPerson>() { @@ -52,16 +59,47 @@ public class DummyDataProviderUI extends AbstractTestUI { }); } + void addItem(ComplexPerson person) { + if (data.add(person)) { + dataProvider.add(person); + } + } + + void removeItem(ComplexPerson person) { + if (data.remove(person)) { + dataProvider.remove(person); + } + } } + private Random r = new Random(1337); + private List<ComplexPerson> persons = getPersons(20); + private DummyDataComponent dummy; + @Override protected void setup(VaadinRequest request) { - addComponent(new DummyDataComponent(getPersons(20))); + dummy = new DummyDataComponent(persons); + + Button remove = new Button("Remove third", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + dummy.removeItem(persons.get(2)); + } + }); + Button add = new Button("Add new", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + dummy.addItem(ComplexPerson.create(r)); + } + }); + addComponent(new HorizontalLayout(add, remove)); + addComponent(dummy); } - private Collection<ComplexPerson> getPersons(int count) { - Random r = new Random(1337); - Collection<ComplexPerson> c = new LinkedHashSet<ComplexPerson>(); + private List<ComplexPerson> getPersons(int count) { + List<ComplexPerson> c = new ArrayList<ComplexPerson>(); for (int i = 0; i < count; ++i) { c.add(ComplexPerson.create(r)); } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DummyDataConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DummyDataConnector.java index 4733026bd7..c64f30ab57 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DummyDataConnector.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DummyDataConnector.java @@ -48,6 +48,13 @@ public class DummyDataConnector extends AbstractComponentConnector implements dataSource.setDataChangeHandler(new AbstractDataChangeHandler() { @Override + public void dataRemoved(int firstRowIndex, int numberOfRows) { + for (int i = 0; i < numberOfRows; ++i) { + getWidget().remove(firstRowIndex); + } + } + + @Override public void dataAdded(int firstRowIndex, int numberOfRows) { for (int i = 0; i < numberOfRows; ++i) { getWidget().add( @@ -57,5 +64,4 @@ public class DummyDataConnector extends AbstractComponentConnector implements } }); } - } |