summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-07-08 19:25:41 +0300
committerTeemu Suo-Anttila <teemusa@vaadin.com>2015-07-09 10:08:13 +0300
commit07523f1da87036e147ff99d3df551e4740f52090 (patch)
tree6f90eb777dd55554b40251d967c49d50bdd02b25
parent1a8901655111addd064490946aed64ed5784710c (diff)
downloadvaadin-framework-07523f1da87036e147ff99d3df551e4740f52090.tar.gz
vaadin-framework-07523f1da87036e147ff99d3df551e4740f52090.zip
Fix Grid detaching with open details rows (#18415)
Change-Id: I68f5edcfc48063419109b1f3b3f61853db5cfd1a
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java9
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridDetailsDetach.java138
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridDetailsDetachTest.java41
3 files changed, 188 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java
index 28527d7a86..6d9e5d18ec 100644
--- a/client/src/com/vaadin/client/widgets/Grid.java
+++ b/client/src/com/vaadin/client/widgets/Grid.java
@@ -7648,6 +7648,15 @@ public class Grid<T> extends ResizeComposite implements
}
@Override
+ protected void onDetach() {
+ for (int row : visibleDetails) {
+ setDetailsVisible(row, false);
+ }
+
+ super.onDetach();
+ }
+
+ @Override
public void onResize() {
super.onResize();
/*
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetach.java b/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetach.java
new file mode 100644
index 0000000000..c25ad287b7
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetach.java
@@ -0,0 +1,138 @@
+/*
+ * 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 com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.event.ItemClickEvent;
+import com.vaadin.event.ItemClickEvent.ItemClickListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.DetailsGenerator;
+import com.vaadin.ui.Grid.RowReference;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+
+public class GridDetailsDetach extends AbstractTestUI {
+
+ private Grid currentGrid;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final VerticalLayout layout = new VerticalLayout();
+ layout.setSizeFull();
+
+ Button button = new Button("Test");
+ layout.addComponent(button);
+ layout.setExpandRatio(button, 0f);
+
+ currentGrid = generateGrid();
+ layout.addComponent(currentGrid);
+ layout.setExpandRatio(currentGrid, 1f);
+
+ button.addClickListener(new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Grid newGrid = generateGrid();
+ layout.replaceComponent(currentGrid, newGrid);
+ currentGrid = newGrid;
+ }
+ });
+
+ addComponent(layout);
+ }
+
+ private Grid generateGrid() {
+ BeanItemContainer<GridExampleBean> container = new BeanItemContainer<GridExampleBean>(
+ GridExampleBean.class);
+ for (int i = 0; i < 1000; i++) {
+ container.addItem(new GridExampleBean("Bean " + i, i * i, i / 10d));
+ }
+
+ final Grid grid = new Grid(container);
+ grid.setColumnOrder("name", "amount", "count");
+ grid.setSizeFull();
+
+ grid.setDetailsGenerator(new DetailsGenerator() {
+ @Override
+ public Component getDetails(RowReference rowReference) {
+ final GridExampleBean bean = (GridExampleBean) rowReference
+ .getItemId();
+ VerticalLayout layout = new VerticalLayout(new Label(
+ "Extra data for " + bean.getName()));
+ layout.setMargin(true);
+ return layout;
+ }
+ });
+
+ grid.addItemClickListener(new ItemClickListener() {
+ @Override
+ public void itemClick(ItemClickEvent event) {
+ Object itemId = event.getItemId();
+ grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId));
+ }
+ });
+ return grid;
+ }
+
+ public class GridExampleBean {
+
+ private String name;
+
+ private int count;
+
+ private double amount;
+
+ public GridExampleBean() {
+ }
+
+ public GridExampleBean(String name, int count, double amount) {
+ this.name = name;
+ this.count = count;
+ this.amount = amount;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public double getAmount() {
+ return amount;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public void setAmount(double amount) {
+ this.amount = amount;
+ }
+
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetachTest.java b/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetachTest.java
new file mode 100644
index 0000000000..f9071dd3da
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetachTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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 org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.parallel.TestCategory;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+@TestCategory("grid")
+public class GridDetailsDetachTest extends MultiBrowserTest {
+
+ @Test
+ public void testDetachGridWithDetailsOpen() {
+ setDebug(true);
+ openTestURL();
+
+ $(GridElement.class).first().getCell(3, 0).click();
+
+ assertNoErrorNotifications();
+
+ $(ButtonElement.class).first().click();
+
+ assertNoErrorNotifications();
+ }
+}