Reviewers: rchandia,
Description:
Adding a constructor overload to CellTable that takes a loading
indicator widget. For legacy support, CellTable uses the
Resources.cellTableLoading() ImageResource to create a loading
indicator. However, the default loading animation adds 20KB to the
compiled code. Using the overloaded constructor, users can provide a
lighter weight loading indicator and avoid the reference to
cellTableLoading(), allowing the compiler to optimize it out.
Please review this at http://gwt-code-reviews.appspot.com/1371805/
Affected files:
M user/src/com/google/gwt/user/cellview/client/CellTable.java
Index: user/src/com/google/gwt/user/cellview/client/CellTable.java
===================================================================
--- user/src/com/google/gwt/user/cellview/client/CellTable.java (revision
9793)
+++ user/src/com/google/gwt/user/cellview/client/CellTable.java (working
copy)
@@ -482,6 +482,19 @@
return DEFAULT_RESOURCES;
}
+ /**
+ * Create the default loading indicator using the loading image in the
+ * specified {@link Resources}.
+ *
+ * @param resources the resources
+ * @return a widget loading indicator
+ */
+ private static Widget createDefaultLoadingIndicator(Resources resources)
{
+ ImageResource loadingImg = resources.cellTableLoading();
+ return (loadingImg == null) ? null
+ : new Image(resources.cellTableLoading());
+ }
+
final TableColElement colgroup;
private boolean cellIsEditing;
@@ -593,6 +606,30 @@
*/
public CellTable(final int pageSize, Resources resources,
ProvidesKey<T> keyProvider) {
+ this(pageSize, resources, keyProvider,
+ createDefaultLoadingIndicator(resources));
+ }
+
+ /**
+ * Constructs a table with the specified page size, {@link Resources},
key
+ * provider, and loading indicator.
+ *
+ * <p>
+ * The default resources used by {@link CellTable} include an animated
loading
+ * indicator that increases code size by about 20KB. If you want to
minimize
+ * the size of your application, specify your own loading widget that
uses a
+ * smaller image or does not use an image at all.
+ * </p>
+ *
+ * @param pageSize the page size
+ * @param resources the resources to use for this widget
+ * @param keyProvider an instance of ProvidesKey<T>, or null if the
record
+ * object should act as its own key
+ * @param loadingIndicator the widget to use as a loading indicator, or
null
+ * to disable
+ */
+ public CellTable(final int pageSize, Resources resources,
+ ProvidesKey<T> keyProvider, Widget loadingIndicator) {
super(Document.get().createTableElement(), pageSize, keyProvider);
if (TABLE_IMPL == null) {
TABLE_IMPL = GWT.create(Impl.class);
@@ -643,14 +680,8 @@
loadingIndicatorContainer.setStyleName(style.cellTableLoading());
}
- /*
- * Set the default loading indicator to use if the user provided a
loading
- * image resource.
- */
- ImageResource loadingImg = resources.cellTableLoading();
- if (loadingImg != null) {
- setLoadingIndicator(new Image(loadingImg));
- }
+ // Set the loading indicator.
+ setLoadingIndicator(loadingIndicator); // Can be null.
// Sink events.
Set<String> eventTypes = new HashSet<String>();
@@ -1106,7 +1137,7 @@
/**
* Set the widget to display when the table has no rows.
*
- * @param widget the empty table widget
+ * @param widget the empty table widget, or null to disable
*/
public void setEmptyTableWidget(Widget widget) {
emptyTableWidgetContainer.setWidget(widget);
@@ -1115,7 +1146,7 @@
/**
* Set the widget to display when the data is loading.
*
- * @param widget the loading indicator
+ * @param widget the loading indicator, or null to disable
*/
public void setLoadingIndicator(Widget widget) {
loadingIndicatorContainer.setWidget(widget);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors