Reviewers: rjrjr,

Description:
TreeItem.setWidget sets its innerHTML to an empty string but doesn't
phsyically detach the widget, which has the odd side effect of deleting
the content of the widget in IE.

This patch physically removes the widget before clearing the contents.
I prepared a similar change to FastTree in incubator.

Associated issue:
http://code.google.com/p/google-web-toolkit/issues
/detail?id=2297

Please review this at http://gwt-code-reviews.appspot.com/33812

Affected files:
   user/src/com/google/gwt/user/client/ui/TreeItem.java
   user/test/com/google/gwt/user/UISuite.java
   user/test/com/google/gwt/user/client/ui/TreeItemTest.java


Index: user/test/com/google/gwt/user/UISuite.java
===================================================================
--- user/test/com/google/gwt/user/UISuite.java  (revision 5357)
+++ user/test/com/google/gwt/user/UISuite.java  (working copy)
@@ -76,6 +76,7 @@
  import com.google.gwt.user.client.ui.TabBarTest;
  import com.google.gwt.user.client.ui.TabPanelTest;
  import com.google.gwt.user.client.ui.TextAreaTest;
+import com.google.gwt.user.client.ui.TreeItemTest;
  import com.google.gwt.user.client.ui.TreeTest;
  import com.google.gwt.user.client.ui.UIObjectTest;
  import com.google.gwt.user.client.ui.VerticalPanelTest;
@@ -161,6 +162,7 @@
      suite.addTestSuite(TabPanelTest.class);
      suite.addTestSuite(TextAreaTest.class);
      suite.addTestSuite(TreeTest.class);
+    suite.addTestSuite(TreeItemTest.class);
      suite.addTestSuite(UIObjectTest.class);
      suite.addTestSuite(VerticalPanelTest.class);
      suite.addTestSuite(WidgetCollectionTest.class);
Index: user/test/com/google/gwt/user/client/ui/TreeItemTest.java
===================================================================
--- user/test/com/google/gwt/user/client/ui/TreeItemTest.java   (revision 0)
+++ user/test/com/google/gwt/user/client/ui/TreeItemTest.java   (revision 0)
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+ * use this file except in compliance with the License. You may obtain a  
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.user.client.ui;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests the {...@link TreeItem}.
+ */
+public class TreeItemTest extends GWTTestCase {
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.user.User";
+  }
+
+  /**
+   * Test that setting the widget to null does not modify the widget. See  
issue
+   * 2297 for more details.
+   */
+  public void testSetWidgetToNull() {
+    Label widget = new Label("Test");
+    TreeItem item = new TreeItem(widget);
+    assertEquals("Test", widget.getText());
+    item.setWidget(null);
+    assertEquals("Test", widget.getText());
+  }
+}

Property changes on:  
user/test/com/google/gwt/user/client/ui/TreeItemTest.java
___________________________________________________________________
Name: svn:mime-type
    + text/x-java
Name: svn:eol-style
    + native

Index: user/src/com/google/gwt/user/client/ui/TreeItem.java
===================================================================
--- user/src/com/google/gwt/user/client/ui/TreeItem.java        (revision 5357)
+++ user/src/com/google/gwt/user/client/ui/TreeItem.java        (working copy)
@@ -576,11 +576,15 @@
      }

      // Detach old child from tree.
-    if (widget != null && tree != null) {
-      tree.orphan(widget);
+    if (widget != null) {
+      if (tree != null) {
+        tree.orphan(widget);
+      }
+
+      // Physical detach old child.
+      contentElem.removeChild(widget.getElement());
      }

-    // Physical detach old from self.
      // Clear out any existing content before adding a widget.
      DOM.setInnerHTML(contentElem, "");




--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to