]> source.dussan.org Git - vaadin-framework.git/commitdiff
fix for #12079 - recalculate Composite layout inside Window (#12082)
authorOlli Tietäväinen <ollit@vaadin.com>
Wed, 26 Aug 2020 12:34:02 +0000 (15:34 +0300)
committerGitHub <noreply@github.com>
Wed, 26 Aug 2020 12:34:02 +0000 (15:34 +0300)
Co-authored-by: Anna Koskinen <anna@vaadin.com>
client/src/main/java/com/vaadin/client/ui/VWindow.java
uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthInsideWindowCompositeContent.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthInsideWindowCompositeContentTest.java [new file with mode: 0644]

index 03cb7e16bf36b42ed6ef888f01dbb1e56fddaad5..976b98118ffc060c931869d424ee9d39fbbeb2e3 100644 (file)
@@ -1230,8 +1230,8 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner,
 
     public void updateContentsSize() {
         LayoutManager layoutManager = getLayoutManager();
-        layoutManager
-                .setNeedsMeasure(ConnectorMap.get(client).getConnector(this));
+        layoutManager.setNeedsMeasureRecursively(
+                ConnectorMap.get(client).getConnector(this));
         layoutManager.layoutNow();
     }
 
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthInsideWindowCompositeContent.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthInsideWindowCompositeContent.java
new file mode 100644 (file)
index 0000000..d5fbfa8
--- /dev/null
@@ -0,0 +1,82 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Composite;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class GridColumnWidthInsideWindowCompositeContent
+        extends AbstractTestUI {
+    @Override
+    protected void setup(VaadinRequest request) {
+        Window compositeWindow = new Window();
+        compositeWindow.setId("the-window");
+        compositeWindow.setDraggable(true);
+        compositeWindow.setHeight(600, Unit.PIXELS);
+        compositeWindow.setWidth(400, Unit.PIXELS);
+        compositeWindow.setContent(new WindowContent(compositeWindow));
+        compositeWindow.setId("composite-itself");
+        Button openCompositeWindow = new Button("Open composite Window",
+                e -> getUI().addWindow(compositeWindow));
+        openCompositeWindow.setId("open-composite");
+        addComponent(openCompositeWindow);
+
+        VerticalLayout nonCompositeLayout = new VerticalLayout();
+        Window nonCompositeWindow = new Window();
+        nonCompositeWindow.setDraggable(true);
+        nonCompositeWindow.setHeight(600, Unit.PIXELS);
+        nonCompositeWindow.setWidth(400, Unit.PIXELS);
+        Grid grid = getGrid();
+        VerticalLayout spacingLayout = new VerticalLayout();
+        nonCompositeLayout.addComponents(spacingLayout, grid);
+        nonCompositeWindow.setContent(nonCompositeLayout);
+
+        Button openNonCompositeWindow = new Button("Open non-composite Window",
+                e -> getUI().addWindow(nonCompositeWindow));
+        openNonCompositeWindow.setId("open-non-composite");
+
+        addComponent(openNonCompositeWindow);
+
+    }
+
+    private class WindowContent extends Composite {
+
+        WindowContent(Window window) {
+            VerticalLayout spacingLayout = new VerticalLayout();
+            spacingLayout.setId("spacing-layout");
+            VerticalLayout layout = new VerticalLayout(spacingLayout,
+                    getGrid());
+            layout.setId("composite-root-vl");
+            setCompositionRoot(layout);
+        }
+
+    }
+
+    private Grid getGrid() {
+        Grid grid = new Grid<>();
+        IntStream.range(0, 20).forEach(i -> grid.addColumn(model -> i));
+        Stream<Object> modelStream = IntStream.range(0, 50)
+                .mapToObj(i -> new Object());
+        grid.setItems(modelStream);
+        grid.setSizeFull();
+        return grid;
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Test column resizing after expanding a Grid which is a part of a Composite inside a Window";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 12079;
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthInsideWindowCompositeContentTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthInsideWindowCompositeContentTest.java
new file mode 100644 (file)
index 0000000..3904aa5
--- /dev/null
@@ -0,0 +1,54 @@
+package com.vaadin.tests.components.grid;
+
+import static org.junit.Assert.assertNotEquals;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.WindowElement;
+import com.vaadin.testbench.parallel.TestCategory;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+@TestCategory("grid")
+public class GridColumnWidthInsideWindowCompositeContentTest
+        extends SingleBrowserTest {
+
+    @Test
+    public void widthAfterExpansion() throws InterruptedException {
+        openTestURL();
+        $(ButtonElement.class).id("open-composite").click();
+        GridElement grid = $(GridElement.class).first();
+        int initialWidth = grid.getHeaderCell(0, 0).getSize().getWidth();
+
+        WindowElement window = $(WindowElement.class).first();
+        window.maximize();
+
+        Thread.sleep(1000);
+
+        int newWidth = grid.getHeaderCell(0, 0).getSize().getWidth();
+        assertNotEquals(
+                "Expected Grid cell to be resized after Window was expanded",
+                initialWidth, newWidth);
+    }
+
+    @Test
+    public void widthAfterExpansionWithoutComposite()
+            throws InterruptedException {
+        openTestURL();
+        $(ButtonElement.class).id("open-non-composite").click();
+        GridElement grid = $(GridElement.class).first();
+        int initialWidth = grid.getHeaderCell(0, 0).getSize().getWidth();
+
+        WindowElement window = $(WindowElement.class).first();
+        window.maximize();
+
+        Thread.sleep(1000);
+
+        int newWidth = grid.getHeaderCell(0, 0).getSize().getWidth();
+        assertNotEquals(
+                "Expected Grid cell to be resized after Window was expanded",
+                initialWidth, newWidth);
+    }
+
+}