diff options
author | Artur Signell <artur.signell@itmill.com> | 2009-01-21 14:31:40 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2009-01-21 14:31:40 +0000 |
commit | 57904593f21ae54ccc5ccaf33933044e62b215e0 (patch) | |
tree | a290e3f2eb29259dcc8e0ac8e3ddbbb32aae5c12 | |
parent | 9aa50d98209fefd3d24cfcaf285d5d4efcad9a24 (diff) | |
download | vaadin-framework-57904593f21ae54ccc5ccaf33933044e62b215e0.tar.gz vaadin-framework-57904593f21ae54ccc5ccaf33933044e62b215e0.zip |
Test case and fix for #2459 - No scrollbars with CustomComponent of undefined size
svn changeset:6611/svn branch:trunk
-rw-r--r-- | src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomComponent.java | 30 | ||||
-rw-r--r-- | src/com/itmill/toolkit/tests/components/CustomComponentwithUndefinedSize.java | 83 |
2 files changed, 111 insertions, 2 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomComponent.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomComponent.java index 9d00abe43f..70a0a18e57 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomComponent.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomComponent.java @@ -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 index 0000000000..4c8619f92e --- /dev/null +++ b/src/com/itmill/toolkit/tests/components/CustomComponentwithUndefinedSize.java @@ -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 |