]> source.dussan.org Git - vaadin-framework.git/commitdiff
Re-add body rows when Escalator is reattached to DOM (#20477)
authorArtur Signell <artur@vaadin.com>
Thu, 24 Nov 2016 09:31:23 +0000 (11:31 +0200)
committerVaadin Code Review <review@vaadin.com>
Mon, 28 Nov 2016 06:49:13 +0000 (06:49 +0000)
Change-Id: I0ae9144817db3bb730c80748d5e9190484b323e7

client/src/main/java/com/vaadin/client/widgets/Escalator.java
uitest/src/main/java/com/vaadin/tests/components/grid/MoveGridAndAddRow.java [new file with mode: 0644]
uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java
uitest/src/test/java/com/vaadin/tests/components/grid/MoveGridAndAddRowTest.java [new file with mode: 0644]

index 39f996aa8418df26bd6993d61ea6495321a61369..4bd61cb53c3d1f8e25bfcd1380b75776b2cae3f0 100644 (file)
@@ -5791,40 +5791,6 @@ public class Escalator extends Widget
         header.paintInsertRows(0, header.getRowCount());
         footer.paintInsertRows(0, footer.getRowCount());
 
-        // recalculateElementSizes();
-
-        Scheduler.get().scheduleDeferred(new Command() {
-            @Override
-            public void execute() {
-                /*
-                 * Not a faintest idea why we have to defer this call, but
-                 * unless it is deferred, the size of the escalator will be 0x0
-                 * after it is first detached and then reattached to the DOM.
-                 * This only applies to a bare Escalator; inside a Grid
-                 * everything works fine either way.
-                 *
-                 * The three autodetectRowHeightLater calls above seem obvious
-                 * suspects at first. However, they don't seem to have anything
-                 * to do with the issue, as they are no-ops in the
-                 * detach-reattach case.
-                 */
-                recalculateElementSizes();
-            }
-        });
-
-        /*
-         * Note: There's no need to explicitly insert rows into the body.
-         *
-         * recalculateElementSizes will recalculate the height of the body. This
-         * has the side-effect that as the body's size grows bigger (i.e. from 0
-         * to its actual height), more escalator rows are populated. Those
-         * escalator rows are then immediately rendered. This, in effect, is the
-         * same thing as inserting those rows.
-         *
-         * In fact, having an extra paintInsertRows here would lead to duplicate
-         * rows.
-         */
-
         boolean columnsChanged = false;
         for (ColumnConfigurationImpl.Column column : columnConfiguration.columns) {
             boolean columnChanged = column.measureAndSetWidthIfNeeded();
@@ -5851,6 +5817,20 @@ public class Escalator extends Widget
         } else {
             scroller.attachTouchListeners(getElement());
         }
+
+        /*
+         * Note: There's no need to explicitly insert rows into the body.
+         *
+         * recalculateElementSizes will recalculate the height of the body. This
+         * has the side-effect that as the body's size grows bigger (i.e. from 0
+         * to its actual height), more escalator rows are populated. Those
+         * escalator rows are then immediately rendered. This, in effect, is the
+         * same thing as inserting those rows.
+         *
+         * In fact, having an extra paintInsertRows here would lead to duplicate
+         * rows.
+         */
+        recalculateElementSizes();
     }
 
     @Override
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/MoveGridAndAddRow.java b/uitest/src/main/java/com/vaadin/tests/components/grid/MoveGridAndAddRow.java
new file mode 100644 (file)
index 0000000..0c6379b
--- /dev/null
@@ -0,0 +1,48 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+
+public class MoveGridAndAddRow extends AbstractTestUIWithLog {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        final VerticalLayout layout = new VerticalLayout();
+
+        final VerticalLayout anotherLayout = new VerticalLayout();
+        anotherLayout.addComponent(new Label("This is another layout"));
+        final Grid g = new Grid();
+        g.addColumn("A");
+        g.addRow("1");
+
+        final Button b = new Button("Add row and remove this button");
+        b.setId("add");
+        b.addClickListener(new ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent e) {
+                g.addRow("2");
+                b.setVisible(false);
+            }
+        });
+
+        Button move = new Button("Move grid to other layout");
+        move.setId("move");
+        move.addClickListener(new ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent event) {
+                anotherLayout.addComponent(g);
+            }
+        });
+
+        layout.addComponents(b, move, g);
+        addComponent(new HorizontalLayout(layout, anotherLayout));
+
+    }
+}
index f39c8119bea8e28099d637a920d72c5bc85dcd2a..8c456f1c7e26091970534a893affcf5fc8476a58 100644 (file)
@@ -379,9 +379,25 @@ public class EscalatorBasicClientFeaturesWidget
         String[] menupath = { GENERAL_MENU };
 
         addMenuCommand("Detach Escalator", new ScheduledCommand() {
+
             @Override
             public void execute() {
+                // DockLayoutPanel removes height and width definitions on
+                // detach, so store them and restore them in attach to keep
+                // Escalator the same size
+                String detachHeight = escalator.getElement().getStyle()
+                        .getHeight();
+                String detachWidth = escalator.getElement().getStyle()
+                        .getWidth();
                 escalator.removeFromParent();
+                if (detachHeight != null) {
+                    escalator.getElement().getStyle().setProperty("height",
+                            detachHeight);
+                }
+                if (detachWidth != null) {
+                    escalator.getElement().getStyle().setProperty("width",
+                            detachWidth);
+                }
             }
         }, menupath);
 
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/MoveGridAndAddRowTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/MoveGridAndAddRowTest.java
new file mode 100644 (file)
index 0000000..c6d9aa3
--- /dev/null
@@ -0,0 +1,21 @@
+package com.vaadin.tests.components.grid;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class MoveGridAndAddRowTest extends SingleBrowserTest {
+
+    @Test
+    public void addRowAndChangeLayout() {
+        openTestURL();
+        $(ButtonElement.class).id("add").click();
+
+        GridElement grid = $(GridElement.class).first();
+        Assert.assertEquals("1", grid.getCell(0, 0).getText());
+        Assert.assertEquals("2", grid.getCell(1, 0).getText());
+    }
+}