From 6e35854213946f2400f50d9e1d1dee04b5c84cb2 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Thu, 18 Dec 2014 18:28:49 +0200 Subject: Fix indexing when adding rows to AbstractRemoteDataSource (#13334) Change-Id: Ifa7c8dacb71d2f6ff612e3801b869652fa0a7bc7 --- .../client/data/AbstractRemoteDataSource.java | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java b/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java index 26b60bd2ae..6799c0bd23 100644 --- a/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java +++ b/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java @@ -502,7 +502,16 @@ public abstract class AbstractRemoteDataSource implements DataSource { size += count; - if (cached.contains(firstRowIndex)) { + if (firstRowIndex < cached.getStart()) { + Range oldCached = cached; + cached = cached.offsetBy(count); + + for (int i = 1; i <= indexToRowMap.size(); i++) { + int oldIndex = oldCached.getEnd() - i; + int newIndex = cached.getEnd() - i; + moveRowFromIndexToIndex(oldIndex, newIndex); + } + } else if (cached.contains(firstRowIndex)) { int oldCacheEnd = cached.getEnd(); /* * We need to invalidate the cache from the inserted row onwards, @@ -519,18 +528,6 @@ public abstract class AbstractRemoteDataSource implements DataSource { keyToIndexMap.remove(getRowKey(row)); } } - - else if (firstRowIndex < cached.getStart()) { - Range oldCached = cached; - cached = cached.offsetBy(count); - - for (int i = 0; i < indexToRowMap.size(); i++) { - int oldIndex = oldCached.getEnd() - i; - int newIndex = cached.getEnd() - i; - moveRowFromIndexToIndex(oldIndex, newIndex); - } - } - assertDataChangeHandlerIsInjected(); dataChangeHandler.dataAdded(firstRowIndex, count); ensureCoverageCheck(); @@ -545,7 +542,9 @@ public abstract class AbstractRemoteDataSource implements DataSource { keyToIndexMap.remove(getRowKey(indexToRowMap.get(newIndex))); } indexToRowMap.put(newIndex, row); - keyToIndexMap.put(getRowKey(row), newIndex); + if (row != null) { + keyToIndexMap.put(getRowKey(row), newIndex); + } } /** -- cgit v1.2.3