]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add handling for completely empty Grid's column width calculations. (#11569)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Tue, 14 May 2019 12:05:12 +0000 (15:05 +0300)
committerSun Zhe <31067185+ZheSun88@users.noreply.github.com>
Tue, 14 May 2019 12:05:12 +0000 (15:05 +0300)
Fixes #11557

client/src/main/java/com/vaadin/client/widgets/Escalator.java
uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRowsOrHeaders.java [new file with mode: 0644]

index c559c36c1859d989bdc973f2a907061ae30df934..c60358e449e84aedfe369cb56daf88652ad7f88d 100644 (file)
@@ -4669,6 +4669,9 @@ public class Escalator extends Widget
 
             double maxWidth = Math.max(headerWidth,
                     Math.max(bodyWidth, footerWidth));
+            if (maxWidth < 0 && header.getRowCount() == 0 && body.getRowCount() == 0 && footer.getRowCount() == 0) {
+                maxWidth = 0;
+            }
             assert maxWidth >= 0 : "Got a negative max width for a column, which should be impossible.";
             return maxWidth;
         }
@@ -4681,7 +4684,10 @@ public class Escalator extends Widget
 
             double minWidth = Math.max(headerWidth,
                     Math.max(bodyWidth, footerWidth));
-            assert minWidth >= 0 : "Got a negative max width for a column, which should be impossible.";
+            if (minWidth < 0 && header.getRowCount() == 0 && body.getRowCount() == 0 && footer.getRowCount() == 0) {
+                minWidth = 0;
+            }
+            assert minWidth >= 0 : "Got a negative min width for a column, which should be impossible.";
             return minWidth;
         }
 
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRowsOrHeaders.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRowsOrHeaders.java
new file mode 100644 (file)
index 0000000..cc74696
--- /dev/null
@@ -0,0 +1,60 @@
+package com.vaadin.tests.components.grid;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.SelectionMode;
+
+/**
+ * There is no corresponding TB test as this problem can only be reproduced
+ * using SuperDevMode.
+ */
+public class GridWithoutRowsOrHeaders extends AbstractTestUI {
+
+    private int counter = 0;
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        List<Integer> data = new ArrayList<>();
+
+        Grid<Integer> grid = new Grid<>();
+        grid.addColumn(Integer::valueOf).setCaption("ID").setId("id")
+                .setMaximumWidth(50d);
+        grid.addColumn(Integer::valueOf).setCaption("FOO").setId("foo")
+                .setMinimumWidth(50d);
+        grid.removeHeaderRow(grid.getHeaderRow(0));
+        grid.setItems(data);
+
+        grid.setSelectionMode(SelectionMode.NONE);
+        grid.setWidth("250px");
+        grid.setHeightByRows(3);
+        addComponent(grid);
+
+        addComponent(new Button("Add header row", e -> {
+            grid.addHeaderRowAt(0);
+        }));
+        addComponent(new Button("Add body row", e -> {
+            data.add(counter);
+            ++counter;
+            grid.getDataProvider().refreshAll();
+        }));
+        addComponent(new Button("Add footer row", e -> {
+            grid.addFooterRowAt(0);
+        }));
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "There should be no client-side assertion error from "
+                + "adding the Grid without contents (requires SuperDevMode).";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 11557;
+    }
+}