Author: [email protected]
Date: Tue May 12 11:15:14 2009
New Revision: 5354

Modified:
    trunk/user/src/com/google/gwt/user/client/ui/FlexTable.java
    trunk/user/src/com/google/gwt/user/client/ui/HTMLTable.java
    trunk/user/test/com/google/gwt/user/client/ui/FlexTableTest.java
    trunk/user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java

Log:
Adds HTMLTable.clear(boolean) and FlexTable.removeAllRows().

Patch by: jlabanca
Review by: rjrjr
Issue: 1766

Modified: trunk/user/src/com/google/gwt/user/client/ui/FlexTable.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/FlexTable.java (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/FlexTable.java Tue May 12  
11:15:14 2009
@@ -172,6 +172,16 @@
      return super.insertRow(beforeRow);
    }

+  /**
+   * Remove all rows in this table.
+   */
+  public void removeAllRows() {
+    int numRows = getRowCount();
+    for (int i = 0; i < numRows; i++) {
+      removeRow(0);
+    }
+  }
+
    @Override
    public void removeCell(int row, int col) {
      super.removeCell(row, col);

Modified: trunk/user/src/com/google/gwt/user/client/ui/HTMLTable.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/HTMLTable.java (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/HTMLTable.java Tue May 12  
11:15:14 2009
@@ -713,12 +713,19 @@
     */
    @Override
    public void clear() {
+    clear(false);
+  }
+
+  /**
+   * Removes all widgets from this table, optionally clearing the inner  
HTML of
+   * each cell.  Note that this method does not remove any cells or rows.
+   *
+   * @param clearInnerHTML should the cell's inner html be cleared?
+   */
+  public void clear(boolean clearInnerHTML) {
      for (int row = 0; row < getRowCount(); ++row) {
        for (int col = 0; col < getCellCount(row); ++col) {
-        Widget child = getWidgetImpl(row, col);
-        if (child != null) {
-          remove(child);
-        }
+        cleanCell(row, col, clearInnerHTML);
        }
      }
    }

Modified: trunk/user/test/com/google/gwt/user/client/ui/FlexTableTest.java
==============================================================================
--- trunk/user/test/com/google/gwt/user/client/ui/FlexTableTest.java     
(original)
+++ trunk/user/test/com/google/gwt/user/client/ui/FlexTableTest.java    Tue  
May 12 11:15:14 2009
@@ -130,6 +130,20 @@
      ft.clear();
    }

+  public void testRemoveAllRows() {
+    FlexTable table = new FlexTable();
+    for (int row = 0; row < 4; row++) {
+      table.setHTML(row, 0, row + ":0");
+      table.setHTML(row, 1, row + ":1");
+      table.setWidget(row, 2, new Button(row + ":2"));
+      table.setWidget(row, 3, new Button(row + ":3"));
+    }
+
+    assertEquals(4, table.getRowCount());
+    table.removeAllRows();
+    assertEquals(0, table.getRowCount());
+  }
+
    public void secondarySetHeightTest() {
      FlexTable ft = new FlexTable();
      FlexCellFormatter cellFormatter = (FlexCellFormatter)  
ft.getCellFormatter();

Modified:  
trunk/user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java
==============================================================================
--- trunk/user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java        
 
(original)
+++ trunk/user/test/com/google/gwt/user/client/ui/HTMLTableTestBase.java        
 
Tue May 12 11:15:14 2009
@@ -74,6 +74,46 @@
      fail("should have throw an index out of bounds");
    }

+  public void testClearWidgetsAndHtml() {
+    HTMLTable table = getTable(4, 4);
+    for (int row = 0; row < 4; row++) {
+      table.setHTML(row, 0, row + ":0");
+      table.setHTML(row, 1, row + ":1");
+      table.setWidget(row, 2, new Button(row + ":2"));
+      table.setWidget(row, 3, new Button(row + ":3"));
+    }
+
+    table.clear(true);
+    for (int row = 0; row < 4; row++) {
+      assertEquals("", table.getHTML(row, 0).trim());
+      assertEquals("", table.getHTML(row, 1).trim());
+      assertEquals("", table.getHTML(row, 2).trim());
+      assertNull(table.getWidget(row, 2));
+      assertEquals("", table.getHTML(row, 3).trim());
+      assertNull(table.getWidget(row, 3));
+    }
+  }
+
+  public void testClearWidgetsOnly() {
+    HTMLTable table = getTable(4, 4);
+    for (int row = 0; row < 4; row++) {
+      table.setHTML(row, 0, row + ":0");
+      table.setHTML(row, 1, row + ":1");
+      table.setWidget(row, 2, new Button(row + ":2"));
+      table.setWidget(row, 3, new Button(row + ":3"));
+    }
+
+    table.clear();
+    for (int row = 0; row < 4; row++) {
+      assertEquals(row + ":0", table.getHTML(row, 0));
+      assertEquals(row + ":1", table.getHTML(row, 1));
+      assertEquals("", table.getHTML(row, 2).trim());
+      assertNull(table.getWidget(row, 2));
+      assertEquals("", table.getHTML(row, 3).trim());
+      assertNull(table.getWidget(row, 3));
+    }
+  }
+
    public void testDebugId() {
      HTMLTable table = getTable(4, 3);
      for (int row = 0; row < 4; row++) {
@@ -88,7 +128,7 @@
      CellFormatter formatter = table.getCellFormatter();
      for (int row = 0; row < 4; row++) {
        for (int cell = 0; cell < 3; cell++) {
-        Element cellElem = formatter.getElement(row, cell);
+        Element cellElem = formatter.getElement(row, cell);
          UIObjectTest.assertDebugId("myTable-" + row + "-" + cell,  
cellElem);
        }
      }

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

Reply via email to