Reviewers: Dan Rice,

Description:
This patch allow empty row data lists that start on the pageStart to
pass through the AbstractListViewAdapter and HasDataPresenter down to
the HasData implementation (such as CellList).  This ensures that Cell
Widgets clear the view when the row count goes to 0.  Before this
change, setting the rowCount to zero would redraw with the empty list,
but the empty list was considered "out of range."
http://code.google.com/p/google-web-toolkit/issues/detail?id=5149


Please review this at http://gwt-code-reviews.appspot.com/756801/show

Affected files:
  M user/src/com/google/gwt/user/cellview/client/HasDataPresenter.java
  M user/src/com/google/gwt/view/client/AbstractListViewAdapter.java
  M user/test/com/google/gwt/user/cellview/client/HasDataPresenterTest.java
  M user/test/com/google/gwt/view/client/AbstractListViewAdapterTest.java


Index: user/src/com/google/gwt/user/cellview/client/HasDataPresenter.java
===================================================================
--- user/src/com/google/gwt/user/cellview/client/HasDataPresenter.java (revision 8519) +++ user/src/com/google/gwt/user/cellview/client/HasDataPresenter.java (working copy)
@@ -381,8 +381,9 @@
     int pageEnd = pageStart + pageSize;
     int boundedStart = Math.max(start, pageStart);
     int boundedEnd = Math.min(valuesEnd, pageEnd);
-    if (boundedStart >= boundedEnd) {
+    if (start != pageStart && boundedStart >= boundedEnd) {
       // The data is out of range for the current page.
+      // Intentionally allow empty lists that start on the page start.
       return;
     }

Index: user/src/com/google/gwt/view/client/AbstractListViewAdapter.java
===================================================================
--- user/src/com/google/gwt/view/client/AbstractListViewAdapter.java (revision 8519) +++ user/src/com/google/gwt/view/client/AbstractListViewAdapter.java (working copy)
@@ -207,8 +207,9 @@
     int curStart = range.getStart();
     int curLength = range.getLength();
     int curEnd = curStart + curLength;
-    if (curStart < end && curEnd > start) {
+    if (start == curStart || (curStart < end && curEnd > start)) {
       // Fire the handler with the data that is in the range.
+      // Allow an empty list that starts on the page start.
       int realStart = curStart < start ? start : curStart;
       int realEnd = curEnd > end ? end : curEnd;
       int realLength = realEnd - realStart;
Index: user/test/com/google/gwt/user/cellview/client/HasDataPresenterTest.java
===================================================================
--- user/test/com/google/gwt/user/cellview/client/HasDataPresenterTest.java (revision 8519) +++ user/test/com/google/gwt/user/cellview/client/HasDataPresenterTest.java (working copy)
@@ -509,6 +509,27 @@
     view.assertLoadingState(LoadingState.LOADED);
   }

+  /**
+ * Setting an empty list that starts on the page start should pass through to
+   * the view.
+   */
+  public void testSetRowValuesChangesEmptySet() {
+    HasData<String> listView = new MockHasData<String>();
+    MockView<String> view = new MockView<String>();
+    HasDataPresenter<String> presenter = new HasDataPresenter<String>(
+        listView, view, 10);
+
+    // Set the initial data size.
+    presenter.setRowCount(10, true);
+    view.assertLoadingState(LoadingState.LOADING);
+
+    // Set an empty list of row values.
+    presenter.setRowValues(0, createData(0, 0));
+    view.assertLoadingState(LoadingState.LOADING);
+    view.assertReplaceAllChildrenCalled(true);
+    view.assertReplaceChildrenCalled(false);
+  }
+
   public void testSetRowValuesOutsideRange() {
     HasData<String> listView = new MockHasData<String>();
     MockView<String> view = new MockView<String>();
Index: user/test/com/google/gwt/view/client/AbstractListViewAdapterTest.java
===================================================================
--- user/test/com/google/gwt/view/client/AbstractListViewAdapterTest.java (revision 8519) +++ user/test/com/google/gwt/view/client/AbstractListViewAdapterTest.java (working copy)
@@ -217,6 +217,15 @@
       view.clearLastRowValuesAndRange();
     }

+    // Empty data list starting at page start.
+    {
+      List<String> values = createData(10, 0);
+      adapter.updateViewData(10, 0, values);
+      assertEquals(values, view.getLastRowValues());
+      assertEquals(new Range(10, 0), view.getLastRowValuesRange());
+      view.clearLastRowValuesAndRange();
+    }
+
     // Data before range.
     {
       List<String> values = createData(5, 5);


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

Reply via email to