Revision: 9384
Author: [email protected]
Date: Wed Dec 8 13:58:54 2010
Log: Change Activity to an abstract class, to allow its api to evolve.
Gwt issue http://code.google.com/p/google-web-toolkit/issues/detail?id=5730
Review at http://gwt-code-reviews.appspot.com/1200801
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9384
Added:
/trunk/samples/expenses/src/main/resources
/trunk/samples/expenses/src/main/resources/log4j.properties
/trunk/user/src/com/google/gwt/activity/shared/IsActivity.java
/trunk/user/src/com/google/gwt/activity/shared/SimpleActivity.java
Deleted:
/trunk/user/src/com/google/gwt/activity/shared/AbstractActivity.java
Modified:
/trunk/samples/expenses/src/main/java/com/google/gwt/sample/expenses/client/ExpenseReportDetails.java
/trunk/samples/expenses/src/main/java/com/google/gwt/sample/expenses/client/ExpenseReportList.java
/trunk/samples/expenses/src/main/java/com/google/gwt/sample/expenses/client/ExpensesActivityMapper.java
/trunk/tools/api-checker/config/gwt21_22userApi.conf
/trunk/user/src/com/google/gwt/activity/shared/Activity.java
/trunk/user/src/com/google/gwt/activity/shared/ActivityManager.java
/trunk/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/activity/shared/IsActivity.java Wed Dec
8 13:58:54 2010
@@ -0,0 +1,28 @@
+/*
+ * 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
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.activity.shared;
+
+
+/**
+ * Implemented by objects that can return an {...@link Activity} aspect.
+ */
+public interface IsActivity {
+
+ /**
+ * Return the {...@link Activity} aspect of this object.
+ */
+ Activity asActivity();
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/activity/shared/SimpleActivity.java Wed
Dec 8 13:58:54 2010
@@ -0,0 +1,42 @@
+/*
+ * 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
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.activity.shared;
+
+
+/**
+ * Simple base implementation of {...@link Activity}.
+ */
+public abstract class SimpleActivity extends Activity {
+
+ /**
+ * Return null.
+ */
+ public String mayStop() {
+ return null;
+ }
+
+ /**
+ * No-op.
+ */
+ public void onCancel() {
+ }
+
+ /**
+ * No-op.
+ */
+ public void onStop() {
+ }
+}
=======================================
--- /trunk/user/src/com/google/gwt/activity/shared/AbstractActivity.java
Tue Oct 12 10:53:11 2010
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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
- * License for the specific language governing permissions and limitations
under
- * the License.
- */
-package com.google.gwt.activity.shared;
-
-/**
- * Simple Activity implementation that is always willing to stop,
- * and does nothing onStop and onCancel.
- */
-public abstract class AbstractActivity implements Activity {
-
- public String mayStop() {
- return null;
- }
-
- public void onCancel() {
- }
-
- public void onStop() {
- }
-}
=======================================
---
/trunk/samples/expenses/src/main/java/com/google/gwt/sample/expenses/client/ExpenseReportDetails.java
Wed Dec 1 05:40:20 2010
+++
/trunk/samples/expenses/src/main/java/com/google/gwt/sample/expenses/client/ExpenseReportDetails.java
Wed Dec 8 13:58:54 2010
@@ -16,6 +16,8 @@
package com.google.gwt.sample.expenses.client;
import com.google.gwt.activity.shared.Activity;
+import com.google.gwt.activity.shared.IsActivity;
+import com.google.gwt.activity.shared.SimpleActivity;
import com.google.gwt.cell.client.AbstractInputCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.DateCell;
@@ -23,7 +25,6 @@
import com.google.gwt.cell.client.NumberCell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.cell.client.ValueUpdater;
-import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
@@ -47,6 +48,7 @@
import com.google.gwt.requestfactory.ui.client.EntityProxyKeyProvider;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
+import com.google.gwt.safehtml.client.SafeHtmlTemplates.Template;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
@@ -89,11 +91,11 @@
* Details about the current expense report on the right side of the app,
* including the list of expenses.
*/
-public class ExpenseReportDetails extends Composite implements Activity {
+public class ExpenseReportDetails extends Composite implements IsActivity {
interface Binder extends UiBinder<Widget, ExpenseReportDetails> {
}
-
+
/**
* Fetches an employee and a report in parallel. A fine example of the
kind of
* thing that will no longer be necessary when RequestFactory provides
server
@@ -127,7 +129,7 @@
});
}
}
-
+
/**
* The resources applied to the table.
*/
@@ -323,6 +325,13 @@
}
}
+ private final Activity activityAspect = new SimpleActivity() {
+ @Override
+ public void start(AcceptsOneWidget panel, EventBus eventBus) {
+ ExpenseReportDetails.this.start(panel, eventBus);
+ }
+ };
+
private static Template template;
/**
@@ -468,6 +477,10 @@
}
});
}
+
+ public Activity asActivity() {
+ return activityAspect;
+ }
public ReportListPlace getReportListPlace() {
ReportListPlace listPlace = place.getListPlace();
@@ -477,13 +490,6 @@
public Anchor getReportsLink() {
return reportsLink;
}
-
- public String mayStop() {
- return null;
- }
-
- public void onCancel() {
- }
public void onExpenseRecordChanged(EntityProxyChange<ExpenseProxy>
event) {
final EntityProxyId<ExpenseProxy> proxyId = event.getProxyId();
@@ -531,10 +537,17 @@
}
}
- public void onStop() {
+ /**
+ * In this application, called by {...@link ExpensesActivityMapper} each
time a
+ * ReportListPlace is posted. In a more typical set up, this would be a
+ * constructor argument to a one shot activity, perhaps managing a shared
+ * widget view instance.
+ */
+ public void updateForPlace(final ReportPlace place) {
+ this.place = place;
}
- public void start(AcceptsOneWidget panel, EventBus eventBus) {
+ void start(AcceptsOneWidget panel, EventBus eventBus) {
final ReportListPlace listPlace = place.getListPlace();
if (listPlace.getEmployeeId() == null) {
@@ -573,16 +586,6 @@
panel.setWidget(this);
}
-
- /**
- * In this application, called by {...@link ExpensesActivityMapper} each
time a
- * ReportListPlace is posted. In a more typical set up, this would be a
- * constructor argument to a one shot activity, perhaps managing a shared
- * widget view instance.
- */
- public void updateForPlace(final ReportPlace place) {
- this.place = place;
- }
/**
* Add a column of a {...@link Comparable} type using default comparators.
=======================================
---
/trunk/samples/expenses/src/main/java/com/google/gwt/sample/expenses/client/ExpenseReportList.java
Tue Dec 7 22:33:06 2010
+++
/trunk/samples/expenses/src/main/java/com/google/gwt/sample/expenses/client/ExpenseReportList.java
Wed Dec 8 13:58:54 2010
@@ -16,6 +16,8 @@
package com.google.gwt.sample.expenses.client;
import com.google.gwt.activity.shared.Activity;
+import com.google.gwt.activity.shared.IsActivity;
+import com.google.gwt.activity.shared.SimpleActivity;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.DateCell;
@@ -76,7 +78,7 @@
* The list of expense reports on the right side of the app.
*/
public class ExpenseReportList extends Composite implements
- EntityProxyChange.Handler<ReportProxy>, Activity {
+ EntityProxyChange.Handler<ReportProxy>, IsActivity {
interface Binder extends UiBinder<Widget, ExpenseReportList> {
}
@@ -177,6 +179,23 @@
}
}
+ private final Activity activityAspect = new SimpleActivity() {
+ @Override
+ public void onCancel() {
+ ExpenseReportList.this.onCancel();
+ }
+
+ @Override
+ public void onStop() {
+ ExpenseReportList.this.onStop();
+ }
+
+ @Override
+ public void start(AcceptsOneWidget panel, EventBus eventBus) {
+ ExpenseReportList.this.start(panel, eventBus);
+ }
+ };
+
private static final ProvidesKey<ReportProxy> keyProvider = new
EntityProxyKeyProvider<ReportProxy>();
/**
@@ -337,12 +356,8 @@
});
}
- public String mayStop() {
- return null;
- }
-
- public void onCancel() {
- onStop();
+ public Activity asActivity() {
+ return activityAspect;
}
public void onProxyChange(EntityProxyChange<ReportProxy> event) {
@@ -358,24 +373,10 @@
i++;
}
}
-
- public void onStop() {
- running = false;
- refreshTimer.cancel();
- }
public void setListener(Listener listener) {
this.listener = listener;
}
-
- public void start(AcceptsOneWidget panel, EventBus eventBus) {
- running = true;
- doUpdateForPlace();
-
- EntityProxyChange.registerForProxyType(eventBus, ReportProxy.class,
this);
- requestReports(false);
- panel.setWidget(this);
- }
/**
* In this application, called by {...@link ExpensesActivityMapper} each
time a
@@ -397,6 +398,24 @@
p.setRangeLimited(true);
return p;
}
+
+ void onCancel() {
+ onStop();
+ }
+
+ void onStop() {
+ running = false;
+ refreshTimer.cancel();
+ }
+
+ void start(AcceptsOneWidget panel, EventBus eventBus) {
+ running = true;
+ doUpdateForPlace();
+
+ EntityProxyChange.registerForProxyType(eventBus, ReportProxy.class,
this);
+ requestReports(false);
+ panel.setWidget(this);
+ }
/**
* Add a sortable column to the table.
=======================================
---
/trunk/samples/expenses/src/main/java/com/google/gwt/sample/expenses/client/ExpensesActivityMapper.java
Sat Oct 16 18:02:46 2010
+++
/trunk/samples/expenses/src/main/java/com/google/gwt/sample/expenses/client/ExpensesActivityMapper.java
Wed Dec 8 13:58:54 2010
@@ -38,12 +38,12 @@
public Activity getActivity(Place place) {
if (place instanceof ReportListPlace) {
expenseList.updateForPlace((ReportListPlace) place);
- return expenseList;
+ return expenseList.asActivity();
}
if (place instanceof ReportPlace) {
expenseDetails.updateForPlace((ReportPlace) place);
- return expenseDetails;
+ return expenseDetails.asActivity();
}
return null;
=======================================
--- /trunk/tools/api-checker/config/gwt21_22userApi.conf Tue Dec 7
22:33:06 2010
+++ /trunk/tools/api-checker/config/gwt21_22userApi.conf Wed Dec 8
13:58:54 2010
@@ -113,6 +113,10 @@
# when adding to the white-list, include comments as to why the addition is
# being made.
+# Changes to make Activity api evolvable in 2.1.1
+com.google.gwt.activity.shared.AbstractActivity MISSING
+com.google.gwt.activity.shared.Activity STATIC_REMOVED
+
# RequestFactory tweaks in 2.1.1
com.google.gwt.requestfactory.client.DefaultRequestTransport::DefaultRequestTransport(Lcom/google/gwt/event/shared/EventBus;)
MISSING
com.google.gwt.requestfactory.shared.RequestEvent MISSING
=======================================
--- /trunk/user/src/com/google/gwt/activity/shared/Activity.java Tue Oct 12
10:53:11 2010
+++ /trunk/user/src/com/google/gwt/activity/shared/Activity.java Wed Dec 8
13:58:54 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
@@ -19,45 +19,51 @@
import com.google.gwt.user.client.ui.AcceptsOneWidget;
/**
- * Implemented by objects that control a piece of user interface, with a
life
- * cycle managed by an {...@link ActivityManager}, in response to
- * {...@link com.google.gwt.place.shared.PlaceChangeEvent} events as the user
- * navigates through the app.
+ * Object that controls a piece of user interface, with a life cycle
managed by
+ * an {...@link ActivityManager}.
+ * <p>
+ * Ideally this would be an interface rather than an abstract class, but we
+ * expect its api will need to evolve (slightly) in the near term. When it
+ * settles down, an interface may be introduced. To this end, future
versions of
+ * this class should not introduce non-trivial behavior.
+ * <p>
+ * For composition, see {...@link IsActivity}.
*/
-public interface Activity {
+public abstract class Activity {
+
/**
* Called when the user is trying to navigate away from this activity.
- *
+ *
* @return A message to display to the user, e.g. to warn of unsaved
work, or
* null to say nothing
*/
- String mayStop();
+ public abstract String mayStop();
/**
* Called when {...@link #start} has not yet replied to its callback, but
the
* user has lost interest.
*/
- void onCancel();
+ public abstract void onCancel();
/**
* Called when the Activity's widget has been removed from view. All
event
* handlers it registered will have been removed before this method is
called.
*/
- void onStop();
+ public abstract void onStop();
/**
* Called when the Activity should ready its widget for the user. When
the
* widget is ready (typically after an RPC response has been received),
* receiver should present it by calling
- * {...@link AcceptsOneWidget#setWidget(IsWidget)} on the given panel.
+ * {...@link AcceptsOneWidget#setWidget()} on the given panel.
* <p>
* Any handlers attached to the provided event bus will be de-registered
when
* the activity is stopped, so activities will rarely need to hold on to
the
* {...@link com.google.gwt.event.shared.HandlerRegistration
HandlerRegistration}
* instances returned by {...@link EventBus#addHandler}.
- *
+ *
* @param panel the panel to display this activity's widget when it is
ready
* @param eventBus the event bus
*/
- void start(AcceptsOneWidget panel, EventBus eventBus);
-}
+ public abstract void start(AcceptsOneWidget panel, EventBus eventBus);
+}
=======================================
--- /trunk/user/src/com/google/gwt/activity/shared/ActivityManager.java Wed
Oct 13 09:41:33 2010
+++ /trunk/user/src/com/google/gwt/activity/shared/ActivityManager.java Wed
Dec 8 13:58:54 2010
@@ -54,7 +54,7 @@
}
}
- private static final Activity NULL_ACTIVITY = new AbstractActivity() {
+ private static final Activity NULL_ACTIVITY = new SimpleActivity() {
public void start(AcceptsOneWidget panel, EventBus eventBus) {
}
};
=======================================
---
/trunk/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
Wed Oct 13 09:41:33 2010
+++
/trunk/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
Wed Dec 8 13:58:54 2010
@@ -81,7 +81,7 @@
return null;
}
}
- private static class SyncActivity implements Activity {
+ private static class SyncActivity extends Activity {
boolean canceled = false;
boolean stopped = false;
AcceptsOneWidget display;
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors