]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test case and fix for #2459 - No scrollbars with CustomComponent of undefined size
authorArtur Signell <artur.signell@itmill.com>
Wed, 21 Jan 2009 14:31:40 +0000 (14:31 +0000)
committerArtur Signell <artur.signell@itmill.com>
Wed, 21 Jan 2009 14:31:40 +0000 (14:31 +0000)
svn changeset:6611/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomComponent.java
src/com/itmill/toolkit/tests/components/CustomComponentwithUndefinedSize.java [new file with mode: 0644]

index 9d00abe43f16e75448a34327ae26b66da705fa42..70a0a18e575348d09336c3b0f6bef3edab109ac7 100644 (file)
@@ -13,6 +13,7 @@ import com.itmill.toolkit.terminal.gwt.client.Container;
 import com.itmill.toolkit.terminal.gwt.client.Paintable;
 import com.itmill.toolkit.terminal.gwt.client.RenderSpace;
 import com.itmill.toolkit.terminal.gwt.client.UIDL;
+import com.itmill.toolkit.terminal.gwt.client.Util;
 
 public class ICustomComponent extends SimplePanel implements Container {
 
@@ -52,9 +53,35 @@ public class ICustomComponent extends SimplePanel implements Container {
         renderSpace.setWidth(getElement().getOffsetWidth());
         renderSpace.setHeight(getElement().getOffsetHeight());
 
+        updateDynamicSize();
+
         rendering = false;
     }
 
+    private boolean updateDynamicSize() {
+        boolean updated = false;
+        if (isDynamicWidth()) {
+            int childWidth = Util.getRequiredWidth(getWidget());
+            getElement().getStyle().setPropertyPx("width", childWidth);
+            updated = true;
+        }
+        if (isDynamicHeight()) {
+            int childHeight = Util.getRequiredHeight(getWidget());
+            getElement().getStyle().setPropertyPx("height", childHeight);
+            updated = true;
+        }
+
+        return updated;
+    }
+
+    private boolean isDynamicWidth() {
+        return width == null || width.equals("");
+    }
+
+    private boolean isDynamicHeight() {
+        return height == null || height.equals("");
+    }
+
     public boolean hasChildComponent(Widget component) {
         if (getWidget() == component) {
             return true;
@@ -77,8 +104,7 @@ public class ICustomComponent extends SimplePanel implements Container {
     }
 
     public boolean requestLayout(Set<Paintable> child) {
-        // TODO Auto-generated method stub
-        return false;
+        return !updateDynamicSize();
     }
 
     public RenderSpace getAllocatedSpace(Widget child) {
diff --git a/src/com/itmill/toolkit/tests/components/CustomComponentwithUndefinedSize.java b/src/com/itmill/toolkit/tests/components/CustomComponentwithUndefinedSize.java
new file mode 100644 (file)
index 0000000..4c8619f
--- /dev/null
@@ -0,0 +1,83 @@
+package com.itmill.toolkit.tests.components;
+
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.Layout;
+import com.itmill.toolkit.ui.Panel;
+import com.itmill.toolkit.ui.TabSheet;
+import com.itmill.toolkit.ui.VerticalLayout;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+import com.itmill.toolkit.ui.Button.ClickListener;
+
+public class CustomComponentwithUndefinedSize extends TestBase {
+
+    @Override
+    protected String getDescription() {
+        return "A custom component with no size definition should not prevent scrollbars from being shown when its contents is larger than its parent";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 2459;
+    }
+
+    @Override
+    protected void setup() {
+
+        TabSheet tabs = new TabSheet();
+        tabs.setSizeFull();
+        MyCustomComponent mcc = new MyCustomComponent();
+        mcc.setSizeUndefined();
+
+        // Doesn't work
+        tabs.addTab(mcc, "Doesn't work (CustomComponent)", null);
+
+        // Works:
+        tabs.addTab(mcc.buildLayout(),
+                "Works (no CustomComponent, same layout)", null);
+
+        addComponent(tabs);
+        getLayout().setSizeFull();
+    }
+
+    private int step = 0;
+
+    public class MyCustomComponent extends CustomComponent {
+        public MyCustomComponent() {
+            setCompositionRoot(buildLayout());
+        }
+
+        public Layout buildLayout() {
+            VerticalLayout layout = new VerticalLayout();
+            final Panel widePanel = new Panel("too big");
+            widePanel.setSizeUndefined();
+            widePanel.setWidth("2000px");
+            widePanel.setHeight("200px");
+            layout.addComponent(widePanel);
+            Button button = new Button("Change panel size",
+                    new ClickListener() {
+
+                        public void buttonClick(ClickEvent event) {
+                            switch (step++ % 4) {
+                            case 0:
+                                widePanel.setWidth("200px");
+                                break;
+                            case 1:
+                                widePanel.setHeight("2000px");
+                                break;
+                            case 2:
+                                widePanel.setWidth("2000px");
+                                break;
+                            case 3:
+                                widePanel.setHeight("200px");
+                                break;
+                            }
+
+                        }
+                    });
+            widePanel.addComponent(button);
+            layout.setSizeUndefined();
+            return layout;
+        }
+    }
+}
\ No newline at end of file