summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/data
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2013-12-17 11:08:25 +0200
committerHenrik Paul <henrik@vaadin.com>2013-12-17 11:08:25 +0200
commit7670a020c7447d7ae2fe2c3e1fb1fa966b138e65 (patch)
tree039d1fddc555ac9ddb34cd36c42d4a231e3a47c3 /server/src/com/vaadin/data
parent887eead6bfa56de25f5b6514b2eafe698b3e9947 (diff)
downloadvaadin-framework-7670a020c7447d7ae2fe2c3e1fb1fa966b138e65.tar.gz
vaadin-framework-7670a020c7447d7ae2fe2c3e1fb1fa966b138e65.zip
Grid supports data set changes (#12645)
Change-Id: I5ceb52dea079f48b0065c1b2dbdc35b30fe8c4ee
Diffstat (limited to 'server/src/com/vaadin/data')
-rw-r--r--server/src/com/vaadin/data/RpcDataProviderExtension.java71
1 files changed, 59 insertions, 12 deletions
diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java
index 48f03b98c0..b22e6a209b 100644
--- a/server/src/com/vaadin/data/RpcDataProviderExtension.java
+++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java
@@ -18,6 +18,7 @@ package com.vaadin.data;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import com.vaadin.data.Container.Indexed;
@@ -67,22 +68,24 @@ public class RpcDataProviderExtension extends AbstractExtension {
Collection<?> propertyIds = container.getContainerPropertyIds();
List<String[]> rows = new ArrayList<String[]>(itemIds.size());
for (Object itemId : itemIds) {
- Item item = container.getItem(itemId);
- String[] row = new String[propertyIds.size()];
-
- int i = 0;
- for (Object propertyId : propertyIds) {
- Object value = item.getItemProperty(propertyId).getValue();
- String stringValue = String.valueOf(value);
- row[i++] = stringValue;
- }
-
- rows.add(row);
+ rows.add(getRowData(propertyIds, itemId));
}
-
getRpcProxy(DataProviderRpc.class).setRowData(firstRow, rows);
}
+ private String[] getRowData(Collection<?> propertyIds, Object itemId) {
+ Item item = container.getItem(itemId);
+ String[] row = new String[propertyIds.size()];
+
+ int i = 0;
+ for (Object propertyId : propertyIds) {
+ Object value = item.getItemProperty(propertyId).getValue();
+ String stringValue = String.valueOf(value);
+ row[i++] = stringValue;
+ }
+ return row;
+ }
+
@Override
protected DataProviderState getState() {
return (DataProviderState) super.getState();
@@ -98,4 +101,48 @@ public class RpcDataProviderExtension extends AbstractExtension {
super.extend(component);
}
+ /**
+ * Informs the client side that new rows have been inserted into the data
+ * source.
+ *
+ * @param index
+ * the index at which new rows have been inserted
+ * @param count
+ * the number of rows inserted at <code>index</code>
+ */
+ public void insertRowData(int index, int count) {
+ getState().containerSize += count;
+ getRpcProxy(DataProviderRpc.class).insertRowData(index, count);
+ }
+
+ /**
+ * Informs the client side that rows have been removed from the data source.
+ *
+ * @param firstIndex
+ * the index of the first row removed
+ * @param count
+ * the number of rows removed
+ */
+ public void removeRowData(int firstIndex, int count) {
+ getState().containerSize -= count;
+ getRpcProxy(DataProviderRpc.class).removeRowData(firstIndex, count);
+ }
+
+ /**
+ * Informs the client side that data of a row has been modified in the data
+ * source.
+ *
+ * @param index
+ * the index of the row that was updated
+ */
+ public void updateRowData(int index) {
+ /*
+ * TODO: ignore duplicate requests for the same index during the same
+ * roundtrip.
+ */
+ Object itemId = container.getIdByIndex(index);
+ String[] row = getRowData(container.getContainerPropertyIds(), itemId);
+ getRpcProxy(DataProviderRpc.class).setRowData(index,
+ Collections.singletonList(row));
+ }
}