Revision: 8425
Author: [email protected]
Date: Wed Jul 28 08:02:11 2010
Log: Resubmitting this change because I accidentally included changes from
another patch the first time I submitted.
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=8425
Modified:
/trunk/user/src/com/google/gwt/view/client/AbstractListViewAdapter.java
=======================================
--- /trunk/user/src/com/google/gwt/view/client/AbstractListViewAdapter.java
Wed Jul 28 07:12:59 2010
+++ /trunk/user/src/com/google/gwt/view/client/AbstractListViewAdapter.java
Wed Jul 28 08:02:11 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,11 +22,11 @@
/**
* 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>
{
@@ -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) {
@@ -58,13 +68,19 @@
}
views.add(view);
view.setDelegate(delegate);
+
+ // Update the data size.
+ if (lastDataSize >= 0) {
+ view.setDataSize(lastDataSize, lastDataSizeExact);
+ }
+
delegate.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 +90,7 @@
/**
* Get the {...@link ProvidesKey} that provides keys for list items.
- *
+ *
* @return the {...@link ProvidesKey}
*/
public ProvidesKey<T> getKeyProvider() {
@@ -83,7 +99,7 @@
/**
* Get the current ranges of all views.
- *
+ *
* @return the ranges
*/
public Range[] getRanges() {
@@ -97,7 +113,7 @@
/**
* Get the set of views currently assigned to this adapter.
- *
+ *
* @return the set of {...@link ListView}
*/
public Set<ListView<T>> getViews() {
@@ -114,7 +130,7 @@
/**
* Set the {...@link ProvidesKey} that provides keys for list items.
- *
+ *
* @param keyProvider the {...@link ProvidesKey}
*/
public void setKeyProvider(ProvidesKey<T> keyProvider) {
@@ -123,18 +139,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 +160,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 +173,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 +191,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