From 918ad6f8bf40fda89c60b8b680e02d5c79efdffd Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Fri, 29 Jan 2016 15:51:33 +0200 Subject: 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 --- .../communication/data/typed/DataProvider.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'server') 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 extends AbstractExtension { private Collection data; private Collection> generators = new LinkedHashSet>(); + private DataProviderClientRpc rpc; /** * Creates a new DataProvider with the given Collection. @@ -88,6 +89,8 @@ public class DataProvider extends AbstractExtension { */ protected DataProvider(Collection data) { this.data = data; + + rpc = getRpcProxy(DataProviderClientRpc.class); registerRpc(createRpc()); } @@ -142,7 +145,7 @@ public class DataProvider extends AbstractExtension { data.set(i++, getDataObject(item)); } - getRpcProxy(DataProviderClientRpc.class).setData(firstIndex, data); + rpc.setData(firstIndex, data); } /** @@ -173,4 +176,25 @@ public class DataProvider 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)); + } + } -- cgit v1.2.3