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;
// 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);
}
--- /dev/null
+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
--- /dev/null
+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