summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2014-08-05 11:27:08 +0300
committerVaadin Code Review <review@vaadin.com>2014-08-19 10:57:06 +0000
commit448619c5168603c134ad4d578bae1d577b00b543 (patch)
tree75289ae0b0e525f4d1c81cce62a7a49ef196c364 /server
parent5dfdd40d00dc0f7a2eea19f8c77485f1afcf77ad (diff)
downloadvaadin-framework-448619c5168603c134ad4d578bae1d577b00b543.tar.gz
vaadin-framework-448619c5168603c134ad4d578bae1d577b00b543.zip
Sending a drag select over the wire in a batch (#13334)
Change-Id: I49a518b484557d232542e999a2f41ffad3cc7568
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/data/RpcDataProviderExtension.java69
-rw-r--r--server/src/com/vaadin/ui/components/grid/Grid.java4
2 files changed, 69 insertions, 4 deletions
diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java
index f731e4575d..86fa11f62e 100644
--- a/server/src/com/vaadin/data/RpcDataProviderExtension.java
+++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java
@@ -53,6 +53,8 @@ import com.vaadin.shared.ui.grid.Range;
import com.vaadin.ui.components.grid.Grid;
import com.vaadin.ui.components.grid.GridColumn;
import com.vaadin.ui.components.grid.Renderer;
+import com.vaadin.ui.components.grid.selection.SelectionChangeEvent;
+import com.vaadin.ui.components.grid.selection.SelectionChangeListener;
/**
* Provides Vaadin server-side container data source to a
@@ -107,10 +109,10 @@ public class RpcDataProviderExtension extends AbstractExtension {
final Integer ii = Integer.valueOf(i);
final Object itemId = indexToItemId.get(ii);
- if (!pinnedItemIds.contains(itemId)) {
+ if (!isPinned(itemId)) {
itemIdToKey.remove(itemId);
+ indexToItemId.remove(ii);
}
- indexToItemId.remove(ii);
}
}
@@ -610,9 +612,21 @@ public class RpcDataProviderExtension extends AbstractExtension {
this.container = container;
registerRpc(new DataRequestRpc() {
+ private Collection<String> allTemporarilyPinnedKeys = new ArrayList<String>();
+
@Override
public void requestRows(int firstRow, int numberOfRows,
- int firstCachedRowIndex, int cacheSize) {
+ int firstCachedRowIndex, int cacheSize,
+ List<String> temporarilyPinnedKeys) {
+
+ for (String key : temporarilyPinnedKeys) {
+ Object itemId = keyMapper.getItemId(key);
+ if (!keyMapper.isPinned(itemId)) {
+ keyMapper.pin(itemId);
+ }
+ }
+ allTemporarilyPinnedKeys.addAll(temporarilyPinnedKeys);
+
Range active = Range.withLength(firstRow, numberOfRows);
if (cacheSize != 0) {
Range cached = Range.withLength(firstCachedRowIndex,
@@ -628,6 +642,55 @@ public class RpcDataProviderExtension extends AbstractExtension {
activeRowHandler.setActiveRows(active.getStart(),
active.length());
}
+
+ @Override
+ public void releaseTemporarilyPinnedKeys() {
+ /*
+ * This needs to be done deferredly since the selection event
+ * comes after this RPC call.
+ */
+
+ final SelectionChangeListener listener = new SelectionChangeListener() {
+ @Override
+ public void selectionChange(SelectionChangeEvent event) {
+ for (String tempPinnedKey : allTemporarilyPinnedKeys) {
+ /*
+ * TODO: this could be moved into a field instead of
+ * inline to reduce indentations.
+ */
+
+ /*
+ * This works around the fact that when deselecting
+ * and leaping through the cache, the client tries
+ * to send a deselect event even though a row never
+ * was selected. So, it tries to unpin something
+ * that never was temporarily pinned.
+ *
+ * If the same thing would happen while selecting
+ * (instead of deselecting), the row would be
+ * pinned, not because of the temporary pinning, but
+ * because it's selected.
+ */
+ if (!keyMapper.isPinned(tempPinnedKey)) {
+ continue;
+ }
+
+ Object itemId = keyMapper.getItemId(tempPinnedKey);
+ Integer index = keyMapper.indexToItemId.inverse()
+ .get(itemId);
+ if (!getGrid().isSelected(itemId)
+ && !activeRowHandler.activeRange
+ .contains(index.intValue())) {
+ keyMapper.unpin(itemId);
+ }
+ }
+ allTemporarilyPinnedKeys = new ArrayList<String>();
+ getGrid().removeSelectionChangeListener(this);
+ }
+ };
+
+ getGrid().addSelectionChangeListener(listener);
+ }
});
getState().containerSize = container.size();
diff --git a/server/src/com/vaadin/ui/components/grid/Grid.java b/server/src/com/vaadin/ui/components/grid/Grid.java
index d365d3e0cc..fba6eed462 100644
--- a/server/src/com/vaadin/ui/components/grid/Grid.java
+++ b/server/src/com/vaadin/ui/components/grid/Grid.java
@@ -282,7 +282,9 @@ public class Grid extends AbstractComponent implements SelectionChangeNotifier,
}
for (Object addedItemId : event.getAdded()) {
- getKeyMapper().pin(addedItemId);
+ if (!getKeyMapper().isPinned(addedItemId)) {
+ getKeyMapper().pin(addedItemId);
+ }
}
List<String> keys = getKeyMapper().getKeys(getSelectedRows());