diff options
4 files changed, 57 insertions, 19 deletions
diff --git a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java index 5680b09cef..79838f3252 100644 --- a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java +++ b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java @@ -107,10 +107,16 @@ public class RpcDataSourceConnector extends AbstractExtensionConnector { private DataRequestRpc rpcProxy = getRpcProxy(DataRequestRpc.class); private DetailsListener detailsListener; + private JsonArray droppedRowKeys = Json.createArray(); @Override protected void requestRows(int firstRowIndex, int numberOfRows, RequestRowsCallback<JsonObject> callback) { + if (droppedRowKeys.length() > 0) { + rpcProxy.dropRows(droppedRowKeys); + droppedRowKeys = Json.createArray(); + } + /* * If you're looking at this code because you want to learn how to * use AbstactRemoteDataSource, please look somewhere else instead. @@ -235,10 +241,8 @@ public class RpcDataSourceConnector extends AbstractExtensionConnector { } @Override - protected void onDropFromCache(int rowIndex) { - super.onDropFromCache(rowIndex); - - rpcProxy.dropRow(getRowKey(getRow(rowIndex))); + protected void onDropFromCache(int rowIndex, JsonObject row) { + droppedRowKeys.set(droppedRowKeys.length(), getRowKey(row)); } } diff --git a/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java b/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java index c8910f8699..256bc5ff6a 100644 --- a/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java +++ b/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java @@ -287,8 +287,7 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> { * Simple case: no overlap between cached data and needed data. * Clear the cache and request new data */ - indexToRowMap.clear(); - keyToIndexMap.clear(); + dropFromCache(cached); cached = Range.between(0, 0); handleMissingRows(getMaxCacheRange()); @@ -330,27 +329,48 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> { private void dropFromCache(Range range) { for (int i = range.getStart(); i < range.getEnd(); i++) { - // Called before dropping from cache, so we can actually do - // something with the data before the drop. - onDropFromCache(i); - + // Called after dropping from cache. Dropped row is passed as a + // parameter, but is no longer present in the DataSource T removed = indexToRowMap.remove(Integer.valueOf(i)); + onDropFromCache(i, removed); keyToIndexMap.remove(getRowKey(removed)); } } /** - * A hook that can be overridden to do something whenever a row is about to - * be dropped from the cache. + * A hook that can be overridden to do something whenever a row has been + * dropped from the cache. DataSource no longer has anything in the given + * index. + * <p> + * NOTE: This method has been replaced. Override + * {@link #onDropFromCache(int, Object)} instead of this method. * * @since 7.5.0 * @param rowIndex * the index of the dropped row + * @deprecated replaced by {@link #onDropFromCache(int, Object)} */ + @Deprecated protected void onDropFromCache(int rowIndex) { // noop } + /** + * A hook that can be overridden to do something whenever a row has been + * dropped from the cache. DataSource no longer has anything in the given + * index. + * + * @since + * @param rowIndex + * the index of the dropped row + * @param removed + * the removed row object + */ + protected void onDropFromCache(int rowIndex, T removed) { + // Call old version as a fallback (someone might have used it) + onDropFromCache(rowIndex); + } + private void handleMissingRows(Range range) { if (range.isEmpty()) { return; @@ -481,6 +501,15 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> { * updated before the widget settings. Support for this will be * implemented later on. */ + + // Run a dummy drop from cache for unused rows. + for (int i = 0; i < partition[0].length(); ++i) { + onDropFromCache(i + partition[0].getStart(), rowData.get(i)); + } + + for (int i = 0; i < partition[2].length(); ++i) { + onDropFromCache(i + partition[2].getStart(), rowData.get(i)); + } } // Eventually check whether all needed rows are now available diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java index 403cc4c016..2ec100eba6 100644 --- a/server/src/com/vaadin/data/RpcDataProviderExtension.java +++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java @@ -123,7 +123,7 @@ public class RpcDataProviderExtension extends AbstractExtension { * the item ids for which to get keys * @return keys for the {@code itemIds} */ - public List<String> getKeys(Collection<Object> itemIds) { + public List<String> getKeys(Collection<?> itemIds) { if (itemIds == null) { throw new IllegalArgumentException("itemIds can't be null"); } @@ -698,8 +698,11 @@ public class RpcDataProviderExtension extends AbstractExtension { } @Override - public void dropRow(String rowKey) { - activeItemHandler.dropActiveItem(keyMapper.getItemId(rowKey)); + public void dropRows(JsonArray rowKeys) { + for (int i = 0; i < rowKeys.length(); ++i) { + activeItemHandler.dropActiveItem(keyMapper + .getItemId(rowKeys.getString(i))); + } } }); diff --git a/shared/src/com/vaadin/shared/data/DataRequestRpc.java b/shared/src/com/vaadin/shared/data/DataRequestRpc.java index 84216f0fab..041e92d05c 100644 --- a/shared/src/com/vaadin/shared/data/DataRequestRpc.java +++ b/shared/src/com/vaadin/shared/data/DataRequestRpc.java @@ -20,6 +20,8 @@ import com.vaadin.shared.annotations.Delayed; import com.vaadin.shared.annotations.NoLoadingIndicator; import com.vaadin.shared.communication.ServerRpc; +import elemental.json.JsonArray; + /** * RPC interface used for requesting container data to the client. * @@ -59,13 +61,13 @@ public interface DataRequestRpc extends ServerRpc { public void setPinned(String key, boolean isPinned); /** - * Informs the server that an item is dropped from the client cache. + * Informs the server that items have been dropped from the client cache. * * @since - * @param rowKey - * key mapping to item + * @param rowKeys + * array of dropped keys mapping to items */ @Delayed @NoLoadingIndicator - public void dropRow(String rowKey); + public void dropRows(JsonArray rowKeys); } |