diff options
-rw-r--r-- | client/src/com/vaadin/client/data/AbstractRemoteDataSource.java | 27 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java | 12 |
2 files changed, 25 insertions, 14 deletions
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<T> implements DataSource<T> { 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<T> implements DataSource<T> { 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<T> implements DataSource<T> { keyToIndexMap.remove(getRowKey(indexToRowMap.get(newIndex))); } indexToRowMap.put(newIndex, row); - keyToIndexMap.put(getRowKey(row), newIndex); + if (row != null) { + keyToIndexMap.put(getRowKey(row), newIndex); + } } /** diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java index 3603d62e78..37e92830f3 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java @@ -367,6 +367,18 @@ public class GridStructureTest extends GridBasicFeaturesTest { "overflow-y")); } + @Test + public void testAddRowAboveViewport() { + setDebug(true); + openTestURL(); + + getGridElement().scrollToRow(500); + selectMenuPath("Component", "Body rows", "Add first row"); + + assertFalse("Error notification was present", + isElementPresent(NotificationElement.class)); + } + private void assertPrimaryStylename(String stylename) { assertTrue(getGridElement().getAttribute("class").contains(stylename)); |