Revision: 10259
Author:   jlaba...@google.com
Date:     Wed Jun  1 10:50:41 2011
Log: Adding a couple of useful methods to AbstractCellTable. getColumnWidth() can be used to access the width of a column set using setColumnWidth(). flush() will immediately flush pending changes into the view.

Review at http://gwt-code-reviews.appspot.com/1453801

Review by: pengzhu...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10259

Modified:
 /trunk/user/src/com/google/gwt/user/cellview/client/AbstractCellTable.java
/trunk/user/test/com/google/gwt/user/cellview/client/AbstractCellTableTestBase.java

=======================================
--- /trunk/user/src/com/google/gwt/user/cellview/client/AbstractCellTable.java Thu May 26 04:44:13 2011 +++ /trunk/user/src/com/google/gwt/user/cellview/client/AbstractCellTable.java Wed Jun 1 10:50:41 2011
@@ -633,6 +633,20 @@
     columnWidths.remove(column);
     refreshColumnWidths();
   }
+
+  /**
+   * Flush all pending changes to the table and render immediately.
+   *
+   * <p>
+ * Modifications to the table, such as adding columns or setting data, are not
+   * rendered immediately. Instead, changes are coalesced at the end of the
+ * current event loop to avoid rendering the table multiple times. Use this + * method to force the table to render all pending modifications immediately.
+   * </p>
+   */
+  public void flush() {
+    getPresenter().flush();
+  }

   /**
    * Get the column at the specified index.
@@ -674,6 +688,17 @@
   public ColumnSortList getColumnSortList() {
     return sortList;
   }
+
+  /**
+   * Get the width of a {@link Column}.
+   *
+   * @param column the column
+   * @return the width of the column, or null if not set
+   * @see #setColumnWidth(Column, double, Unit)
+   */
+  public String getColumnWidth(Column<T, ?> column) {
+    return columnWidths.get(column);
+  }

   /**
    * Get the widget displayed when the table has no rows.
@@ -703,7 +728,7 @@
    *           current page
    */
   public TableRowElement getRowElement(int row) {
-    getPresenter().flush();
+    flush();
     checkRowBounds(row);
     NodeList<TableRowElement> rows = getTableBodyElement().getRows();
     return rows.getLength() > row ? rows.getItem(row) : null;
=======================================
--- /trunk/user/test/com/google/gwt/user/cellview/client/AbstractCellTableTestBase.java Thu May 26 04:44:13 2011 +++ /trunk/user/test/com/google/gwt/user/cellview/client/AbstractCellTableTestBase.java Wed Jun 1 10:50:41 2011
@@ -21,6 +21,7 @@
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.dom.client.TableCellElement;
+import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.LoadingStateChangeEvent.LoadingState;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
@@ -271,6 +272,28 @@
       // Expected.
     }
   }
+
+  public void testSetColumnWidth() {
+ AbstractCellTable<String> table = createAbstractHasData(new TextCell());
+    Column<String, ?> col0 = new MockColumn<String, String>();
+    Column<String, ?> col1 = new MockColumn<String, String>();
+    Column<String, ?> col2 = new MockColumn<String, String>();
+
+    // Set a column width.
+    table.setColumnWidth(col0, "100px");
+    table.setColumnWidth(col1, 200.0, Unit.EM);
+    assertEquals("100px", table.getColumnWidth(col0));
+
+    // Some browsers return 200.0, others 200.
+    assertTrue(table.getColumnWidth(col1).contains("200"));
+
+    // Check a column that has not been set.
+    assertNull(table.getColumnWidth(col2));
+
+    // Check a column that has been cleared.
+    table.clearColumnWidth(col0);
+    assertNull(table.getColumnWidth(col0));
+  }

   public void testSetEmptyTableWidget() {
AbstractCellTable<String> table = createAbstractHasData(new TextCell());

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

Reply via email to