]> source.dussan.org Git - vaadin-framework.git/commitdiff
Calculate column widths immediately if there is data (#20269)
authorArtur Signell <artur@vaadin.com>
Fri, 9 Sep 2016 19:28:15 +0000 (22:28 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 14 Sep 2016 07:50:50 +0000 (07:50 +0000)
Deferring the column width calculations, like done before,
causes flickering as each column is first rendered with its
minimum required width.

Change-Id: I02e6951a99dcb0cb9ad78a95915076d064fa9642

client/src/main/java/com/vaadin/client/widgets/Grid.java
uitest/src/main/java/com/vaadin/tests/components/grid/InitiallyDisabledGrid.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/grid/InitiallyDisabledGridTest.java [new file with mode: 0644]

index 7e5838be400557f3e1732099b3d9da0baa61a0d9..69eec13d28b16e4655e30b7633fdd2f501e847ae 100644 (file)
@@ -3177,7 +3177,9 @@ public class Grid<T> extends ResizeComposite implements
                         rescheduleCount = 0;
                         Scheduler.get().scheduleDeferred(this);
                     }
-                } else if (dataIsBeingFetched) {
+                } else if (currentDataAvailable.isEmpty()
+                        && dataIsBeingFetched) {
+                    // No data available yet but something is incoming soon
                     Scheduler.get().scheduleDeferred(this);
                 } else {
                     calculate();
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/InitiallyDisabledGrid.java b/uitest/src/main/java/com/vaadin/tests/components/grid/InitiallyDisabledGrid.java
new file mode 100644 (file)
index 0000000..41f8eb0
--- /dev/null
@@ -0,0 +1,85 @@
+package com.vaadin.tests.components.grid;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+public class InitiallyDisabledGrid extends UI {
+
+    public static class NotAPersonJustStringAndInt {
+        private String name;
+
+        public NotAPersonJustStringAndInt() {
+        }
+
+        public NotAPersonJustStringAndInt(String string, int i) {
+            name = string;
+            age = i;
+        }
+
+        public int getAge() {
+            return age;
+        }
+
+        public void setAge(int age) {
+            this.age = age;
+        }
+
+        private int age;
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getName() {
+            return name;
+        }
+    }
+
+    @Override
+    protected void init(VaadinRequest request) {
+        VerticalLayout layout = new VerticalLayout();
+        setContent(layout);
+        layout.setSizeFull();
+        layout.setWidth("600px");
+        layout.setHeight("600px");
+        final Grid g = createGrid();
+        Button button = new Button("Sample button");
+
+        layout.addComponent(button);
+        VerticalLayout l = new VerticalLayout();
+        l.setSizeFull();
+        l.addComponent(g);
+
+        layout.addComponent(l);
+        layout.setExpandRatio(l, 1.0f);
+    }
+
+    private Grid createGrid() {
+        // Have some data
+        Collection<NotAPersonJustStringAndInt> people = new ArrayList<NotAPersonJustStringAndInt>();
+        for (int i = 0; i < 100; i++) {
+            people.add(new NotAPersonJustStringAndInt("A " + i, i));
+        }
+        // Have a container of some type to contain the data
+        BeanItemContainer<NotAPersonJustStringAndInt> container = new BeanItemContainer<NotAPersonJustStringAndInt>(
+                NotAPersonJustStringAndInt.class, people);
+
+        // Create a grid bound to the container
+        Grid grid = new Grid(container);
+        grid.setSizeFull();
+        grid.setColumnOrder("name", "age");
+
+        grid.setEnabled(false);
+
+        return grid;
+
+    }
+
+}
\ No newline at end of file
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/InitiallyDisabledGridTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/InitiallyDisabledGridTest.java
new file mode 100644 (file)
index 0000000..1f9aad8
--- /dev/null
@@ -0,0 +1,22 @@
+package com.vaadin.tests.components.grid;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class InitiallyDisabledGridTest extends SingleBrowserTest {
+
+    @Test
+    public void columnsExpanded() {
+        openTestURL();
+
+        GridElement grid = $(GridElement.class).first();
+        GridCellElement col0 = grid.getCell(0, 0);
+        GridCellElement col1 = grid.getCell(0, 1);
+        Assert.assertTrue(col0.getSize().getWidth() > 250);
+        Assert.assertTrue(col1.getSize().getWidth() > 250);
+    }
+}