summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2014-12-18 18:28:49 +0200
committerVaadin Code Review <review@vaadin.com>2014-12-18 21:12:47 +0000
commit6e35854213946f2400f50d9e1d1dee04b5c84cb2 (patch)
tree7d4475a11a1a3b75d7a4b4ee25017b49cde6b08f
parentfe6f23946a39f87c6b67c91c550404024a487043 (diff)
downloadvaadin-framework-6e35854213946f2400f50d9e1d1dee04b5c84cb2.tar.gz
vaadin-framework-6e35854213946f2400f50d9e1d1dee04b5c84cb2.zip
Fix indexing when adding rows to AbstractRemoteDataSource (#13334)
Change-Id: Ifa7c8dacb71d2f6ff612e3801b869652fa0a7bc7
-rw-r--r--client/src/com/vaadin/client/data/AbstractRemoteDataSource.java27
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java12
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));