Adding a new method AbstractHasData#setRowData(List) to make CellList and CellTable easier to use without a data provider. Currently, users must call setRowCount() any time the row count changes in order to hide truncated rows. That makes sense in a DataProvider world where the CellTable is showing a small subset of the total data. However, some users want to use CellTable as a standalone widget, without worrying about setting the total row count.
Review at http://gwt-code-reviews.appspot.com/1079801
Review by: sbrubaker@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9190 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/cellview/client/AbstractHasData.java b/user/src/com/google/gwt/user/cellview/client/AbstractHasData.java
index b819263..79cf0a4 100644
--- a/user/src/com/google/gwt/user/cellview/client/AbstractHasData.java
+++ b/user/src/com/google/gwt/user/cellview/client/AbstractHasData.java
@@ -545,6 +545,25 @@
presenter.setRowCount(size, isExact);
}
+ /**
+ * <p>
+ * Set the complete list of values to display on one page.
+ * </p>
+ * <p>
+ * Equivalent to calling {@link #setRowCount(int)} with the length of the list
+ * of values, {@link #setVisibleRange(Range)} from 0 to the size of the list
+ * of values, and {@link #setRowData(int, List)} with a start of 0 and the
+ * specified list of values.
+ * </p>
+ *
+ * @param values
+ */
+ public final void setRowData(List<? extends T> values) {
+ setRowCount(values.size());
+ setVisibleRange(0, values.size());
+ setRowData(0, values);
+ }
+
public void setRowData(int start, List<? extends T> values) {
presenter.setRowData(start, values);
}
diff --git a/user/src/com/google/gwt/view/client/HasData.java b/user/src/com/google/gwt/view/client/HasData.java
index 31ec457..66f71da 100644
--- a/user/src/com/google/gwt/view/client/HasData.java
+++ b/user/src/com/google/gwt/view/client/HasData.java
@@ -34,8 +34,18 @@
SelectionModel<? super T> getSelectionModel();
/**
+ * <p>
* Set a values associated with the rows in the visible range.
- *
+ * </p>
+ * <p>
+ * This method <i>does not</i> replace all rows in the display; it replaces
+ * the row values starting at the specified start index through the length of
+ * the the specified values. You must call {@link #setRowCount(int)} to set
+ * the total number of rows in the display. You should also use
+ * {@link #setRowCount(int)} to remove rows when the total number of rows
+ * decreases.
+ * </p>
+ *
* @param start the start index of the data
* @param values the values within the range
*/
diff --git a/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java b/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java
index 31b9c33..be504c6 100644
--- a/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java
+++ b/user/test/com/google/gwt/user/cellview/client/AbstractHasDataTestBase.java
@@ -20,6 +20,7 @@
import com.google.gwt.regexp.shared.RegExp;
import com.google.gwt.user.client.Window;
import com.google.gwt.view.client.ListDataProvider;
+import com.google.gwt.view.client.Range;
import java.util.ArrayList;
import java.util.List;
@@ -81,6 +82,36 @@
assertEquals("test 12", items.get(2));
}
+ public void testSetRowData() {
+ AbstractHasData<String> display = createAbstractHasData();
+
+ // Set exact data.
+ List<String> values = createData(0, 62);
+ display.setRowData(values);
+ assertEquals(62, display.getRowCount());
+ assertTrue(display.isRowCountExact());
+ assertEquals(values, display.getDisplayedItems());
+ assertEquals(new Range(0, 62), display.getVisibleRange());
+
+ // Add some data.
+ List<String> moreValues = createData(62, 10);
+ display.setVisibleRange(0, 100);
+ display.setRowData(62, moreValues);
+ assertEquals(72, display.getRowCount());
+ assertTrue(display.isRowCountExact());
+ assertEquals("test 62", display.getDisplayedItem(62));
+ assertEquals("test 71", display.getDisplayedItem(71));
+ assertEquals(72, display.getDisplayedItems().size());
+ assertEquals(new Range(0, 100), display.getVisibleRange());
+
+ // Push the exact data again.
+ display.setRowData(values);
+ assertEquals(62, display.getRowCount());
+ assertTrue(display.isRowCountExact());
+ assertEquals(values, display.getDisplayedItems());
+ assertEquals(new Range(0, 62), display.getVisibleRange());
+ }
+
public void testSetTabIndex() {
// Skip this test on Safari 3 because it does not support focusable divs.
String userAgent = Window.Navigator.getUserAgent();