summaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com/vaadin
diff options
context:
space:
mode:
authorJohannes Tuikkala <johannes@vaadin.com>2017-04-20 12:42:52 +0300
committerIlia Motornyi <elmot@vaadin.com>2017-04-20 11:42:52 +0200
commit779c260b674705a86235f76b5d38685b2062b193 (patch)
tree43aa4938866146054e615670a736122777ffd869 /uitest/src/main/java/com/vaadin
parent2d9fb530cced8a4329a57293d308760b424af067 (diff)
downloadvaadin-framework-779c260b674705a86235f76b5d38685b2062b193.tar.gz
vaadin-framework-779c260b674705a86235f76b5d38685b2062b193.zip
Fix removing rows over the cached range in Grid
Fixes #8840 for 7.7
Diffstat (limited to 'uitest/src/main/java/com/vaadin')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridRemoveCachedRows.java92
1 files changed, 92 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridRemoveCachedRows.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridRemoveCachedRows.java
new file mode 100644
index 0000000000..fcd33add30
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridRemoveCachedRows.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.grid.HeightMode;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+
+@SuppressWarnings("serial")
+public class GridRemoveCachedRows extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+
+ List<String> columnIds = Arrays.asList("Hello", "this", "are",
+ "multiple", "columns", "plus", "these", "resemble", "a",
+ "group", "here", "no", "more");
+
+ final Grid grid = new Grid(new CustomIndexedContainer());
+ grid.setHeightMode(HeightMode.ROW);
+ grid.setHeightByRows(20);
+ for (String columnId : columnIds) {
+ ((CustomIndexedContainer) grid.getContainerDataSource())
+ .addContainerProperty(columnId, String.class, "");
+ }
+
+ // add a lot of rows to make sure that at least some of them are cached
+ for (int i = 0; i < 400; i++) {
+ grid.addRow(columnIds.toArray());
+ }
+
+ Button removeRowsButton = new Button("Remove a cached row");
+ removeRowsButton.addClickListener(new Button.ClickListener() {
+ @Override
+ public void buttonClick(Button.ClickEvent event) {
+ // remove a range of items starting from the visible items and
+ // ending into the cached items
+ ((CustomIndexedContainer) grid.getContainerDataSource())
+ .removeItemRange(10, 300);
+ }
+ });
+
+ addComponents(grid, removeRowsButton);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Test what happens when item range (starting from visible and ending to cached items) is removed from Grid.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 8840;
+ }
+
+ /**
+ * Customised IndexedContainer for removing item range
+ */
+ public class CustomIndexedContainer extends IndexedContainer {
+ public void removeItemRange(int startIndex, int count) {
+ Object firstItem = null;
+
+ for (int index = startIndex; index < startIndex + count; index++) {
+ Object itemId = getIdByIndex(startIndex);
+ getAllItemIds().remove(itemId);
+ if (firstItem == null) {
+ firstItem = itemId;
+ }
+ }
+ fireItemsRemoved(startIndex, firstItem, count);
+ }
+ }
+}