Revision: 9737
Author: jlaba...@google.com
Date: Tue Feb 15 09:05:00 2011
Log: Fixing HTMLTable#setWidget() to remove the widget or text when null is
passed as the widget. Currently, the widget is not removed.
Review at http://gwt-code-reviews.appspot.com/1358803
Review by: rj...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=9737
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/HTMLTable.java
/trunk/user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/HTMLTable.java Tue Sep 21
07:53:19 2010
+++ /trunk/user/src/com/google/gwt/user/client/ui/HTMLTable.java Tue Feb 15
09:05:00 2011
@@ -1091,19 +1091,20 @@
* 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);
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java
Wed Jan 19 08:59:29 2011
+++ /trunk/user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java
Tue Feb 15 09:05:00 2011
@@ -240,6 +240,29 @@
formatter.setHorizontalAlignment(1, 1,
HasHorizontalAlignment.ALIGN_RIGHT);
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);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors