Revision: 8423
Author: [email protected]
Date: Wed Jul 28 06:51:41 2010
Log: Fixing a bug in AbstractListViewAdapter where it does not inform new
views of the current data size. We now cache the data size and pass it to
views as they are added.
Review at http://gwt-code-reviews.appspot.com/721801
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8423
Modified:
/trunk/user/src/com/google/gwt/view/client/AbstractListViewAdapter.java
=======================================
--- /trunk/user/src/com/google/gwt/view/client/AbstractListViewAdapter.java
Tue Jul 20 08:04:29 2010
+++ /trunk/user/src/com/google/gwt/view/client/AbstractListViewAdapter.java
Wed Jul 28 06:51:41 2010
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -22,22 +22,22 @@
/**
* A base implementation of a data source for list views.
- *
+ *
* <p>
* Note: This class is new and its interface subject to change.
* </p>
- *
+ *
* @param <T> the data type of records in the list
*/
public abstract class AbstractListViewAdapter<T> implements ProvidesKey<T>
{
- private class Delegate implements ListView.Delegate<T> {
+ private class DataProvider implements ListView.DataProvider<T> {
public void onRangeChanged(ListView<T> view) {
AbstractListViewAdapter.this.onRangeChanged(view);
}
}
- private final Delegate delegate = new Delegate();
+ private final DataProvider dataProvider = new DataProvider();
private Set<ListView<T>> views = new HashSet<ListView<T>>();
@@ -46,10 +46,20 @@
*/
private ProvidesKey<T> keyProvider;
+ /**
+ * The last data size.
+ */
+ private int lastDataSize = -1;
+
+ /**
+ * Indicates whether or not the last data size is exact.
+ */
+ private boolean lastDataSizeExact;
+
/**
* Adds a view to this adapter. The current range of interest of the
view will
* be populated with data.
- *
+ *
* @param view a {...@link ListView}.
*/
public void addView(ListView<T> view) {
@@ -57,14 +67,23 @@
throw new IllegalStateException("ListView already added");
}
views.add(view);
- view.setDelegate(delegate);
- delegate.onRangeChanged(view);
+
+ // Set the data provider. Do not initialize until we have a change to
set
+ // the data size.
+ view.setDataProvider(dataProvider, false);
+
+ // Update the data size.
+ if (lastDataSize >= 0) {
+ view.setDataSize(lastDataSize, lastDataSizeExact);
+ }
+
+ dataProvider.onRangeChanged(view);
}
/**
* Get the key for a list item. The default implementation returns the
item
* itself.
- *
+ *
* @param item the list item
* @return the key that represents the item
*/
@@ -74,7 +93,7 @@
/**
* Get the {...@link ProvidesKey} that provides keys for list items.
- *
+ *
* @return the {...@link ProvidesKey}
*/
public ProvidesKey<T> getKeyProvider() {
@@ -83,7 +102,7 @@
/**
* Get the current ranges of all views.
- *
+ *
* @return the ranges
*/
public Range[] getRanges() {
@@ -97,7 +116,7 @@
/**
* Get the set of views currently assigned to this adapter.
- *
+ *
* @return the set of {...@link ListView}
*/
public Set<ListView<T>> getViews() {
@@ -109,12 +128,12 @@
throw new IllegalStateException("ListView not present");
}
views.remove(view);
- view.setDelegate(null);
+ view.setDataProvider(null);
}
/**
* Set the {...@link ProvidesKey} that provides keys for list items.
- *
+ *
* @param keyProvider the {...@link ProvidesKey}
*/
public void setKeyProvider(ProvidesKey<T> keyProvider) {
@@ -123,18 +142,20 @@
/**
* Called when a view changes its range of interest.
- *
+ *
* @param view the view whose range has changed
*/
protected abstract void onRangeChanged(ListView<T> view);
/**
* Inform the views of the total number of items that are available.
- *
+ *
* @param size the new size
* @param exact true if the size is exact, false if it is a guess
*/
protected void updateDataSize(int size, boolean exact) {
+ lastDataSize = size;
+ lastDataSizeExact = exact;
for (ListView<T> view : views) {
view.setDataSize(size, exact);
}
@@ -142,7 +163,7 @@
/**
* Inform the views of the new data.
- *
+ *
* @param start the start index
* @param length the length of the data
* @param values the data values
@@ -155,14 +176,14 @@
/**
* Informs a single view of new data.
- *
+ *
* @param view the view to be updated
* @param start the start index
* @param length the length of the data
* @param values the data values
*/
- protected void updateViewData(ListView<T> view, int start, int length,
- List<T> values) {
+ protected void updateViewData(
+ ListView<T> view, int start, int length, List<T> values) {
int end = start + length;
Range range = view.getRange();
int curStart = range.getStart();
@@ -173,8 +194,8 @@
int realStart = curStart < start ? start : curStart;
int realEnd = curEnd > end ? end : curEnd;
int realLength = realEnd - realStart;
- List<T> realValues = values.subList(realStart - start, realStart -
start
- + realLength);
+ List<T> realValues = values.subList(
+ realStart - start, realStart - start + realLength);
view.setData(realStart, realLength, realValues);
}
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors