]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #1805
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 12 Jun 2008 11:16:53 +0000 (11:16 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 12 Jun 2008 11:16:53 +0000 (11:16 +0000)
svn changeset:4862/svn branch:trunk

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

index 4789d9d8aab2d469cd07b6df8d7f0415e5923400..4e6a55541cda50d8ae18cbe50a1f6e111acb0b3f 100644 (file)
@@ -20,32 +20,57 @@ import com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConst
 import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
 import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
 import com.itmill.toolkit.terminal.gwt.client.Container;
+import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
 import com.itmill.toolkit.terminal.gwt.client.Paintable;
 import com.itmill.toolkit.terminal.gwt.client.StyleConstants;
 import com.itmill.toolkit.terminal.gwt.client.UIDL;
+import com.itmill.toolkit.terminal.gwt.client.Util;
 
-public class IGridLayout extends SimplePanel implements Paintable, Container {
+public class IGridLayout extends SimplePanel implements Paintable, Container,
+        ContainerResizedListener {
 
     public static final String CLASSNAME = "i-gridlayout";
 
     private Grid grid = new Grid();
 
+    private boolean needsLayout = false;
+
+    private Element margin = DOM.createDiv();
+
+    private Element meterElement;
+
+    private String width;
+
     public IGridLayout() {
         super();
+        DOM.appendChild(getElement(), margin);
+        DOM.setStyleAttribute(getElement(), "overflow", "hidden");
         setStyleName(CLASSNAME);
         setWidget(grid);
     }
 
+    protected Element getContainerElement() {
+        return margin;
+    }
+
+    public void setWidth(String width) {
+        this.width = width;
+        if (width != null && !width.equals("")) {
+            needsLayout = true;
+        } else {
+            needsLayout = false;
+            grid.setWidth("");
+        }
+    }
+
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
 
         if (client.updateComponent(this, uidl, false)) {
             return;
         }
-
         final MarginInfo margins = new MarginInfo(uidl
                 .getIntAttribute("margins"));
 
-        Element margin = getElement();
         setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP,
                 margins.hasTop());
         setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_RIGHT,
@@ -57,7 +82,7 @@ public class IGridLayout extends SimplePanel implements Paintable, Container {
 
         setStyleName(margin, CLASSNAME + "-" + "spacing", uidl
                 .hasAttribute("spacing"));
-
+        iLayout();
         grid.updateFromUIDL(uidl, client);
     }
 
@@ -220,4 +245,24 @@ public class IGridLayout extends SimplePanel implements Paintable, Container {
 
     }
 
+    public void iLayout() {
+        if (needsLayout) {
+            super.setWidth(width);
+            if (meterElement == null) {
+                meterElement = DOM.createDiv();
+                DOM.setStyleAttribute(meterElement, "overflow", "hidden");
+                DOM.setStyleAttribute(meterElement, "height", "0");
+                DOM.appendChild(getContainerElement(), meterElement);
+            }
+            int contentWidth = DOM.getElementPropertyInt(meterElement,
+                    "offsetWidth");
+            int offsetWidth = getOffsetWidth();
+
+            grid.setWidth((offsetWidth - (offsetWidth - contentWidth)) + "px");
+        } else {
+            grid.setWidth("");
+        }
+        Util.runDescendentsLayout(this);
+    }
+
 }
diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1805.java b/src/com/itmill/toolkit/tests/tickets/Ticket1805.java
new file mode 100644 (file)
index 0000000..e9a8453
--- /dev/null
@@ -0,0 +1,55 @@
+package com.itmill.toolkit.tests.tickets;\r
+\r
+import com.itmill.toolkit.data.Property.ValueChangeEvent;\r
+import com.itmill.toolkit.data.Property.ValueChangeListener;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.GridLayout;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.TextField;\r
+import com.itmill.toolkit.ui.Window;\r
+\r
+public class Ticket1805 extends com.itmill.toolkit.Application {\r
+\r
+    public void init() {\r
+        final Window main = new Window(getClass().getName().substring(\r
+                getClass().getName().lastIndexOf(".") + 1));\r
+        setMainWindow(main);\r
+        main.getLayout().setMargin(false);\r
+\r
+        Label description = new Label(\r
+                "GridLayout with 100% (no height), is wanted to "\r
+                        + "share all available width with columns "\r
+                        + "relatively to their natural width. And it "\r
+                        + "should still work with margins and spacings");\r
+        main.addComponent(description);\r
+\r
+        final GridLayout grid = new GridLayout(4, 1);\r
+\r
+        final TextField size = new TextField("Grid width in css unit");\r
+        size.addListener(new ValueChangeListener() {\r
+            public void valueChange(ValueChangeEvent event) {\r
+                String width = size.getValue().toString();\r
+                if (width == null || width.equals("")) {\r
+                    grid.setSizeUndefined();\r
+                } else {\r
+                    grid.setWidth(width);\r
+                }\r
+            }\r
+        });\r
+        main.addComponent(size);\r
+        main.addComponent(new Button("set size"));\r
+\r
+        grid.setMargin(true);\r
+        grid.setSpacing(true);\r
+\r
+        grid.addComponent(new Label("WIDE"));\r
+        grid.addComponent(new Label("_I_"));\r
+        grid.addComponent(new Label("VEEEEEEEEEEERY_WIDE"));\r
+        Label label = new Label("|");\r
+        grid.addComponent(label);\r
+        grid.setComponentAlignment(label, GridLayout.ALIGNMENT_RIGHT,\r
+                GridLayout.ALIGNMENT_TOP);\r
+        main.addComponent(grid);\r
+    }\r
+\r
+}\r