Revision: 7887
Author: [email protected]
Date: Wed Apr 7 09:03:27 2010
Log: Changes ListRegistration to carry information about its associated
handler
and range of interest. This allows ListListModel (and theoretically other
models) to call back directly to views whose range of interest changes
without having to re-render all views.
Review at http://gwt-code-reviews.appspot.com/314801
http://code.google.com/p/google-web-toolkit/source/detail?r=7887
Modified:
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/PagingTableListView.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/SimpleCellList.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/AbstractListModel.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/AsyncListModel.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/ListListModel.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/ListModel.java
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/ListRegistration.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksDesktop.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksMobile.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/TransactionTreeViewModel.java
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/tree/TreeSample.gwt.xml
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/tree/client/MyTreeViewModel.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeListView.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportListView.java
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/PagingTableListView.java
Fri Apr 2 11:25:19 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/PagingTableListView.java
Wed Apr 7 09:03:27 2010
@@ -59,7 +59,7 @@
private ArrayList<T> data = new ArrayList<T>();
private List<Header<?>> footers = new ArrayList<Header<?>>();
private List<Header<?>> headers = new ArrayList<Header<?>>();
- private ListRegistration listReg;
+ private ListRegistration<T> listReg;
private ListModel<T> listModel;
private int numPages;
@@ -86,7 +86,7 @@
// TODO: Total hack. It would almost definitely be preferable to sink
only
// those events actually needed by cells.
sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.KEYEVENTS
- | Event.ONCHANGE);
+ | Event.ONCHANGE | Event.FOCUSEVENTS);
}
public void addColumn(Column<T, ?, ?> col) {
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/SimpleCellList.java
Fri Mar 26 06:51:35 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/client/SimpleCellList.java
Wed Apr 7 05:51:51 2010
@@ -45,7 +45,7 @@
private int initialMaxSize;
private int maxSize;
private ListModel<T> model;
- private ListRegistration reg;
+ private ListRegistration<T> reg;
private int seq; // for debugging - TODO: remove
private final Element showFewerElem;
private final Element showMoreElem;
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/AbstractListModel.java
Fri Apr 2 11:25:19 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/AbstractListModel.java
Wed Apr 7 05:51:51 2010
@@ -57,7 +57,7 @@
* An implementation of {...@link ListRegistration} that remembers its own
range
* of interest.
*/
- private class DefaultListRegistration implements ListRegistration {
+ private class DefaultListRegistration implements ListRegistration<T> {
private final ListHandler<T> handler;
private int start;
@@ -71,6 +71,18 @@
public DefaultListRegistration(ListHandler<T> handler) {
this.handler = handler;
}
+
+ public ListHandler<T> getHandler() {
+ return handler;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public int getStart() {
+ return start;
+ }
public void removeHandler() {
if (!registrations.contains(this)) {
@@ -82,19 +94,7 @@
public void setRangeOfInterest(int start, int length) {
this.start = start;
this.length = length;
- onRangeChanged(start, length);
- }
-
- protected ListHandler<T> getHandler() {
- return handler;
- }
-
- protected int getLength() {
- return length;
- }
-
- protected int getStart() {
- return start;
+ onRangeChanged(this, start, length);
}
}
@@ -108,7 +108,7 @@
*/
private List<DefaultListRegistration> registrations = new
ArrayList<DefaultListRegistration>();
- public ListRegistration addListHandler(ListHandler<T> handler) {
+ public ListRegistration<T> addListHandler(ListHandler<T> handler) {
DefaultListRegistration reg = new DefaultListRegistration(handler);
registrations.add(reg);
return reg;
@@ -159,8 +159,13 @@
/**
* Called when a view changes its range of interest.
+ *
+ * @param reg the list whose range has changed
+ * @param start the start of the list's new range
+ * @param length the length of the list's new range
*/
- protected abstract void onRangeChanged(int start, int length);
+ protected abstract void onRangeChanged(ListRegistration<T> reg, int
start,
+ int length);
/**
* Inform the views of the total number of items that are available.
@@ -183,21 +188,33 @@
* @param values the data values
*/
protected void updateViewData(int start, int length, List<T> values) {
+ for (ListRegistration<T> reg : registrations) {
+ updateViewData(reg, start, length, values);
+ }
+ }
+
+ /**
+ * Informs a single view (via its {...@link ListRegistration}) of new data.
+ *
+ * @param reg the list registration of 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(ListRegistration<T> reg, int start, int
length, List<T> values) {
int end = start + length;
- for (DefaultListRegistration reg : registrations) {
- int curStart = reg.getStart();
- int curLength = reg.getLength();
- int curEnd = curStart + curLength;
- if (curStart < end && curEnd > start) {
- // Fire the handler with the data that is in the range.
- 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);
- ListEvent<T> event = new ListEvent<T>(realStart, realLength,
realValues);
- reg.getHandler().onDataChanged(event);
- }
+ int curStart = reg.getStart();
+ int curLength = reg.getLength();
+ int curEnd = curStart + curLength;
+ if (curStart < end && curEnd > start) {
+ // Fire the handler with the data that is in the range.
+ 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);
+ ListEvent<T> event = new ListEvent<T>(realStart, realLength,
realValues);
+ reg.getHandler().onDataChanged(event);
}
}
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/AsyncListModel.java
Fri Mar 19 07:22:04 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/AsyncListModel.java
Wed Apr 7 05:51:51 2010
@@ -31,6 +31,7 @@
* @param size the new size
* @param exact true if the size is exact, false if it is a guess
*/
+ @Override
public void updateDataSize(int size, boolean exact) {
super.updateDataSize(size, exact);
}
@@ -42,6 +43,7 @@
* @param length the length of the data
* @param values the data values
*/
+ @Override
public void updateViewData(int start, int length, List<T> values) {
super.updateViewData(start, length, values);
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/ListListModel.java
Wed Mar 31 07:22:26 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/ListListModel.java
Wed Apr 7 05:51:51 2010
@@ -282,7 +282,23 @@
/**
* The wrapper around the actual list.
*/
- private ListWrapper listWrapper = new ListWrapper(new ArrayList<T>());
+ private ListWrapper listWrapper;
+
+ /**
+ * Creates an empty model.
+ */
+ public ListListModel() {
+ this(new ArrayList<T>());
+ }
+
+ /**
+ * Creates a list model that wraps the given collection. Changes to the
+ * wrapped list must be made via this model in order to be correctly
applied
+ * to views.
+ */
+ public ListListModel(List<T> wrappee) {
+ listWrapper = new ListWrapper(wrappee);
+ }
/**
* Get the list that backs this model. Changes to the list will be
reflected
@@ -294,11 +310,20 @@
return listWrapper;
}
- @Override
- protected void onRangeChanged(int start, int length) {
- // TODO - update size only when needed
- // TODO - update only relevant range of data
+ /**
+ * Replaces this model's list.
+ *
+ * @param wrappee the model's new list
+ */
+ public void setList(List<T> wrappee) {
+ listWrapper = new ListWrapper(wrappee);
updateDataSize(listWrapper.size(), true);
updateViewData(0, listWrapper.size(), listWrapper);
}
-}
+
+ @Override
+ protected void onRangeChanged(ListRegistration<T> reg, int start, int
length) {
+ // TODO - update only relevant range of data
+ updateViewData(reg, 0, listWrapper.size(), listWrapper);
+ }
+}
=======================================
--- /trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/ListModel.java
Fri Apr 2 11:25:19 2010
+++ /trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/ListModel.java
Wed Apr 7 05:51:51 2010
@@ -27,5 +27,5 @@
*
* @param handler the {...@link ListHandler}
*/
- ListRegistration addListHandler(ListHandler<T> handler);
-}
+ ListRegistration<T> addListHandler(ListHandler<T> handler);
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/ListRegistration.java
Fri Feb 26 09:32:06 2010
+++
/trunk/bikeshed/src/com/google/gwt/bikeshed/list/shared/ListRegistration.java
Wed Apr 7 05:51:51 2010
@@ -19,8 +19,10 @@
/**
* Registration returned from a call to ListModel#addListHandler.
+ *
+ * @param <T> the data type displayed by the list
*/
-public interface ListRegistration extends HandlerRegistration {
+public interface ListRegistration<T> extends HandlerRegistration {
/**
* Set the range of data that is interesting to the {...@link ListHandler}.
@@ -29,4 +31,19 @@
* @param length the length
*/
void setRangeOfInterest(int start, int length);
-}
+
+ /**
+ * Gets the {...@link ListHandler} associated with this registration.
+ */
+ ListHandler<T> getHandler();
+
+ /**
+ * Gets the length of this registration's range of interest.
+ */
+ int getLength();
+
+ /**
+ * Gets the start of this registration's range of interest.
+ */
+ int getStart();
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksDesktop.java
Fri Apr 2 11:25:19 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksDesktop.java
Wed Apr 7 05:51:51 2010
@@ -18,6 +18,7 @@
import com.google.gwt.bikeshed.cells.client.FieldUpdater;
import com.google.gwt.bikeshed.list.shared.AsyncListModel;
import com.google.gwt.bikeshed.list.shared.ListListModel;
+import com.google.gwt.bikeshed.list.shared.ListRegistration;
import com.google.gwt.bikeshed.list.shared.Range;
import com.google.gwt.bikeshed.tree.client.SideBySideTreeView;
import com.google.gwt.bikeshed.tree.client.TreeNode;
@@ -113,7 +114,7 @@
// of the UiFactories need the models to instantiate their widgets.
searchListModel = new AsyncListModel<StockQuote>() {
@Override
- protected void onRangeChanged(int start, int length) {
+ protected void onRangeChanged(ListRegistration reg, int start, int
length) {
update();
}
};
@@ -121,7 +122,7 @@
favoritesListModel = new AsyncListModel<StockQuote>() {
@Override
- protected void onRangeChanged(int start, int length) {
+ protected void onRangeChanged(ListRegistration reg, int start, int
length) {
update();
}
};
@@ -129,7 +130,7 @@
playerScoresListModel = new AsyncListModel<PlayerInfo>() {
@Override
- protected void onRangeChanged(int start, int length) {
+ protected void onRangeChanged(ListRegistration reg, int start, int
length) {
}
};
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksMobile.java
Fri Apr 2 11:25:19 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/StocksMobile.java
Wed Apr 7 05:51:51 2010
@@ -17,6 +17,7 @@
import com.google.gwt.bikeshed.list.client.PagingTableListView;
import com.google.gwt.bikeshed.list.shared.AsyncListModel;
+import com.google.gwt.bikeshed.list.shared.ListRegistration;
import com.google.gwt.bikeshed.list.shared.Range;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.NumberFormat;
@@ -74,7 +75,7 @@
// of the UiFactories need the models to instantiate their widgets.
favoritesListModel = new AsyncListModel<StockQuote>() {
@Override
- protected void onRangeChanged(int start, int length) {
+ protected void onRangeChanged(ListRegistration reg, int start, int
length) {
update();
}
};
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/TransactionTreeViewModel.java
Wed Apr 7 05:28:43 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/stocks/client/TransactionTreeViewModel.java
Wed Apr 7 05:51:51 2010
@@ -22,6 +22,7 @@
import com.google.gwt.bikeshed.list.shared.AsyncListModel;
import com.google.gwt.bikeshed.list.shared.ListListModel;
import com.google.gwt.bikeshed.list.shared.ListModel;
+import com.google.gwt.bikeshed.list.shared.ListRegistration;
import com.google.gwt.bikeshed.tree.client.TreeNode;
import com.google.gwt.bikeshed.tree.client.TreeViewModel;
import com.google.gwt.sample.bikeshed.stocks.shared.StockQuote;
@@ -51,7 +52,7 @@
}
@Override
- protected void onRangeChanged(int start, int length) {
+ protected void onRangeChanged(ListRegistration reg, int start, int
length) {
updater.update();
}
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/tree/TreeSample.gwt.xml
Tue Mar 23 06:01:07 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/tree/TreeSample.gwt.xml
Wed Apr 7 05:51:51 2010
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit
0.0.999//EN" "http://google-web-toolkit.googlecode.com/svn/tags/0.0.999/distro-source/core/src/gwt-module.dtd">
-<module rename-to='tree'>
+<module rename-to='treesample'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<inherits name='com.google.gwt.bikeshed.list.List'/>
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/tree/client/MyTreeViewModel.java
Thu Apr 1 12:13:45 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/bikeshed/tree/client/MyTreeViewModel.java
Wed Apr 7 05:51:51 2010
@@ -24,6 +24,7 @@
import com.google.gwt.bikeshed.list.shared.AbstractListModel;
import com.google.gwt.bikeshed.list.shared.ListModel;
import com.google.gwt.bikeshed.list.shared.SelectionModel;
+import com.google.gwt.bikeshed.list.shared.ListRegistration;
import com.google.gwt.bikeshed.tree.client.TreeNode;
import com.google.gwt.bikeshed.tree.client.TreeViewModel;
import com.google.gwt.core.client.GWT;
@@ -47,7 +48,7 @@
}
@Override
- protected void onRangeChanged(int start, int length) {
+ protected void onRangeChanged(ListRegistration reg, int start, int
length) {
List<Integer> values = new ArrayList<Integer>(1);
values.add(wordLength);
updateDataSize(1, true);
@@ -63,7 +64,7 @@
}
@Override
- protected void onRangeChanged(int start, int length) {
+ protected void onRangeChanged(ListRegistration reg, int start, int
length) {
String prefix = value.endsWith("...") ? value.substring(0,
value.length() - 3) : value;
dataService.getNext(prefix, new AsyncCallback<List<String>>() {
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeListView.java
Sat Apr 3 11:30:35 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeListView.java
Wed Apr 7 05:51:51 2010
@@ -22,6 +22,7 @@
import com.google.gwt.bikeshed.list.client.TextColumn;
import com.google.gwt.bikeshed.list.client.TextHeader;
import com.google.gwt.bikeshed.list.shared.ListModel;
+import com.google.gwt.bikeshed.list.shared.ListRegistration;
import com.google.gwt.sample.expenses.gwt.place.ExpensesPlaces;
import com.google.gwt.sample.expenses.gwt.request.ExpensesRequestFactory;
import com.google.gwt.sample.expenses.gwt.request.EmployeeKey;
@@ -80,9 +81,8 @@
private static ListModel<Values<EmployeeKey>> getModel(
final ExpensesRequestFactory requests) {
return new ListModelAdapter<EmployeeKey>() {
-
@Override
- protected void onRangeChanged(int start, int length) {
+ protected void onRangeChanged(ListRegistration reg, int start, int
length) {
requests.employeeRequest().findAllEmployees().forProperties(
getProperties()).to(this).fire();
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportListView.java
Sat Apr 3 11:30:35 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportListView.java
Wed Apr 7 05:51:51 2010
@@ -24,6 +24,7 @@
import com.google.gwt.bikeshed.list.client.TextColumn;
import com.google.gwt.bikeshed.list.client.TextHeader;
import com.google.gwt.bikeshed.list.shared.ListModel;
+import com.google.gwt.bikeshed.list.shared.ListRegistration;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.sample.expenses.gwt.place.ExpensesPlaces;
import com.google.gwt.sample.expenses.gwt.request.ExpensesRequestFactory;
@@ -85,9 +86,8 @@
private static ListModel<Values<ReportKey>> getModel(
final ExpensesRequestFactory requests) {
return new ListModelAdapter<ReportKey>() {
-
@Override
- protected void onRangeChanged(int start, int length) {
+ protected void onRangeChanged(ListRegistration reg, int start, int
length) {
requests.reportRequest().findAllReports().forProperties(getProperties()).to(
this).fire();
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
To unsubscribe, reply using "remove me" as the subject.