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 /server | |
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 'server')
-rw-r--r-- | server/src/com/vaadin/server/communication/data/typed/DataProvider.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/server/src/com/vaadin/server/communication/data/typed/DataProvider.java b/server/src/com/vaadin/server/communication/data/typed/DataProvider.java index 60cf17ab57..41cdb95dba 100644 --- a/server/src/com/vaadin/server/communication/data/typed/DataProvider.java +++ b/server/src/com/vaadin/server/communication/data/typed/DataProvider.java @@ -79,6 +79,7 @@ public class DataProvider<T> extends AbstractExtension { private Collection<T> data; private Collection<TypedDataGenerator<T>> generators = new LinkedHashSet<TypedDataGenerator<T>>(); + private DataProviderClientRpc rpc; /** * Creates a new DataProvider with the given Collection. @@ -88,6 +89,8 @@ public class DataProvider<T> extends AbstractExtension { */ protected DataProvider(Collection<T> data) { this.data = data; + + rpc = getRpcProxy(DataProviderClientRpc.class); registerRpc(createRpc()); } @@ -142,7 +145,7 @@ public class DataProvider<T> extends AbstractExtension { data.set(i++, getDataObject(item)); } - getRpcProxy(DataProviderClientRpc.class).setData(firstIndex, data); + rpc.setData(firstIndex, data); } /** @@ -173,4 +176,25 @@ public class DataProvider<T> extends AbstractExtension { return new DataRequestRpcImpl(); } + /** + * Informs the DataProvider that an item has been added. It is assumed to be + * the last item in the collection. + * + * @param item + * item added to collection + */ + public void add(T item) { + rpc.add(getDataObject(item)); + } + + /** + * Informs the DataProvider that an item has been removed. + * + * @param item + * item removed from collection + */ + public void remove(T item) { + rpc.drop(getDataObject(item)); + } + } |