Reviewers: rjrjr,

Description:
Fixing HTMLTable#setWidget() to remove the widget or text when null is
passed as the widget.  Currently, the widget is not removed.


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

Affected files:
  M user/src/com/google/gwt/user/client/ui/HTMLTable.java
  M user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java


Index: user/src/com/google/gwt/user/client/ui/HTMLTable.java
===================================================================
--- user/src/com/google/gwt/user/client/ui/HTMLTable.java       (revision 9736)
+++ user/src/com/google/gwt/user/client/ui/HTMLTable.java       (working copy)
@@ -1091,18 +1091,19 @@
    * within the Grid's bounding box.
    * </p>
    *
-   * @param widget The widget to be added
+   * @param widget The widget to be added, or null to clear the cell
    * @param row the cell's row
    * @param column the cell's column
    * @throws IndexOutOfBoundsException
    */
   public void setWidget(int row, int column, Widget widget) {
     prepareCell(row, column);
+
+    // Removes any existing widget.
+    Element td = cleanCell(row, column, true);
+
     if (widget != null) {
       widget.removeFromParent();
-
-      // Removes any existing widget.
-      Element td = cleanCell(row, column, true);

       // Logical attach.
       widgetMap.put(widget);
Index: user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java
===================================================================
--- user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java (revision 9736) +++ user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java (working copy)
@@ -241,6 +241,29 @@
     formatter.setWidth(0, 2, "100%");
   }

+  public void testSetWidgetNull() {
+    HTMLTable t = getTable(1, 2);
+
+    // Set some text and a widget.
+    Label content = new Label("widget");
+    t.setText(0, 0, "hello world");
+    t.setWidget(0, 1, content);
+    assertEquals("hello world", t.getText(0, 0));
+    assertEquals(content, t.getWidget(0, 1));
+
+    // Set the text cell to a null widget.
+    t.setWidget(0, 0, null);
+ assertEquals("text should be cleared when the widget is set to null", "",
+        t.getText(0, 0));
+    assertEquals("widget should be cleared when set to null", content,
+        t.getWidget(0, 1));
+
+    // Set the widget cell to a null widget.
+    t.setWidget(0, 1, null);
+    assertEquals("", t.getText(0, 0));
+    assertNull(t.getWidget(0, 1));
+  }
+
   public void testSafeHtml() {
     HTMLTable table = getTable(1, 1);
     table.setHTML(0, 0, SafeHtmlUtils.fromSafeConstant(html));


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

Reply via email to