Set row attributes depending on current row value.

Change-Id: I00c94c9fad037048ce14b6b23f71fa4028576a74
diff --git a/user/src/com/google/gwt/user/cellview/client/AbstractCellTableBuilder.java b/user/src/com/google/gwt/user/cellview/client/AbstractCellTableBuilder.java
index e1da850..f816056 100644
--- a/user/src/com/google/gwt/user/cellview/client/AbstractCellTableBuilder.java
+++ b/user/src/com/google/gwt/user/cellview/client/AbstractCellTableBuilder.java
@@ -167,7 +167,8 @@
   }
   
   /**
-   * Return if an element contains a cell. This may be faster to execute than {@link getColumn}.
+   * Return if an element contains a cell. This may be faster to execute than
+   * {@link #getColumn(Element)}.
    *
    * @param elem the element of interest
    */
@@ -239,6 +240,16 @@
    * Start a row and return the {@link TableRowBuilder} for this row.
    */
   public final TableRowBuilder startRow() {
+    return startRow(null);
+  }
+
+  /**
+   * Start a row and return the {@link TableRowBuilder} for this row. The row can be initialized
+   * according to its corresponding value.
+   *
+   * @param rowValue the value for the row corresponding to the element. Can be null.
+   */
+  public final TableRowBuilder startRow(T rowValue) {
     // End any dangling rows.
     while (tbody.getDepth() > 1) {
       tbody.end();
@@ -254,7 +265,7 @@
     TableRowBuilder row = tbody.startTR();
     row.attribute(ROW_ATTRIBUTE, rowIndex);
     row.attribute(SUBROW_ATTRIBUTE, subrowIndex);
-    addRowAttributes(row);
+    addRowAttributes(row, rowValue);
     subrowIndex++;
     return row;
   }
@@ -264,11 +275,24 @@
    * The default does nothing.
    *
    * @param row the row element
+   *
+   * @see #addRowAttributes(TableRowBuilder, Object)
    */
   protected void addRowAttributes(TableRowBuilder row) {
   }
 
   /**
+   * Hook for subclasses to add their own attributes to each row in the table.
+   * The default does nothing.
+   *
+   * @param row the row element
+   * @param rowValue the value for the row corresponding to the element. Can be null.
+   */
+  protected void addRowAttributes(TableRowBuilder row, T rowValue) {
+    addRowAttributes(row);
+  }
+
+  /**
    * Build zero or more table rows for the specified row value.
    * 
    * @param rowValue the value for the row to render
diff --git a/user/src/com/google/gwt/user/cellview/client/DefaultCellTableBuilder.java b/user/src/com/google/gwt/user/cellview/client/DefaultCellTableBuilder.java
index 8e09c8e..97e26ee 100644
--- a/user/src/com/google/gwt/user/cellview/client/DefaultCellTableBuilder.java
+++ b/user/src/com/google/gwt/user/cellview/client/DefaultCellTableBuilder.java
@@ -81,7 +81,7 @@
     }
 
     // Build the row.
-    TableRowBuilder tr = startRow();
+    TableRowBuilder tr = startRow(rowValue);
     tr.className(trClasses.toString());
 
     // Build the columns.
diff --git a/user/test/com/google/gwt/user/cellview/client/AbstractCellTableTestBase.java b/user/test/com/google/gwt/user/cellview/client/AbstractCellTableTestBase.java
index 1b74f13..96272b3 100644
--- a/user/test/com/google/gwt/user/cellview/client/AbstractCellTableTestBase.java
+++ b/user/test/com/google/gwt/user/cellview/client/AbstractCellTableTestBase.java
@@ -114,13 +114,13 @@
       @Override
       public void buildRowImpl(String rowValue, int absRowIndex) {
         builtRows.add(absRowIndex);
-        TableRowBuilder tr = startRow();
+        TableRowBuilder tr = startRow(rowValue);
         tr.endTR(); // End the tr.
         tr.end(); // Accidentally end the table section.
 
         // Try to start another row.
         try {
-          startRow();
+          startRow(rowValue);
           fail("Expected IllegalStateException: tbody is already ended");
         } catch (IllegalStateException e) {
           // Expected.
@@ -149,7 +149,7 @@
         // Add child rows to row five.
         if (absRowIndex == 5) {
           for (int i = 0; i < 4; i++) {
-            TableRowBuilder tr = startRow();
+            TableRowBuilder tr = startRow(rowValue);
             tr.startTD().colSpan(2).text("child " + i).endTD();
             tr.endTR();
           }
@@ -677,7 +677,7 @@
 
         // Add some children.
         for (int i = 0; i < 4; i++) {
-          TableRowBuilder tr = startRow();
+          TableRowBuilder tr = startRow(rowValue);
           tr.startTD().colSpan(2).text("child " + absRowIndex + ":" + i).endTD();
           tr.endTR();
         }