]> source.dussan.org Git - vaadin-framework.git/commitdiff
reopen Grid details on attach, fixes #8015 (#8074)
authorOlli Tietäväinen <ollit@vaadin.com>
Mon, 9 Jan 2017 06:39:57 +0000 (08:39 +0200)
committerDenis <denis@vaadin.com>
Mon, 9 Jan 2017 06:39:57 +0000 (08:39 +0200)
Fixes #8015

client/src/main/java/com/vaadin/client/widgets/Grid.java [changed mode: 0644->0755]
uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsReattach.java [new file with mode: 0755]
uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsReattachTest.java [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index b0735a5..0ce4882
@@ -4138,6 +4138,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
     private GridSpacerUpdater gridSpacerUpdater = new GridSpacerUpdater();
     /** A set keeping track of the indices of all currently open details */
     private Set<Integer> visibleDetails = new HashSet<Integer>();
+    /** A set of indices of details to reopen after detach and on attach */
+    private final Set<Integer> reattachVisibleDetails = new HashSet<Integer>();
 
     private boolean columnReorderingAllowed;
 
@@ -8774,11 +8776,17 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
 
         // Grid was just attached to DOM. Column widths should be calculated.
         recalculateColumnWidths();
+        for (int row : reattachVisibleDetails) {
+            setDetailsVisible(row, true);
+        }
+        reattachVisibleDetails.clear();
     }
 
     @Override
     protected void onDetach() {
         Set<Integer> details = new HashSet<Integer>(visibleDetails);
+        reattachVisibleDetails.clear();
+        reattachVisibleDetails.addAll(details);
         for (int row : details) {
             setDetailsVisible(row, false);
         }
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsReattach.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsReattach.java
new file mode 100755 (executable)
index 0000000..b1a057e
--- /dev/null
@@ -0,0 +1,49 @@
+package com.vaadin.tests.components.grid;\r
+\r
+import com.vaadin.data.util.IndexedContainer;\r
+import com.vaadin.server.VaadinRequest;\r
+import com.vaadin.tests.components.AbstractTestUI;\r
+import com.vaadin.ui.*;\r
+import org.apache.tools.ant.taskdefs.Java;\r
+\r
+public class GridDetailsReattach extends AbstractTestUI {\r
+\r
+       @Override\r
+       protected void setup(VaadinRequest request) {\r
+               final VerticalLayout verticalMain = new VerticalLayout();\r
+\r
+        final VerticalLayout layoutWithGrid = new VerticalLayout();\r
+\r
+        final IndexedContainer container = new IndexedContainer();\r
+        container.addContainerProperty("foo", String.class, "foo");\r
+        container.addItem("bar");\r
+\r
+        Grid grid = new Grid("Grid");\r
+        grid.setHeight("150px");\r
+        grid.setContainerDataSource(container);\r
+        grid.setDetailsGenerator(new Grid.DetailsGenerator() {\r
+            @Override\r
+            public Component getDetails(Grid.RowReference rowReference) {\r
+                return new Label("AnyDetails");\r
+            }\r
+        });\r
+        grid.setDetailsVisible(container.getItemIds().iterator().next(), true);\r
+        layoutWithGrid.addComponent(grid);\r
+\r
+        Button addCaptionToLayoutWithGridButton = new Button("Add caption to 'layoutWithGrid' layout");\r
+        addCaptionToLayoutWithGridButton.addClickListener(new Button.ClickListener() {\r
+\r
+            @Override\r
+            public void buttonClick(Button.ClickEvent event) {\r
+                // This causes a relayout, which detaches and reattaches the grid\r
+               layoutWithGrid.setCaption("Caption added to 'layoutWithGrid' layout");\r
+            }\r
+        });\r
+        layoutWithGrid.addComponent(addCaptionToLayoutWithGridButton);\r
+\r
+        verticalMain.addComponent(layoutWithGrid);\r
+\r
+        addComponent(verticalMain);\r
+               \r
+       }\r
+}\r
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsReattachTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsReattachTest.java
new file mode 100755 (executable)
index 0000000..a6fa1da
--- /dev/null
@@ -0,0 +1,34 @@
+package com.vaadin.tests.components.grid;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.openqa.selenium.By;\r
+\r
+import com.vaadin.testbench.elements.ButtonElement;\r
+import com.vaadin.testbench.parallel.TestCategory;\r
+import com.vaadin.tests.tb3.MultiBrowserTest;\r
+\r
+@TestCategory("grid")\r
+public class GridDetailsReattachTest extends MultiBrowserTest {\r
+\r
+    @Before\r
+    public void setUp() {\r
+        setDebug(true);\r
+    }\r
+\r
+    @Test\r
+    public void clickToAddCaption() {\r
+        openTestURL();\r
+        Assert.assertTrue("Grid details don't exist",  hasDetailsElement());\r
+        $(ButtonElement.class).first().click();\r
+        Assert.assertTrue("Grid details don't exist after deattach and reattach",hasDetailsElement() );\r
+    }\r
+\r
+    private final By locator = By.className("v-grid-spacer");\r
+\r
+    private boolean hasDetailsElement() {\r
+        return !findElements(locator).isEmpty();\r
+    }\r
+\r
+}\r