Removed the private content field from DisclosurePanel and instead deferred to the SimplePanel that contains the content Widget. These prevents a bug when the content is removed from the DisclosurePanel using Widget#removeFromParent().
Patch by: jlabanca
Review by: ecc
Issue: 2792
git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4336 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/DisclosurePanel.java b/user/src/com/google/gwt/user/client/ui/DisclosurePanel.java
index df4a490..87cbbea 100644
--- a/user/src/com/google/gwt/user/client/ui/DisclosurePanel.java
+++ b/user/src/com/google/gwt/user/client/ui/DisclosurePanel.java
@@ -262,8 +262,7 @@
/**
* top level widget. The first child will be a reference to {@link #header}.
- * The second child will either not exist or be a non-null to reference to
- * {@link #content}.
+ * The second child will be a reference to {@link #contentWrapper}.
*/
private final VerticalPanel mainPanel = new VerticalPanel();
@@ -277,11 +276,6 @@
*/
private final ClickableHeader header = new ClickableHeader();
- /**
- * the content widget, this can be null.
- */
- private Widget content;
-
private boolean isAnimationEnabled = false;
private boolean isOpen = false;
@@ -392,7 +386,7 @@
* @return the panel's current content widget
*/
public Widget getContent() {
- return content;
+ return contentWrapper.getWidget();
}
/**
@@ -463,7 +457,7 @@
* @param content the widget to be used as the content panel
*/
public void setContent(Widget content) {
- final Widget currentContent = this.content;
+ final Widget currentContent = getContent();
// Remove existing content widget.
if (currentContent != null) {
@@ -472,7 +466,6 @@
}
// Add new content widget if != null.
- this.content = content;
if (content != null) {
contentWrapper.setWidget(content);
content.addStyleName(STYLENAME_CONTENT);
@@ -545,7 +538,7 @@
addStyleDependentName(STYLENAME_SUFFIX_CLOSED);
}
- if (content != null) {
+ if (getContent() != null) {
if (contentAnimation == null) {
contentAnimation = new ContentAnimation();
}
diff --git a/user/test/com/google/gwt/user/client/ui/DisclosurePanelTest.java b/user/test/com/google/gwt/user/client/ui/DisclosurePanelTest.java
index 5412215..6039eea 100644
--- a/user/test/com/google/gwt/user/client/ui/DisclosurePanelTest.java
+++ b/user/test/com/google/gwt/user/client/ui/DisclosurePanelTest.java
@@ -129,7 +129,6 @@
assertEquals(3, panel.getHandlers().getHandlerCount(CloseEvent.getType()));
assertEquals(3, panel.getHandlers().getHandlerCount(OpenEvent.getType()));
-
panel.setOpen(true);
// We expect onOpen to fire and onClose to not fire.
assertTrue(aDidFire[OPEN] && bDidFire[OPEN] && !aDidFire[CLOSE]
@@ -148,7 +147,6 @@
assertEquals(2, panel.getHandlers().getHandlerCount(OpenEvent.getType()));
assertEquals(2, panel.getHandlers().getHandlerCount(CloseEvent.getType()));
-
panel.setOpen(true);
panel.setOpen(false);
// We expect a to have fired both events, and b to have fired none.
@@ -158,6 +156,19 @@
assertTrue(!bDidFire[CLOSE]);
}
+ /**
+ * Tests that the content is set to null if the content widget's
+ * {@link Widget#removeFromParent()} method is called.
+ */
+ public void testRemoveFromParent() {
+ DisclosurePanel panel = createTestPanel();
+ Label content = new Label();
+ panel.setContent(content);
+ assertEquals(content, panel.getContent());
+ content.removeFromParent();
+ assertNull(panel.getContent());
+ }
+
private DisclosurePanel createTestPanel() {
DisclosurePanel panel = new DisclosurePanel("Test Subject", false);
panel.setContent(new SimplePanel());