]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test case and fix for #2406 - Sub window with undefined height and 100% high layout
authorArtur Signell <artur.signell@itmill.com>
Tue, 30 Dec 2008 12:49:30 +0000 (12:49 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 30 Dec 2008 12:49:30 +0000 (12:49 +0000)
svn changeset:6366/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java
src/com/itmill/toolkit/tests/tickets/Ticket2406.java [new file with mode: 0644]
src/com/itmill/toolkit/ui/Window.java

index a40183cdb90fb79be1f8798927db40c54e2de6df..c033766309712bebb2b2119dbf298b1e2b1a7caf 100644 (file)
@@ -308,9 +308,9 @@ public class IWindow extends IToolkitOverlay implements Container,
         boolean dynamicHeight = !uidl.hasAttribute("height");
         boolean widthHasBeenFixed = false;
 
-        String layoutWidth = childUidl.getStringAttribute("width");
-        boolean layoutRelativeWidth = (layoutWidth != null && layoutWidth
-                .endsWith("%"));
+        boolean layoutRelativeWidth = uidl.hasAttribute("layoutRelativeWidth");
+        boolean layoutRelativeHeight = uidl
+                .hasAttribute("layoutRelativeHeight");
 
         if (dynamicWidth && layoutRelativeWidth) {
             /*
@@ -328,7 +328,7 @@ public class IWindow extends IToolkitOverlay implements Container,
              * be able to take scrollbars into account (layout gets narrower
              * space if it is higher than the window) -> only vertical scrollbar
              */
-            client.handleComponentRelativeSize((Widget) layout);
+            client.runDescendentsLayout(this);
         }
 
         /*
@@ -340,6 +340,26 @@ public class IWindow extends IToolkitOverlay implements Container,
             widthHasBeenFixed = true;
         }
 
+        if (dynamicHeight && layoutRelativeHeight) {
+            /*
+             * Window height is undefined, layout is 100% high so the layout
+             * should define the initial window height but on resize the layout
+             * should be as high as the window. We fix the height immediately to
+             * deal with this.
+             */
+
+            int h = contents.getOffsetHeight() + getExtraHeight();
+            int w = contents.getOffsetWidth();
+
+            // Prevent resizing until height has been fixed
+            resizable = false;
+
+            client.updateVariable(id, "height", h, false);
+            client.updateVariable(id, "width", w, true);
+            // ApplicationConnection.getConsole().log("Fixing window size to " +
+            // w + "x" + h);
+        }
+
         // we may have actions and notifications
         if (uidl.getChildCount() > 1) {
             final int cnt = uidl.getChildCount();
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2406.java b/src/com/itmill/toolkit/tests/tickets/Ticket2406.java
new file mode 100644 (file)
index 0000000..4f33b59
--- /dev/null
@@ -0,0 +1,47 @@
+package com.itmill.toolkit.tests.tickets;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.VerticalLayout;
+import com.itmill.toolkit.ui.Window;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+import com.itmill.toolkit.ui.Button.ClickListener;
+
+public class Ticket2406 extends Application {
+
+    private Window w;
+
+    public void init() {
+        Window w = new Window(getClass().getSimpleName());
+        setMainWindow(w);
+        // setTheme("tests-tickets");
+        createUI((VerticalLayout) w.getLayout());
+    }
+
+    private void createUI(VerticalLayout layout) {
+        w = new Window("A sub window");
+        w.setSizeUndefined();
+        getMainWindow().addWindow(w);
+
+        VerticalLayout l = new VerticalLayout();
+        l.setSizeFull();
+        w.setLayout(l);
+
+        Button b = new Button("Button 1");
+        b.setSizeFull();
+        b.addListener(new ClickListener() {
+
+            public void buttonClick(ClickEvent event) {
+                w.setHeight("200px");
+            }
+
+        });
+        l.addComponent(b);
+
+        for (int i = 0; i < 5; i++) {
+            b = new Button("Button number "+(i+2));
+            b.setSizeFull();
+            l.addComponent(b);
+        }
+    }
+}
index 8849d8e034463f8774fed0810121b3edc7914591..f255d717d206a9fe7926c09155609304685af7e6 100644 (file)
@@ -20,6 +20,7 @@ import com.itmill.toolkit.terminal.PaintException;
 import com.itmill.toolkit.terminal.PaintTarget;
 import com.itmill.toolkit.terminal.ParameterHandler;
 import com.itmill.toolkit.terminal.Resource;
+import com.itmill.toolkit.terminal.Sizeable;
 import com.itmill.toolkit.terminal.Terminal;
 import com.itmill.toolkit.terminal.URIHandler;
 
@@ -496,6 +497,15 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
             target.addAttribute("main", true);
         }
 
+        if (getLayout() != null) {
+            if (getLayout().getHeightUnits() == Sizeable.UNITS_PERCENTAGE) {
+                target.addAttribute("layoutRelativeHeight", true);
+            }
+            if (getLayout().getWidthUnits() == Sizeable.UNITS_PERCENTAGE) {
+                target.addAttribute("layoutRelativeWidth", true);
+            }
+        }
+
         // Open requested resource
         synchronized (openList) {
             if (!openList.isEmpty()) {