Makes EventBus available outside of the gwt package, in
com.google.web.bindery.event.shared. Retrofits the old
classes as deprecated wrappers around the new ones.
The new package is not quite an identical API: we use the
excuse to remove the EventHandler and HasEventHandlers
interfaces, which serve no discernable purpose. And the new
base event class is named Event, not GwtEvent
Note that the classes used directly by GWT widgets and dom
events (GwtEvent and HandlerManager in particular) are not
deprecated.
Review at http://gwt-code-reviews.appspot.com/1394803
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10014 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/DynaTableRf.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/DynaTableRf.java
index 3b17927..d0e1bc9 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/DynaTableRf.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/DynaTableRf.java
@@ -18,8 +18,6 @@
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.sample.dynatablerf.client.widgets.DayFilterWidget;
import com.google.gwt.sample.dynatablerf.client.widgets.FavoritesWidget;
import com.google.gwt.sample.dynatablerf.client.widgets.SummaryWidget;
@@ -28,6 +26,8 @@
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.SimpleEventBus;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryLogHandler;
import com.google.web.bindery.requestfactory.shared.LoggingRequest;
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/FavoritesManager.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/FavoritesManager.java
index de4417e..ae5879f 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/FavoritesManager.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/FavoritesManager.java
@@ -15,15 +15,15 @@
*/
package com.google.gwt.sample.dynatablerf.client;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.sample.dynatablerf.client.events.MarkFavoriteEvent;
import com.google.gwt.sample.dynatablerf.shared.PersonProxy;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.ClosingEvent;
import com.google.gwt.user.client.Window.ClosingHandler;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
+import com.google.web.bindery.event.shared.SimpleEventBus;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java
index 6b9073e..3cc27ed 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/PersonEditorWorkflow.java
@@ -21,7 +21,6 @@
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
-import com.google.gwt.event.shared.EventBus;
import com.google.gwt.sample.dynatablerf.client.events.EditPersonEvent;
import com.google.gwt.sample.dynatablerf.client.widgets.MentorSelector;
import com.google.gwt.sample.dynatablerf.client.widgets.PersonEditor;
@@ -36,6 +35,7 @@
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTMLPanel;
+import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver;
import com.google.web.bindery.requestfactory.shared.Receiver;
import com.google.web.bindery.requestfactory.shared.Request;
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/EditPersonEvent.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/EditPersonEvent.java
index cf11e14..72e4eba 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/EditPersonEvent.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/EditPersonEvent.java
@@ -15,9 +15,8 @@
*/
package com.google.gwt.sample.dynatablerf.client.events;
-import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.sample.dynatablerf.shared.PersonProxy;
+import com.google.web.bindery.event.shared.Event;
import com.google.web.bindery.requestfactory.shared.RequestContext;
/**
@@ -25,13 +24,13 @@
*
* TODO: Make this an Activity.
*/
-public class EditPersonEvent extends GwtEvent<EditPersonEvent.Handler> {
- public static final Type<Handler> TYPE = new Type<Handler>();
+public class EditPersonEvent extends Event<EditPersonEvent.Handler> {
+ public static final Event.Type<Handler> TYPE = new Event.Type<Handler>();
/**
* Handles {@link EditPersonEvent}.
*/
- public interface Handler extends EventHandler {
+ public interface Handler {
void startEdit(PersonProxy person, RequestContext requestContext);
}
@@ -53,7 +52,7 @@
}
@Override
- public com.google.gwt.event.shared.GwtEvent.Type<Handler> getAssociatedType() {
+ public Event.Type<Handler> getAssociatedType() {
return TYPE;
}
}
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/FilterChangeEvent.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/FilterChangeEvent.java
index 5cb4864..d4ed5e1 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/FilterChangeEvent.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/FilterChangeEvent.java
@@ -15,23 +15,22 @@
*/
package com.google.gwt.sample.dynatablerf.client.events;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.event.shared.GwtEvent;
-import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.web.bindery.event.shared.Event;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
/**
* An event to indicate a change in the filter options.
*/
-public class FilterChangeEvent extends GwtEvent<FilterChangeEvent.Handler> {
+public class FilterChangeEvent extends Event<FilterChangeEvent.Handler> {
/**
* Handles {@link FilterChangeEvent}.
*/
- public interface Handler extends EventHandler {
+ public interface Handler {
void onFilterChanged(FilterChangeEvent e);
}
- public static final Type<Handler> TYPE = new Type<Handler>();
+ public static final Event.Type<Handler> TYPE = new Event.Type<Handler>();
public static HandlerRegistration register(EventBus eventBus, Handler handler) {
return eventBus.addHandler(TYPE, handler);
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/MarkFavoriteEvent.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/MarkFavoriteEvent.java
index c0e442d..70e643c 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/MarkFavoriteEvent.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/events/MarkFavoriteEvent.java
@@ -15,23 +15,22 @@
*/
package com.google.gwt.sample.dynatablerf.client.events;
-import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.sample.dynatablerf.shared.PersonProxy;
+import com.google.web.bindery.event.shared.Event;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
/**
* Used client-side to add entries to the favorites list.
*/
-public class MarkFavoriteEvent extends GwtEvent<MarkFavoriteEvent.Handler> {
+public class MarkFavoriteEvent extends Event<MarkFavoriteEvent.Handler> {
/**
* Handles {@link MarkFavoriteEvent}.
*/
- public interface Handler extends EventHandler {
+ public interface Handler {
void onMarkFavorite(MarkFavoriteEvent event);
}
- public static final Type<Handler> TYPE = new Type<Handler>();
+ public static final Event.Type<Handler> TYPE = new Event.Type<Handler>();
private final EntityProxyId<PersonProxy> id;
private final boolean isFavorite;
@@ -42,7 +41,7 @@
}
@Override
- public Type<Handler> getAssociatedType() {
+ public Event.Type<Handler> getAssociatedType() {
return TYPE;
}
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/DayCheckBox.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/DayCheckBox.java
index 79a1fc4..590215b 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/DayCheckBox.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/DayCheckBox.java
@@ -17,11 +17,11 @@
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.sample.dynatablerf.client.events.FilterChangeEvent;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
/**
* Used by DayFilterWidget.
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/DayFilterWidget.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/DayFilterWidget.java
index de62579..f0f5942 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/DayFilterWidget.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/DayFilterWidget.java
@@ -17,7 +17,6 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.shared.EventBus;
import com.google.gwt.sample.dynatablerf.client.events.FilterChangeEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiConstructor;
@@ -27,6 +26,7 @@
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
+import com.google.web.bindery.event.shared.EventBus;
/**
* A UI Widget that allows a user to filter the days being displayed in the
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/FavoritesWidget.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/FavoritesWidget.java
index f442235..c7df7b1 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/FavoritesWidget.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/FavoritesWidget.java
@@ -18,8 +18,6 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.adapters.EditorSource;
import com.google.gwt.editor.client.adapters.ListEditor;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.sample.dynatablerf.client.FavoritesManager;
import com.google.gwt.sample.dynatablerf.client.events.MarkFavoriteEvent;
@@ -29,6 +27,8 @@
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.Receiver;
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/NameLabel.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/NameLabel.java
index b169461..852f3ca 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/NameLabel.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/NameLabel.java
@@ -19,12 +19,12 @@
import com.google.gwt.editor.client.ValueAwareEditor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.sample.dynatablerf.client.events.EditPersonEvent;
import com.google.gwt.sample.dynatablerf.shared.PersonProxy;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
/**
* This NameLabel uses the EditorDelegate to receive notifications on updates to
diff --git a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.java b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.java
index 889594c..e2524fc 100644
--- a/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.java
+++ b/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/client/widgets/SummaryWidget.java
@@ -22,7 +22,6 @@
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.shared.EventBus;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.sample.dynatablerf.client.events.EditPersonEvent;
import com.google.gwt.sample.dynatablerf.client.events.FilterChangeEvent;
@@ -46,6 +45,7 @@
import com.google.gwt.view.client.RangeChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
+import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.shared.EntityProxyChange;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.Receiver;
@@ -255,7 +255,7 @@
}
private int offsetOf(EntityProxyId<PersonProxy> personId) {
- List<PersonProxy> displayedItems = table.getDisplayedItems();
+ List<PersonProxy> displayedItems = table.getVisibleItems();
for (int offset = 0, j = displayedItems.size(); offset < j; offset++) {
if (personId.equals(displayedItems.get(offset).stableId())) {
return offset;
diff --git a/tools/api-checker/config/gwt22_23userApi.conf b/tools/api-checker/config/gwt22_23userApi.conf
index 2501873..d97d277 100644
--- a/tools/api-checker/config/gwt22_23userApi.conf
+++ b/tools/api-checker/config/gwt22_23userApi.conf
@@ -123,6 +123,32 @@
# Overloaded SimplePanel constructor to accept a Widget.
com.google.gwt.user.client.ui.SimplePanel::SimplePanel(Lcom/google/gwt/dom/client/Element;) OVERLOADED_METHOD_CALL
+# Overloads for legacy compatibility after introduction of com.google.web.bindery
+#
+
+com.google.gwt.event.shared.EventBus::addHandler(Lcom/google/gwt/event/shared/GwtEvent$Type;Lcom/google/gwt/event/shared/EventHandler;) OVERLOADED_METHOD_CALL
+com.google.gwt.event.shared.EventBus::addHandlerToSource(Lcom/google/gwt/event/shared/GwtEvent$Type;Ljava/lang/Object;Lcom/google/gwt/event/shared/EventHandler;) OVERLOADED_METHOD_CALL
+
+com.google.gwt.event.shared.ResettableEventBus::addHandler(Lcom/google/gwt/event/shared/GwtEvent$Type;Lcom/google/gwt/event/shared/EventHandler;) OVERLOADED_METHOD_CALL
+com.google.gwt.event.shared.ResettableEventBus::addHandlerToSource(Lcom/google/gwt/event/shared/GwtEvent$Type;Ljava/lang/Object;Lcom/google/gwt/event/shared/EventHandler;) OVERLOADED_METHOD_CALL
+
+com.google.gwt.event.shared.SimpleEventBus::addHandler(Lcom/google/gwt/event/shared/GwtEvent$Type;Lcom/google/gwt/event/shared/EventHandler;) OVERLOADED_METHOD_CALL
+com.google.gwt.event.shared.SimpleEventBus::addHandlerToSource(Lcom/google/gwt/event/shared/GwtEvent$Type;Ljava/lang/Object;Lcom/google/gwt/event/shared/EventHandler;) OVERLOADED_METHOD_CALL
+
+com.google.gwt.event.shared.testing.CountingEventBus::addHandler(Lcom/google/gwt/event/shared/GwtEvent$Type;Lcom/google/gwt/event/shared/EventHandler;) OVERLOADED_METHOD_CALL
+com.google.gwt.event.shared.testing.CountingEventBus::addHandlerToSource(Lcom/google/gwt/event/shared/GwtEvent$Type;Ljava/lang/Object;Lcom/google/gwt/event/shared/EventHandler;) OVERLOADED_METHOD_CALL
+
+com.google.gwt.place.shared.PlaceController.DefaultDelegate::addWindowClosingHandler(Lcom/google/gwt/user/client/Window$ClosingHandler;) OVERRIDABLE_METHOD_RETURN_TYPE_CHANGE
+
+com.google.gwt.place.shared.PlaceHistoryHandler.DefaultHistorian::addValueChangeHandler(Lcom/google/gwt/event/logical/shared/ValueChangeHandler;) OVERRIDABLE_METHOD_RETURN_TYPE_CHANGE
+
+com.google.gwt.place.shared.PlaceHistoryHandler::register(Lcom/google/gwt/place/shared/PlaceController;Lcom/google/gwt/event/shared/EventBus;Lcom/google/gwt/place/shared/Place;) OVERRIDABLE_METHOD_ARGUMENT_TYPE_CHANGE
+
+com.google.gwt.place.shared.PlaceHistoryHandler::register(Lcom/google/gwt/place/shared/PlaceController;Lcom/google/gwt/event/shared/EventBus;Lcom/google/gwt/place/shared/Place;) OVERRIDABLE_METHOD_RETURN_TYPE_CHANGE
+
+#
+# end com.google.web.bindery changes
+
# Renamed CellBasedWidgetImplSafari to CellBasedWidgetImplStandardBase.
com.google.gwt.user.cellview.client.CellBasedWidgetImplSafari MISSING
diff --git a/user/src/com/google/gwt/activity/shared/Activity.java b/user/src/com/google/gwt/activity/shared/Activity.java
index f141171..9635841 100644
--- a/user/src/com/google/gwt/activity/shared/Activity.java
+++ b/user/src/com/google/gwt/activity/shared/Activity.java
@@ -15,8 +15,8 @@
*/
package com.google.gwt.activity.shared;
-import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
+import com.google.web.bindery.event.shared.EventBus;
/**
* Implemented by objects that control a piece of user interface, with a life
@@ -49,7 +49,7 @@
* 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
diff --git a/user/src/com/google/gwt/activity/shared/ActivityManager.java b/user/src/com/google/gwt/activity/shared/ActivityManager.java
index 45f41b5..db2d4cc 100644
--- a/user/src/com/google/gwt/activity/shared/ActivityManager.java
+++ b/user/src/com/google/gwt/activity/shared/ActivityManager.java
@@ -15,14 +15,14 @@
*/
package com.google.gwt.activity.shared;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.event.shared.ResettableEventBus;
-import com.google.gwt.event.shared.UmbrellaException;
import com.google.gwt.place.shared.PlaceChangeEvent;
import com.google.gwt.place.shared.PlaceChangeRequestEvent;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
+import com.google.web.bindery.event.shared.ResettableEventBus;
+import com.google.web.bindery.event.shared.UmbrellaException;
import java.util.LinkedHashSet;
import java.util.Set;
diff --git a/user/src/com/google/gwt/editor/client/EditorDelegate.java b/user/src/com/google/gwt/editor/client/EditorDelegate.java
index 8009ebb..1fc6603 100644
--- a/user/src/com/google/gwt/editor/client/EditorDelegate.java
+++ b/user/src/com/google/gwt/editor/client/EditorDelegate.java
@@ -15,7 +15,7 @@
*/
package com.google.gwt.editor.client;
-import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.web.bindery.event.shared.HandlerRegistration;
/**
* Binds an individual Editor to the backing service. Every Editor has a peer
diff --git a/user/src/com/google/gwt/editor/client/impl/AbstractEditorDelegate.java b/user/src/com/google/gwt/editor/client/impl/AbstractEditorDelegate.java
index ed1e52b..5875e0e 100644
--- a/user/src/com/google/gwt/editor/client/impl/AbstractEditorDelegate.java
+++ b/user/src/com/google/gwt/editor/client/impl/AbstractEditorDelegate.java
@@ -20,7 +20,7 @@
import com.google.gwt.editor.client.EditorDelegate;
import com.google.gwt.editor.client.EditorError;
import com.google.gwt.editor.client.EditorVisitor;
-import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.web.bindery.event.shared.HandlerRegistration;
import java.util.ArrayList;
import java.util.LinkedHashMap;
diff --git a/user/src/com/google/gwt/event/Event.gwt.xml b/user/src/com/google/gwt/event/Event.gwt.xml
index 3dafaf8..14f6dab 100644
--- a/user/src/com/google/gwt/event/Event.gwt.xml
+++ b/user/src/com/google/gwt/event/Event.gwt.xml
@@ -1,5 +1,20 @@
+<!--
+ Copyright 2008 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.
+-->
<module>
- <inherits name="com.google.gwt.event.EventBase" />
- <inherits name="com.google.gwt.event.dom.DomEvent" />
- <inherits name="com.google.gwt.event.logical.LogicalEvent" />
+ <inherits name="com.google.gwt.event.EventBase" />
+ <inherits name="com.google.gwt.event.dom.DomEvent" />
+ <inherits name="com.google.gwt.event.logical.LogicalEvent" />
</module>
diff --git a/user/src/com/google/gwt/event/EventBase.gwt.xml b/user/src/com/google/gwt/event/EventBase.gwt.xml
index 9f0de72..895f0ee 100644
--- a/user/src/com/google/gwt/event/EventBase.gwt.xml
+++ b/user/src/com/google/gwt/event/EventBase.gwt.xml
@@ -1,5 +1,21 @@
+<!--
+ Copyright 2008 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.
+-->
<module>
- <inherits name="com.google.gwt.core.Core" />
+ <inherits name="com.google.web.bindery.event.Event" />
+ <inherits name="com.google.gwt.core.Core" />
- <source path="shared" />
+ <source path="shared" />
</module>
diff --git a/user/src/com/google/gwt/event/shared/EventBus.java b/user/src/com/google/gwt/event/shared/EventBus.java
index 74460c3..84879d3 100644
--- a/user/src/com/google/gwt/event/shared/EventBus.java
+++ b/user/src/com/google/gwt/event/shared/EventBus.java
@@ -15,81 +15,43 @@
*/
package com.google.gwt.event.shared;
-import com.google.gwt.event.shared.GwtEvent.Type;
+import com.google.web.bindery.event.shared.Event;
/**
- * Dispatches {@link GwtEvent}s to interested parties. Eases decoupling by
- * allowing objects to interact without having direct dependencies upon one
- * another, and without requiring event sources to deal with maintaining handler
- * lists. There will typically be one EventBus per application, broadcasting
- * events that may be of general interest.
+ * Extends {com.google.web.bindery.event.shared.EventBus} for legacy
+ * compatibility.
*
- * @see SimpleEventBus
- * @see ResettableEventBus
- * @see com.google.gwt.event.shared.testing.CountingEventBus
+ * @deprecated Replaced by com.google.web.bindery.event.shared.EventBus
*/
-public abstract class EventBus implements HasHandlers {
+@Deprecated
+public abstract class EventBus extends com.google.web.bindery.event.shared.EventBus implements HasHandlers {
+
+ public <H extends EventHandler> HandlerRegistration addHandler(GwtEvent.Type<H> type, H handler) {
+ return wrap(addHandler((Event.Type<H>) type, handler));
+ }
- /**
- * Adds an unfiltered handler to receive events of this type from all sources.
- * <p>
- * It is rare to call this method directly. More typically a {@link GwtEvent}
- * subclass will provide a static <code>register</code> method, or a widget
- * will accept handlers directly.
- * <p>
- * A tip: to make a handler de-register itself, the following works:
- * <code><pre>new MyHandler() {
- * HandlerRegistration reg = MyEvent.register(eventBus, this);
- *
- * public void onMyThing(MyEvent event) {
- * {@literal /}* do your thing *{@literal /}
- * reg.removeHandler();
- * }
- * };
- * </pre></code>
- *
- * @param <H> The type of handler
- * @param type the event type associated with this handler
- * @param handler the handler
- * @return the handler registration, can be stored in order to remove the
- * handler later
- */
- public abstract <H extends EventHandler> HandlerRegistration addHandler(
- Type<H> type, H handler);
+ public <H extends EventHandler> HandlerRegistration addHandlerToSource(GwtEvent.Type<H> type,
+ Object source, H handler) {
+ return wrap(addHandlerToSource((Event.Type<H>) type, source, handler));
+ }
+
+ public void fireEvent(GwtEvent<?> event) {
+ try {
+ fireEvent((Event<?>) event);
+ } catch (com.google.web.bindery.event.shared.UmbrellaException e) {
+ throw new UmbrellaException(e.getCauses());
+ }
+ }
- /**
- * Adds a handler to receive events of this type from the given source.
- * <p>
- * It is rare to call this method directly. More typically a {@link GwtEvent}
- * subclass will provide a static <code>register</code> method, or a widget
- * will accept handlers directly.
- *
- * @param <H> The type of handler
- * @param type the event type associated with this handler
- * @param source the source associated with this handler
- * @param handler the handler
- * @return the handler registration, can be stored in order to remove the
- * handler later
- */
- public abstract <H extends EventHandler> HandlerRegistration addHandlerToSource(
- Type<H> type, Object source, H handler);
+ public void fireEventFromSource(GwtEvent<?> event, Object source) {
+ try {
+ fireEventFromSource((Event<?>) event, source);
+ } catch (com.google.web.bindery.event.shared.UmbrellaException e) {
+ throw new UmbrellaException(e.getCauses());
+ }
+ }
- /**
- * Fires the event from no source. Only unfiltered handlers will receive it.
- *
- * @param event the event to fire
- */
- public abstract void fireEvent(GwtEvent<?> event);
-
- /**
- * Fires the given event to the handlers listening to the event's type.
- * <p>
- * Any exceptions thrown by handlers will be bundled into a
- * {@link UmbrellaException} and then re-thrown after all handlers have
- * completed. An exception thrown by a handler will not prevent other handlers
- * from executing.
- *
- * @param event the event to fire
- */
- public abstract void fireEventFromSource(GwtEvent<?> event, Object source);
+ protected HandlerRegistration wrap(com.google.web.bindery.event.shared.HandlerRegistration reg) {
+ return new LegacyHandlerWrapper(reg);
+ }
}
diff --git a/user/src/com/google/gwt/event/shared/EventHandler.java b/user/src/com/google/gwt/event/shared/EventHandler.java
index 2558629..7860744 100644
--- a/user/src/com/google/gwt/event/shared/EventHandler.java
+++ b/user/src/com/google/gwt/event/shared/EventHandler.java
@@ -16,8 +16,8 @@
package com.google.gwt.event.shared;
/**
- * Marker interface for event handlers. All GWT event handlers should extend
- * {@link EventHandler}.
+ * Marker interface for event handlers. All stock GWT Widget and dom event
+ * handlers extend {@link EventHandler}.
*/
public interface EventHandler {
diff --git a/user/src/com/google/gwt/event/shared/GwtEvent.java b/user/src/com/google/gwt/event/shared/GwtEvent.java
index ef74c39..a4a8465 100644
--- a/user/src/com/google/gwt/event/shared/GwtEvent.java
+++ b/user/src/com/google/gwt/event/shared/GwtEvent.java
@@ -15,16 +15,20 @@
*/
package com.google.gwt.event.shared;
+import com.google.web.bindery.event.shared.Event;
+
/**
- * Root of all GWT events. All GWT events are considered dead and should no
- * longer be accessed once the {@link HandlerManager} which originally fired the
- * event finishes with it. That is, don't hold on to event objects outside of
- * your handler methods.
+ * Root of all GWT widget and dom events sourced by a {@link HandlerManager}.
+ * All GWT events are considered dead and should no longer be accessed once the
+ * {@link HandlerManager} which originally fired the event finishes with it.
+ * That is, don't hold on to event objects outside of your handler methods.
+ * <p>
+ * There is no need for an application's custom event types to extend GwtEvent.
+ * Prefer {@link Event} instead.
*
* @param <H> handler type
- *
*/
-public abstract class GwtEvent<H extends EventHandler> {
+public abstract class GwtEvent<H extends EventHandler> extends Event<H> {
/**
* Type class used to register events with the {@link HandlerManager}.
* <p>
@@ -34,79 +38,24 @@
*
* @param <H> handler type
*/
- public static class Type<H> {
- private static int nextHashCode;
- private final int index;
-
- /**
- * Constructor.
- */
- public Type() {
- index = ++nextHashCode;
- }
-
- // We override hash code to make it as efficient as possible.
- @Override
- public final int hashCode() {
- return index;
- }
-
- @Override
- public String toString() {
- return "Event type";
- }
+ public static class Type<H> extends com.google.web.bindery.event.shared.Event.Type<H> {
}
private boolean dead;
- private Object source;
-
/**
* Constructor.
*/
protected GwtEvent() {
}
- /**
- * Returns the type used to register this event. Used by handler manager to
- * dispatch events to the correct handlers.
- *
- * @return the type
- */
- public abstract Type<H> getAssociatedType();
+ @Override
+ public abstract GwtEvent.Type<H> getAssociatedType();
- /**
- * Returns the source that last fired this event.
- *
- * @return object representing the source of this event
- */
+ @Override
public Object getSource() {
assertLive();
- return source;
- }
-
- /**
- * This is a method used primarily for debugging. It gives a string
- * representation of the event details. This does not override the toString
- * method because the compiler cannot always optimize toString out correctly.
- * Event types should override as desired.
- *
- * @return a string representing the event's specifics.
- */
- public String toDebugString() {
- String name = this.getClass().getName();
- name = name.substring(name.lastIndexOf(".") + 1);
- return "event: " + name + ":";
- }
-
- /**
- * The toString() for abstract event is overridden to avoid accidently
- * including class literals in the the compiled output. Use {@link GwtEvent}
- * #toDebugString to get more information about the event.
- */
- @Override
- public String toString() {
- return "An event type";
+ return super.getSource();
}
/**
@@ -141,7 +90,7 @@
*/
protected void kill() {
dead = true;
- source = null;
+ setSource(null);
}
/**
@@ -149,16 +98,10 @@
*/
protected void revive() {
dead = false;
- source = null;
+ setSource(null);
}
- /**
- * Set the source that triggered this event.
- *
- * @param source the source of this event, should only be set by a
- * {@link HandlerManager}
- */
- void setSource(Object source) {
- this.source = source;
+ void overrideSource(Object source) {
+ super.setSource(source);
}
}
diff --git a/user/src/com/google/gwt/event/shared/HandlerManager.java b/user/src/com/google/gwt/event/shared/HandlerManager.java
index 7b01a51..9f4d350 100644
--- a/user/src/com/google/gwt/event/shared/HandlerManager.java
+++ b/user/src/com/google/gwt/event/shared/HandlerManager.java
@@ -1,12 +1,12 @@
/*
* Copyright 2009 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
@@ -15,7 +15,7 @@
*/
package com.google.gwt.event.shared;
-import com.google.gwt.event.shared.GwtEvent.Type;
+import com.google.web.bindery.event.shared.Event;
/**
* Manager responsible for adding handlers to event sources and firing those
@@ -25,13 +25,40 @@
* While widget authors should continue to use
* {@link com.google.gwt.user.client.ui.Widget#addDomHandler(EventHandler, com.google.gwt.event.dom.client.DomEvent.Type)}
* and
- * {@link com.google.gwt.user.client.ui.Widget#addHandler(EventHandler, com.google.gwt.event.shared.GwtEvent.Type)},
- * application developers are strongly discouraged from using a HandlerManager
+ * {@link com.google.gwt.user.client.ui.Widget#addHandler(EventHandler, com.google.gwt.event.shared.GwtEvent.Type)}
+ * , application developers are strongly discouraged from using a HandlerManager
* instance as a global event dispatch mechanism.
*/
public class HandlerManager implements HasHandlers {
- private final SimpleEventBus eventBus;
+ @SuppressWarnings("deprecation")
+ private static class Bus extends com.google.web.bindery.event.shared.SimpleEventBus {
+ public Bus(boolean fireInReverseOrder) {
+ super(fireInReverseOrder);
+ }
+
+ @Override
+ protected <H> void doRemove(Event.Type<H> type, Object source, H handler) {
+ super.doRemove(type, source, handler);
+ }
+
+ @Override
+ protected <H> H getHandler(Event.Type<H> type, int index) {
+ return super.getHandler(type, index);
+ }
+
+ @Override
+ protected int getHandlerCount(Event.Type<?> eventKey) {
+ return super.getHandlerCount(eventKey);
+ }
+
+ @Override
+ protected boolean isEventHandled(Event.Type<?> eventKey) {
+ return super.isEventHandled(eventKey);
+ }
+ }
+
+ private final Bus eventBus;
// source of the events
private final Object source;
@@ -40,7 +67,7 @@
* Creates a handler manager with a source to be set on all events fired via
* {@link #fireEvent(GwtEvent)}. Handlers will be fired in the order that they
* are added.
- *
+ *
* @param source the default event source
*/
public HandlerManager(Object source) {
@@ -50,28 +77,27 @@
/**
* Creates a handler manager with the given source, specifying the order in
* which handlers are fired.
- *
+ *
* @param source the event source
* @param fireInReverseOrder true to fire handlers in reverse order
*/
- @SuppressWarnings("deprecation")
public HandlerManager(Object source, boolean fireInReverseOrder) {
- eventBus = new SimpleEventBus(fireInReverseOrder);
+ eventBus = new Bus(fireInReverseOrder);
this.source = source;
}
/**
* Adds a handler.
- *
+ *
* @param <H> The type of handler
* @param type the event type associated with this handler
* @param handler the handler
* @return the handler registration, can be stored in order to remove the
* handler later
*/
- public <H extends EventHandler> HandlerRegistration addHandler(
- GwtEvent.Type<H> type, final H handler) {
- return eventBus.addHandler(type, handler);
+ public <H extends EventHandler> HandlerRegistration addHandler(GwtEvent.Type<H> type,
+ final H handler) {
+ return new LegacyHandlerWrapper(eventBus.addHandler(type, handler));
}
/**
@@ -85,7 +111,7 @@
* Note, any subclass should be very careful about overriding this method, as
* adds/removes of handlers will not be safe except within this
* implementation.
- *
+ *
* @param event the event
*/
public void fireEvent(GwtEvent<?> event) {
@@ -94,68 +120,65 @@
event.revive();
}
Object oldSource = event.getSource();
- event.setSource(source);
+ event.overrideSource(source);
try {
// May throw an UmbrellaException.
eventBus.fireEvent(event);
-
+ } catch (com.google.web.bindery.event.shared.UmbrellaException e) {
+ throw new UmbrellaException(e.getCauses());
} finally {
if (oldSource == null) {
// This was my event, so I should kill it now that I'm done.
event.kill();
} else {
// Restoring the source for the next handler to use.
- event.setSource(oldSource);
+ event.overrideSource(oldSource);
}
}
}
/**
* Gets the handler at the given index.
- *
+ *
* @param <H> the event handler type
* @param index the index
* @param type the handler's event type
* @return the given handler
*/
- @SuppressWarnings("deprecation")
public <H extends EventHandler> H getHandler(GwtEvent.Type<H> type, int index) {
return eventBus.getHandler(type, index);
}
/**
* Gets the number of handlers listening to the event type.
- *
+ *
* @param type the event type
* @return the number of registered handlers
*/
- @SuppressWarnings("deprecation")
- public int getHandlerCount(Type<?> type) {
+ public int getHandlerCount(GwtEvent.Type<?> type) {
return eventBus.getHandlerCount(type);
}
/**
* Does this handler manager handle the given event type?
- *
+ *
* @param e the event type
* @return whether the given event type is handled
*/
- @SuppressWarnings("deprecation")
- public boolean isEventHandled(Type<?> e) {
+ public boolean isEventHandled(GwtEvent.Type<?> e) {
return eventBus.isEventHandled(e);
}
/**
* Removes the given handler from the specified event type.
- *
+ *
* @param <H> handler type
- *
+ *
* @param type the event type
* @param handler the handler
*/
- public <H extends EventHandler> void removeHandler(GwtEvent.Type<H> type,
- final H handler) {
- eventBus.doRemove(type, null, handler);
+ public <H extends EventHandler> void removeHandler(GwtEvent.Type<H> type, final H handler) {
+ eventBus.doRemove(type, null, handler);
}
}
diff --git a/user/src/com/google/gwt/event/shared/HandlerRegistration.java b/user/src/com/google/gwt/event/shared/HandlerRegistration.java
index 9031343..5d04ac9 100644
--- a/user/src/com/google/gwt/event/shared/HandlerRegistration.java
+++ b/user/src/com/google/gwt/event/shared/HandlerRegistration.java
@@ -17,19 +17,8 @@
package com.google.gwt.event.shared;
/**
- * Registration returned from a call to
- * {@link HandlerManager#addHandler(com.google.gwt.event.shared.GwtEvent.Type, EventHandler)}
- * . Use the handler registration to remove handlers when they are no longer
- * needed.
- *
- * Note, this interface is under the control of the {@link HandlerManager} class
- * and may be expanded over time, so extend {@link DefaultHandlerRegistration}
- * if you do not wish to get compiler errors if we extend the handler registry
- * functionality.
+ * Extends {com.google.bindery.event.shared.HandlerRegistration} for legacy
+ * compatibility.
*/
-public interface HandlerRegistration {
- /**
- * Removes the given handler from its manager.
- */
- void removeHandler();
+public interface HandlerRegistration extends com.google.web.bindery.event.shared.HandlerRegistration {
}
diff --git a/user/src/com/google/gwt/event/shared/LegacyHandlerWrapper.java b/user/src/com/google/gwt/event/shared/LegacyHandlerWrapper.java
new file mode 100644
index 0000000..b5396da
--- /dev/null
+++ b/user/src/com/google/gwt/event/shared/LegacyHandlerWrapper.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2011 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.event.shared;
+
+class LegacyHandlerWrapper implements HandlerRegistration {
+ private final com.google.web.bindery.event.shared.HandlerRegistration real;
+
+ LegacyHandlerWrapper(com.google.web.bindery.event.shared.HandlerRegistration real) {
+ this.real = real;
+ }
+
+ public void removeHandler() {
+ real.removeHandler();
+ }
+}
diff --git a/user/src/com/google/gwt/event/shared/ResettableEventBus.java b/user/src/com/google/gwt/event/shared/ResettableEventBus.java
index 50055d6..8ea5ace 100644
--- a/user/src/com/google/gwt/event/shared/ResettableEventBus.java
+++ b/user/src/com/google/gwt/event/shared/ResettableEventBus.java
@@ -15,84 +15,67 @@
*/
package com.google.gwt.event.shared;
-import com.google.gwt.event.shared.GwtEvent.Type;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
+import com.google.web.bindery.event.shared.Event;
+import com.google.web.bindery.event.shared.Event.Type;
+import com.google.web.bindery.event.shared.HandlerRegistration;
/**
- * Wraps an EventBus to hold on to any HandlerRegistrations, so that they can
- * easily all be cleared at once.
+ * Wraps {com.google.web.bindery.event.shared.ResettableEventBus} for legacy
+ * compatibility.
+ *
+ * @deprecated Use com.google.web.bindery.event.shared.ResettableEventBus.
*/
+@SuppressWarnings("deprecation")
+@Deprecated
public class ResettableEventBus extends EventBus {
+ private static class TestableResettableEventBus extends com.google.web.bindery.event.shared.ResettableEventBus {
+ /**
+ * @param wrappedBus
+ */
+ public TestableResettableEventBus(EventBus wrappedBus) {
+ super(wrappedBus);
+ }
- private final EventBus wrapped;
- private final Set<HandlerRegistration> registrations = new HashSet<HandlerRegistration>();
+ @Override
+ public int getRegistrationSize() {
+ return super.getRegistrationSize();
+ }
+ }
+
+ private final TestableResettableEventBus real;
public ResettableEventBus(EventBus wrappedBus) {
- this.wrapped = wrappedBus;
+ real = new TestableResettableEventBus(wrappedBus);
}
@Override
- public <H extends EventHandler> HandlerRegistration addHandler(Type<H> type, H handler) {
- HandlerRegistration rtn = wrapped.addHandler(type, handler);
- return doRegisterHandler(rtn);
+ public <H> HandlerRegistration addHandler(Type<H> type, H handler) {
+ return real.addHandler(type, handler);
}
@Override
- public <H extends EventHandler> HandlerRegistration addHandlerToSource(GwtEvent.Type<H> type,
- Object source, H handler) {
- HandlerRegistration rtn = wrapped.addHandlerToSource(type, source, handler);
- return doRegisterHandler(rtn);
+ public <H> HandlerRegistration addHandlerToSource(Type<H> type, Object source, H handler) {
+ return real.addHandlerToSource(type, source, handler);
}
@Override
- public void fireEvent(GwtEvent<?> event) {
- wrapped.fireEvent(event);
+ public void fireEvent(Event<?> event) {
+ real.fireEvent(event);
}
@Override
- public void fireEventFromSource(GwtEvent<?> event, Object source) {
- wrapped.fireEventFromSource(event, source);
+ public void fireEventFromSource(Event<?> event, Object source) {
+ real.fireEventFromSource(event, source);
+ }
+
+ public void removeHandlers() {
+ real.removeHandlers();
}
/**
- * Remove all handlers that have been added through this wrapper.
+ * Visible for testing
*/
- public void removeHandlers() {
- Iterator<HandlerRegistration> it = registrations.iterator();
- while (it.hasNext()) {
- HandlerRegistration r = it.next();
-
- /*
- * must remove before we call removeHandler. Might have come from nested
- * ResettableEventBus
- */
- it.remove();
-
- r.removeHandler();
- }
- }
-
- // Visible for testing
int getRegistrationSize() {
- return registrations.size();
- }
-
- private HandlerRegistration doRegisterHandler(final HandlerRegistration registration) {
- registrations.add(registration);
- return new HandlerRegistration() {
- public void removeHandler() {
- doUnregisterHandler(registration);
- }
- };
- }
-
- private void doUnregisterHandler(HandlerRegistration registration) {
- if (registrations.contains(registration)) {
- registration.removeHandler();
- registrations.remove(registration);
- }
+ return real.getRegistrationSize();
}
}
diff --git a/user/src/com/google/gwt/event/shared/SimpleEventBus.java b/user/src/com/google/gwt/event/shared/SimpleEventBus.java
index 673d698..94c8207 100644
--- a/user/src/com/google/gwt/event/shared/SimpleEventBus.java
+++ b/user/src/com/google/gwt/event/shared/SimpleEventBus.java
@@ -15,309 +15,39 @@
*/
package com.google.gwt.event.shared;
-import com.google.gwt.core.client.Scheduler.ScheduledCommand;
-import com.google.gwt.event.shared.GwtEvent.Type;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Set;
+import com.google.web.bindery.event.shared.Event;
+import com.google.web.bindery.event.shared.Event.Type;
+import com.google.web.bindery.event.shared.HandlerRegistration;
/**
- * Basic implementation of {@link EventBus}.
+ * Wraps {com.google.web.bindery.event.shared.SimpleEventBus} for legacy
+ * compatibility.
+ *
+ * @deprecated Use com.google.web.bindery.event.shared.SimpleEventBus
*/
+@SuppressWarnings("deprecation")
+@Deprecated
public class SimpleEventBus extends EventBus {
- private final boolean isReverseOrder;
+ private final com.google.web.bindery.event.shared.SimpleEventBus real =
+ new com.google.web.bindery.event.shared.SimpleEventBus();
- private int firingDepth = 0;
-
- /**
- * Add and remove operations received during dispatch.
- */
- private List<ScheduledCommand> deferredDeltas;
-
- /**
- * Map of event type to map of event source to list of their handlers.
- */
- private final Map<GwtEvent.Type<?>, Map<Object, List<?>>> map = new HashMap<GwtEvent.Type<?>, Map<Object, List<?>>>();
-
- public SimpleEventBus() {
- this(false);
- }
-
- /**
- * Allows creation of an instance that fires its handlers in the reverse of
- * the order in which they were added, although filtered handlers all fire
- * before unfiltered handlers.
- * <p>
- *
- * @deprecated This is a legacy feature, required by HandlerManager. Package
- * protected because it is a bad idea to rely upon the order of
- * event dispatch, and because fully supporting it (that is, not
- * segregating filtered and unfiltered handlers, a distinction not
- * used by HandlerManager) is not worth the effort.
- */
- @Deprecated
- SimpleEventBus(boolean fireInReverseOrder) {
- isReverseOrder = fireInReverseOrder;
+ @Override
+ public <H> HandlerRegistration addHandler(Type<H> type, H handler) {
+ return real.addHandler(type, handler);
}
@Override
- public <H extends EventHandler> HandlerRegistration addHandler(Type<H> type,
- H handler) {
- if (type == null) {
- throw new NullPointerException("Cannot add a handler with a null type");
- }
- if (handler == null) {
- throw new NullPointerException("Cannot add a null handler");
- }
-
- return doAdd(type, null, handler);
+ public <H> HandlerRegistration addHandlerToSource(Type<H> type, Object source, H handler) {
+ return real.addHandlerToSource(type, source, handler);
}
@Override
- public <H extends EventHandler> HandlerRegistration addHandlerToSource(
- final GwtEvent.Type<H> type, final Object source, final H handler) {
- if (type == null) {
- throw new NullPointerException("Cannot add a handler with a null type");
- }
- if (source == null) {
- throw new NullPointerException("Cannot add a handler with a null source");
- }
- if (handler == null) {
- throw new NullPointerException("Cannot add a null handler");
- }
-
- return doAdd(type, source, handler);
+ public void fireEvent(Event<?> event) {
+ real.fireEvent(event);
}
@Override
- public void fireEvent(GwtEvent<?> event) {
- if (event == null) {
- throw new NullPointerException("Cannot fire null event");
- }
- doFire(event, null);
+ public void fireEventFromSource(Event<?> event, Object source) {
+ real.fireEventFromSource(event, source);
}
-
- @Override
- public void fireEventFromSource(GwtEvent<?> event, Object source) {
- if (event == null) {
- throw new NullPointerException("Cannot fire null event");
- }
- if (source == null) {
- throw new NullPointerException("Cannot fire from a null source");
- }
- doFire(event, source);
- }
-
- /**
- * Package protected to support legacy features in HandlerManager.
- */
- <H extends EventHandler> void doRemove(
- com.google.gwt.event.shared.GwtEvent.Type<H> type, Object source,
- H handler) {
- if (firingDepth > 0) {
- enqueueRemove(type, source, handler);
- } else {
- doRemoveNow(type, source, handler);
- }
- }
-
- /**
- * Package protected to support legacy features in HandlerManager.
- */
- @Deprecated
- <H extends EventHandler> H getHandler(GwtEvent.Type<H> type, int index) {
- assert index < getHandlerCount(type) : "handlers for " + type.getClass()
- + " have size: " + getHandlerCount(type)
- + " so do not have a handler at index: " + index;
-
- List<H> l = getHandlerList(type, null);
- return l.get(index);
- }
-
- /**
- * Package protected to support legacy features in HandlerManager.
- */
- @Deprecated
- int getHandlerCount(GwtEvent.Type<?> eventKey) {
- return getHandlerList(eventKey, null).size();
- }
-
- /**
- * Package protected to support legacy features in HandlerManager.
- */
- @Deprecated
- boolean isEventHandled(GwtEvent.Type<?> eventKey) {
- return map.containsKey(eventKey);
- }
-
- private void defer(ScheduledCommand command) {
- if (deferredDeltas == null) {
- deferredDeltas = new ArrayList<ScheduledCommand>();
- }
- deferredDeltas.add(command);
- }
-
- private <H extends EventHandler> HandlerRegistration doAdd(
- final GwtEvent.Type<H> type, final Object source, final H handler) {
- if (firingDepth > 0) {
- enqueueAdd(type, source, handler);
- } else {
- doAddNow(type, source, handler);
- }
-
- return new HandlerRegistration() {
- public void removeHandler() {
- doRemove(type, source, handler);
- }
- };
- }
-
- private <H extends EventHandler> void doAddNow(GwtEvent.Type<H> type,
- Object source, H handler) {
- List<H> l = ensureHandlerList(type, source);
- l.add(handler);
- }
-
- private <H extends EventHandler> void doFire(GwtEvent<H> event, Object source) {
- try {
- firingDepth++;
-
- if (source != null) {
- event.setSource(source);
- }
-
- List<H> handlers = getDispatchList(event.getAssociatedType(), source);
- Set<Throwable> causes = null;
-
- ListIterator<H> it = isReverseOrder
- ? handlers.listIterator(handlers.size()) : handlers.listIterator();
- while (isReverseOrder ? it.hasPrevious() : it.hasNext()) {
- H handler = isReverseOrder ? it.previous() : it.next();
-
- try {
- event.dispatch(handler);
- } catch (Throwable e) {
- if (causes == null) {
- causes = new HashSet<Throwable>();
- }
- causes.add(e);
- }
- }
-
- if (causes != null) {
- throw new UmbrellaException(causes);
- }
- } finally {
- firingDepth--;
- if (firingDepth == 0) {
- handleQueuedAddsAndRemoves();
- }
- }
- }
-
- private <H> void doRemoveNow(GwtEvent.Type<H> type, Object source, H handler) {
- List<H> l = getHandlerList(type, source);
-
- boolean removed = l.remove(handler);
- assert removed : "redundant remove call";
- if (removed && l.isEmpty()) {
- prune(type, source);
- }
- }
-
- private <H extends EventHandler> void enqueueAdd(final GwtEvent.Type<H> type,
- final Object source, final H handler) {
- defer(new ScheduledCommand() {
- public void execute() {
- doAddNow(type, source, handler);
- }
- });
- }
-
- private <H extends EventHandler> void enqueueRemove(
- final GwtEvent.Type<H> type, final Object source, final H handler) {
- defer(new ScheduledCommand() {
- public void execute() {
- doRemoveNow(type, source, handler);
- }
- });
- }
-
- private <H> List<H> ensureHandlerList(GwtEvent.Type<H> type, Object source) {
- Map<Object, List<?>> sourceMap = map.get(type);
- if (sourceMap == null) {
- sourceMap = new HashMap<Object, List<?>>();
- map.put(type, sourceMap);
- }
-
- // safe, we control the puts.
- @SuppressWarnings("unchecked")
- List<H> handlers = (List<H>) sourceMap.get(source);
- if (handlers == null) {
- handlers = new ArrayList<H>();
- sourceMap.put(source, handlers);
- }
-
- return handlers;
- }
-
- private <H> List<H> getDispatchList(GwtEvent.Type<H> type, Object source) {
- List<H> directHandlers = getHandlerList(type, source);
- if (source == null) {
- return directHandlers;
- }
-
- List<H> globalHandlers = getHandlerList(type, null);
-
- List<H> rtn = new ArrayList<H>(directHandlers);
- rtn.addAll(globalHandlers);
- return rtn;
- }
-
- private <H> List<H> getHandlerList(GwtEvent.Type<H> type, Object source) {
- Map<Object, List<?>> sourceMap = map.get(type);
- if (sourceMap == null) {
- return Collections.emptyList();
- }
-
- // safe, we control the puts.
- @SuppressWarnings("unchecked")
- List<H> handlers = (List<H>) sourceMap.get(source);
- if (handlers == null) {
- return Collections.emptyList();
- }
-
- return handlers;
- }
-
- private void handleQueuedAddsAndRemoves() {
- if (deferredDeltas != null) {
- try {
- for (ScheduledCommand c : deferredDeltas) {
- c.execute();
- }
- } finally {
- deferredDeltas = null;
- }
- }
- }
-
- private void prune(GwtEvent.Type<?> type, Object source) {
- Map<Object, List<?>> sourceMap = map.get(type);
-
- List<?> pruned = sourceMap.remove(source);
-
- assert pruned != null : "Can't prune what wasn't there";
- assert pruned.isEmpty() : "Pruned unempty list!";
-
- if (sourceMap.isEmpty()) {
- map.remove(type);
- }
- }
-}
\ No newline at end of file
+}
diff --git a/user/src/com/google/gwt/event/shared/UmbrellaException.java b/user/src/com/google/gwt/event/shared/UmbrellaException.java
index 134af51..dd34695 100644
--- a/user/src/com/google/gwt/event/shared/UmbrellaException.java
+++ b/user/src/com/google/gwt/event/shared/UmbrellaException.java
@@ -15,43 +15,21 @@
*/
package com.google.gwt.event.shared;
-import java.util.HashSet;
import java.util.Set;
/**
- * A {@link RuntimeException} that collects a {@link Set} of child
- * {@link Throwable}s together. Typically thrown after loop, with all of the
- * exceptions thrown during that loop, but delayed so that the loop finishes
- * executing.
+ * Wraps {com.google.web.bindery.event.shared.UmbrellaException} for legacy
+ * compatibility.
*/
-public class UmbrellaException extends RuntimeException {
-
- /**
- * The causes of the exception.
- */
- private Set<Throwable> causes;
-
- /*
- * The default constructor enables RPC support.
- */
- public UmbrellaException() {
- this(new HashSet<Throwable>());
- }
-
+public class UmbrellaException extends com.google.web.bindery.event.shared.UmbrellaException {
public UmbrellaException(Set<Throwable> causes) {
- super(
- "One or more exceptions caught, see full set in UmbrellaException#getCauses",
- causes.size() == 0 ? null : causes.toArray(new Throwable[0])[0]);
- this.causes = causes;
+ super(causes);
}
/**
- * Get the set of exceptions that caused the failure.
- *
- * @return the set of causes
+ * Required for GWT RPC serialization.
*/
- public Set<Throwable> getCauses() {
- return causes;
+ protected UmbrellaException() {
+ super();
}
-
-}
\ No newline at end of file
+}
diff --git a/user/src/com/google/gwt/event/shared/testing/CountingEventBus.java b/user/src/com/google/gwt/event/shared/testing/CountingEventBus.java
index 3c1a121..7503966 100644
--- a/user/src/com/google/gwt/event/shared/testing/CountingEventBus.java
+++ b/user/src/com/google/gwt/event/shared/testing/CountingEventBus.java
@@ -15,87 +15,50 @@
*/
package com.google.gwt.event.shared.testing;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
-import com.google.gwt.event.shared.GwtEvent.Type;
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.event.shared.SimpleEventBus;
-
-import java.util.HashMap;
-import java.util.Map;
+import com.google.web.bindery.event.shared.Event;
+import com.google.web.bindery.event.shared.Event.Type;
+import com.google.web.bindery.event.shared.HandlerRegistration;
/**
- * Wraps an {@link EventBus} to keep a count of registered handlers. Handy for
- * tests.
+ * Legacy compatibility wrapper for
+ * {@link com.google.web.bindery.event.shared.testing.CountingEventBus}.
+ * @deprecated
*/
-public class CountingEventBus extends EventBus {
- private final Map<Type<?>, Integer> counts = new HashMap<GwtEvent.Type<?>, Integer>();
- private final EventBus wrapped;
-
+@SuppressWarnings("deprecation")
+@Deprecated
+public class CountingEventBus extends com.google.gwt.event.shared.EventBus {
+ private final com.google.web.bindery.event.shared.testing.CountingEventBus real;
+
public CountingEventBus() {
- this(new SimpleEventBus());
+ real = new com.google.web.bindery.event.shared.testing.CountingEventBus();
}
-
- public CountingEventBus(EventBus wrapped) {
- this.wrapped = wrapped;
+
+ public CountingEventBus(com.google.gwt.event.shared.EventBus wrapped) {
+ real = new com.google.web.bindery.event.shared.testing.CountingEventBus(wrapped);
}
@Override
- public <H extends EventHandler> HandlerRegistration addHandler(Type<H> type,
- H handler) {
- increment(type);
- final HandlerRegistration superReg = wrapped.addHandler(type, handler);
- return makeReg(type, superReg);
+ public <H> HandlerRegistration addHandler(Type<H> type, H handler) {
+ return real.addHandler(type, handler);
}
@Override
- public <H extends EventHandler> HandlerRegistration addHandlerToSource(
- final Type<H> type, Object source, H handler) {
- increment(type);
- final HandlerRegistration superReg = wrapped.addHandlerToSource(type,
- source, handler);
- return makeReg(type, superReg);
+ public <H> HandlerRegistration addHandlerToSource(Type<H> type, Object source, H handler) {
+ return real.addHandlerToSource(type, source, handler);
}
@Override
- public void fireEvent(GwtEvent<?> event) {
- wrapped.fireEvent(event);
+ public void fireEvent(Event<?> event) {
+ real.fireEvent(event);
}
@Override
- public void fireEventFromSource(GwtEvent<?> event, Object source) {
- wrapped.fireEventFromSource(event, source);
+ public void fireEventFromSource(Event<?> event, Object source) {
+ real.fireEventFromSource(event, source);
}
- public int getCount(Type<?> type) {
- Integer count = counts.get(type);
- return count == null ? 0 : count;
- }
-
- private void decrement(Type<?> type) {
- Integer count = counts.get(type);
- if (count == null) {
- count = 0;
- }
- counts.put(type, count - 1);
- }
-
- private <H> void increment(final Type<H> type) {
- Integer count = counts.get(type);
- if (count == null) {
- count = 0;
- }
- counts.put(type, count + 1);
- }
-
- private <H> HandlerRegistration makeReg(final Type<H> type,
- final HandlerRegistration superReg) {
- return new HandlerRegistration() {
- public void removeHandler() {
- decrement(type);
- superReg.removeHandler();
- }
- };
+ public int getCount(GwtEvent.Type<?> type) {
+ return real.getCount(type);
}
}
diff --git a/user/src/com/google/gwt/place/shared/PlaceController.java b/user/src/com/google/gwt/place/shared/PlaceController.java
index 294a963..56efe51 100644
--- a/user/src/com/google/gwt/place/shared/PlaceController.java
+++ b/user/src/com/google/gwt/place/shared/PlaceController.java
@@ -16,11 +16,11 @@
package com.google.gwt.place.shared;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.Window.ClosingEvent;
import com.google.gwt.user.client.Window.ClosingHandler;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
import java.util.logging.Logger;
diff --git a/user/src/com/google/gwt/place/shared/PlaceHistoryHandler.java b/user/src/com/google/gwt/place/shared/PlaceHistoryHandler.java
index 7117169..fc6bb98 100644
--- a/user/src/com/google/gwt/place/shared/PlaceHistoryHandler.java
+++ b/user/src/com/google/gwt/place/shared/PlaceHistoryHandler.java
@@ -18,9 +18,9 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.History;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
import java.util.logging.Logger;
diff --git a/user/src/com/google/gwt/user/client/ui/Widget.java b/user/src/com/google/gwt/user/client/ui/Widget.java
index 7bc1ba3..932aaee 100644
--- a/user/src/com/google/gwt/user/client/ui/Widget.java
+++ b/user/src/com/google/gwt/user/client/ui/Widget.java
@@ -23,7 +23,6 @@
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerManager;
-import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
@@ -246,8 +245,8 @@
*
* @return the {@link HandlerManager} you want to use
*/
- protected com.google.gwt.event.shared.HandlerManager createHandlerManager() {
- return new com.google.gwt.event.shared.HandlerManager(this);
+ protected HandlerManager createHandlerManager() {
+ return new HandlerManager(this);
}
/**
@@ -289,7 +288,7 @@
* @param type the event type
* @return the number of registered handlers
*/
- protected int getHandlerCount(Type<?> type) {
+ protected int getHandlerCount(GwtEvent.Type<?> type) {
return handlerManager == null ? 0 : handlerManager.getHandlerCount(type);
}
@@ -412,12 +411,12 @@
*
* @return the handler manager
* */
- com.google.gwt.event.shared.HandlerManager ensureHandlers() {
+ HandlerManager ensureHandlers() {
return handlerManager == null ? handlerManager = createHandlerManager()
: handlerManager;
}
- com.google.gwt.event.shared.HandlerManager getHandlerManager() {
+ HandlerManager getHandlerManager() {
return handlerManager;
}
diff --git a/user/src/com/google/web/bindery/event/Event.gwt.xml b/user/src/com/google/web/bindery/event/Event.gwt.xml
new file mode 100644
index 0000000..8bafd18
--- /dev/null
+++ b/user/src/com/google/web/bindery/event/Event.gwt.xml
@@ -0,0 +1,18 @@
+<!--
+ Copyright 2011 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.
+-->
+<module>
+ <source path="shared" />
+</module>
diff --git a/user/src/com/google/web/bindery/event/shared/Event.java b/user/src/com/google/web/bindery/event/shared/Event.java
new file mode 100644
index 0000000..487771f
--- /dev/null
+++ b/user/src/com/google/web/bindery/event/shared/Event.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+/**
+ * Base Event object.
+ *
+ * @param <H> interface implemented by handlers of this kind of event
+ */
+public abstract class Event<H> {
+ /**
+ * Type class used to register events with an {@link EventBus}.
+ *
+ * @param <H> handler type
+ */
+ public static class Type<H> {
+ private static int nextHashCode;
+ private final int index;
+
+ /**
+ * Constructor.
+ */
+ public Type() {
+ index = ++nextHashCode;
+ }
+
+ @Override
+ public final int hashCode() {
+ return index;
+ }
+
+ @Override
+ public String toString() {
+ return "Event type";
+ }
+ }
+
+ private Object source;
+
+ /**
+ * Constructor.
+ */
+ protected Event() {
+ }
+
+ /**
+ * Returns the {@link Type} used to register this event, allowing an
+ * {@link EventBus} to find handlers of the appropriate class.
+ *
+ * @return the type
+ */
+ public abstract Type<H> getAssociatedType();
+
+ /**
+ * Returns the source for this event. The type and meaning of the source is
+ * arbitrary, and is most useful as a secondary key for handler registration.
+ * (See {@link EventBus#addHandlerToSource}, which allows a handler to
+ * register for events of a particular type, tied to a particular source.)
+ * <p>
+ * Note that the source is actually set at dispatch time, e.g. via
+ * {@link EventBus#fireEventFromSource(Event, Object)}.
+ *
+ * @return object representing the source of this event
+ */
+ public Object getSource() {
+ return source;
+ }
+
+ /**
+ * This is a method used primarily for debugging. It gives a string
+ * representation of the event details. This does not override the toString
+ * method because the compiler cannot always optimize toString out correctly.
+ * Event types should override as desired.
+ *
+ * @return a string representing the event's specifics.
+ */
+ public String toDebugString() {
+ String name = this.getClass().getName();
+ name = name.substring(name.lastIndexOf(".") + 1);
+ return "event: " + name + ":";
+ }
+
+ /**
+ * The toString() for abstract event is overridden to avoid accidently
+ * including class literals in the the compiled output. Use {@link Event}
+ * #toDebugString to get more information about the event.
+ */
+ @Override
+ public String toString() {
+ return "An event type";
+ }
+
+ /**
+ * Implemented by subclasses to to invoke their handlers in a type safe
+ * manner. Intended to be called by {@link EventBus#fireEvent(Event)} or
+ * {@link EventBus#fireEventFromSource(Event, Object)}.
+ *
+ * @param handler handler
+ */
+ protected abstract void dispatch(H handler);
+
+ /**
+ * Set the source that triggered this event. Intended to be called by the
+ * {@link EventBus} during dispatch.
+ *
+ * @param source the source of this event.
+ * @see EventBus#fireEventFromSource(Event, Object)
+ */
+ protected void setSource(Object source) {
+ this.source = source;
+ }
+}
diff --git a/user/src/com/google/web/bindery/event/shared/EventBus.java b/user/src/com/google/web/bindery/event/shared/EventBus.java
new file mode 100644
index 0000000..91ed3dc
--- /dev/null
+++ b/user/src/com/google/web/bindery/event/shared/EventBus.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+import com.google.web.bindery.event.shared.Event.Type;
+
+/**
+ * Dispatches {@link Event}s to interested parties. Eases decoupling by allowing
+ * objects to interact without having direct dependencies upon one another, and
+ * without requiring event sources to deal with maintaining handler lists. There
+ * will typically be one EventBus per application, broadcasting events that may
+ * be of general interest.
+ *
+ * @see SimpleEventBus
+ * @see ResettableEventBus
+ * @see com.google.web.bindery.event.shared.testing.CountingEventBus
+ */
+public abstract class EventBus {
+
+ /**
+ * Adds an unfiltered handler to receive events of this type from all sources.
+ * <p>
+ * It is rare to call this method directly. More typically an {@link Event}
+ * subclass will provide a static <code>register</code> method, or a widget
+ * will accept handlers directly.
+ *
+ * @param <H> The type of handler
+ * @param type the event type associated with this handler
+ * @param handler the handler
+ * @return the handler registration, can be stored in order to remove the
+ * handler later
+ */
+ public abstract <H> HandlerRegistration addHandler(Type<H> type, H handler);
+
+ /**
+ * Adds a handler to receive events of this type from the given source.
+ * <p>
+ * It is rare to call this method directly. More typically a {@link Event}
+ * subclass will provide a static <code>register</code> method, or a widget
+ * will accept handlers directly.
+ *
+ * @param <H> The type of handler
+ * @param type the event type associated with this handler
+ * @param source the source associated with this handler
+ * @param handler the handler
+ * @return the handler registration, can be stored in order to remove the
+ * handler later
+ */
+ public abstract <H> HandlerRegistration addHandlerToSource(Type<H> type, Object source, H handler);
+
+ /**
+ * Fires the event from no source. Only unfiltered handlers will receive it.
+ * <p>
+ * Any exceptions thrown by handlers will be bundled into a
+ * {@link UmbrellaException} and then re-thrown after all handlers have
+ * completed. An exception thrown by a handler will not prevent other handlers
+ * from executing.
+ *
+ * @throws UmbrellaException wrapping exceptions thrown by handlers
+ *
+ * @param event the event to fire
+ */
+ public abstract void fireEvent(Event<?> event);
+
+ /**
+ * Fires the given event to the handlers listening to the event's type.
+ * <p>
+ * Any exceptions thrown by handlers will be bundled into a
+ * {@link UmbrellaException} and then re-thrown after all handlers have
+ * completed. An exception thrown by a handler will not prevent other handlers
+ * from executing.
+ *
+ * @throws UmbrellaException wrapping exceptions thrown by handlers
+ *
+ * @param event the event to fire
+ */
+ public abstract void fireEventFromSource(Event<?> event, Object source);
+}
diff --git a/user/src/com/google/web/bindery/event/shared/HandlerRegistration.java b/user/src/com/google/web/bindery/event/shared/HandlerRegistration.java
new file mode 100644
index 0000000..ce34e39
--- /dev/null
+++ b/user/src/com/google/web/bindery/event/shared/HandlerRegistration.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+/**
+ * Registration objects returned when an event handler is bound (e.g. via
+ * {@link EventBus#addHandler}), used to deregister.
+ * <p>
+ * A tip: to make a handler deregister itself try something like the following:
+ * <code><pre>new MyHandler() {
+ * HandlerRegistration reg = MyEvent.register(eventBus, this);
+ *
+ * public void onMyThing(MyEvent event) {
+ * {@literal /}* do your thing *{@literal /}
+ * reg.removeHandler();
+ * }
+ * };
+ * </pre></code>
+ */
+public interface HandlerRegistration {
+
+ /**
+ * Deregisters the handler associated with this registration object if the
+ * handler is still attached to the event source. If the handler is no longer
+ * attached to the event source, this is a no-op.
+ */
+ void removeHandler();
+}
diff --git a/user/src/com/google/web/bindery/event/shared/ResettableEventBus.java b/user/src/com/google/web/bindery/event/shared/ResettableEventBus.java
new file mode 100644
index 0000000..a1b56ce
--- /dev/null
+++ b/user/src/com/google/web/bindery/event/shared/ResettableEventBus.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+import com.google.web.bindery.event.shared.Event.Type;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Wraps an EventBus to hold on to any HandlerRegistrations, so that they can
+ * easily all be cleared at once.
+ */
+public class ResettableEventBus extends EventBus {
+ private final EventBus wrapped;
+ private final Set<HandlerRegistration> registrations = new HashSet<HandlerRegistration>();
+
+ public ResettableEventBus(EventBus wrappedBus) {
+ this.wrapped = wrappedBus;
+ }
+
+ @Override
+ public <H> HandlerRegistration addHandler(Type<H> type, H handler) {
+ HandlerRegistration rtn = wrapped.addHandler(type, handler);
+ return doRegisterHandler(rtn);
+ }
+
+ @Override
+ public <H> HandlerRegistration addHandlerToSource(Event.Type<H> type, Object source, H handler) {
+ HandlerRegistration rtn = wrapped.addHandlerToSource(type, source, handler);
+ return doRegisterHandler(rtn);
+ }
+
+ @Override
+ public void fireEvent(Event<?> event) {
+ wrapped.fireEvent(event);
+ }
+
+ @Override
+ public void fireEventFromSource(Event<?> event, Object source) {
+ wrapped.fireEventFromSource(event, source);
+ }
+
+ /**
+ * Remove all handlers that have been added through this wrapper.
+ */
+ public void removeHandlers() {
+ Iterator<HandlerRegistration> it = registrations.iterator();
+ while (it.hasNext()) {
+ HandlerRegistration r = it.next();
+
+ /*
+ * must remove before we call removeHandler. Might have come from nested
+ * ResettableEventBus
+ */
+ it.remove();
+
+ r.removeHandler();
+ }
+ }
+
+ /**
+ * Visible for testing
+ */
+ protected int getRegistrationSize() {
+ return registrations.size();
+ }
+
+ private HandlerRegistration doRegisterHandler(final HandlerRegistration registration) {
+ registrations.add(registration);
+ return new HandlerRegistration() {
+ public void removeHandler() {
+ doUnregisterHandler(registration);
+ }
+ };
+ }
+
+ private void doUnregisterHandler(HandlerRegistration registration) {
+ if (registrations.contains(registration)) {
+ registration.removeHandler();
+ registrations.remove(registration);
+ }
+ }
+}
diff --git a/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java b/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java
new file mode 100644
index 0000000..14a1f3c
--- /dev/null
+++ b/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java
@@ -0,0 +1,310 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+import com.google.web.bindery.event.shared.Event.Type;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Basic implementation of {@link EventBus}.
+ */
+public class SimpleEventBus extends EventBus {
+ private interface Command {
+ void execute();
+ }
+
+ private final boolean isReverseOrder;
+
+ private int firingDepth = 0;
+
+ /**
+ * Add and remove operations received during dispatch.
+ */
+ private List<Command> deferredDeltas;
+
+ /**
+ * Map of event type to map of event source to list of their handlers.
+ */
+ private final Map<Event.Type<?>, Map<Object, List<?>>> map =
+ new HashMap<Event.Type<?>, Map<Object, List<?>>>();
+
+ public SimpleEventBus() {
+ this(false);
+ }
+
+ /**
+ * Allows creation of an instance that fires its handlers in the reverse of
+ * the order in which they were added, although filtered handlers all fire
+ * before unfiltered handlers.
+ * <p>
+ *
+ * @deprecated This is a legacy feature, required by GWT's old HandlerManager.
+ * Reverse order is not honored for handlers tied to a specific
+ * event source (via {@link #addHandlerToSource}.
+ */
+ @Deprecated
+ protected SimpleEventBus(boolean fireInReverseOrder) {
+ isReverseOrder = fireInReverseOrder;
+ }
+
+ @Override
+ public <H> HandlerRegistration addHandler(Type<H> type, H handler) {
+ return doAdd(type, null, handler);
+ }
+
+ @Override
+ public <H> HandlerRegistration addHandlerToSource(final Event.Type<H> type, final Object source,
+ final H handler) {
+ if (source == null) {
+ throw new NullPointerException("Cannot add a handler with a null source");
+ }
+
+ return doAdd(type, source, handler);
+ }
+
+ @Override
+ public void fireEvent(Event<?> event) {
+ doFire(event, null);
+ }
+
+ @Override
+ public void fireEventFromSource(Event<?> event, Object source) {
+ if (source == null) {
+ throw new NullPointerException("Cannot fire from a null source");
+ }
+ doFire(event, source);
+ }
+
+ /**
+ * @deprecated required by legacy features in GWT's old HandlerManager
+ */
+ @Deprecated
+ protected <H> void doRemove(Event.Type<H> type, Object source, H handler) {
+ if (firingDepth > 0) {
+ enqueueRemove(type, source, handler);
+ } else {
+ doRemoveNow(type, source, handler);
+ }
+ }
+
+ /**
+ * @deprecated required by legacy features in GWT's old HandlerManager
+ */
+ @Deprecated
+ protected <H> H getHandler(Event.Type<H> type, int index) {
+ assert index < getHandlerCount(type) : "handlers for " + type.getClass() + " have size: "
+ + getHandlerCount(type) + " so do not have a handler at index: " + index;
+
+ List<H> l = getHandlerList(type, null);
+ return l.get(index);
+ }
+
+ /**
+ * @deprecated required by legacy features in GWT's old HandlerManager
+ */
+ @Deprecated
+ protected int getHandlerCount(Event.Type<?> eventKey) {
+ return getHandlerList(eventKey, null).size();
+ }
+
+ /**
+ * @deprecated required by legacy features in GWT's old HandlerManager
+ */
+ @Deprecated
+ protected boolean isEventHandled(Event.Type<?> eventKey) {
+ return map.containsKey(eventKey);
+ }
+
+ private void defer(Command command) {
+ if (deferredDeltas == null) {
+ deferredDeltas = new ArrayList<Command>();
+ }
+ deferredDeltas.add(command);
+ }
+
+ private <H> HandlerRegistration doAdd(final Event.Type<H> type, final Object source,
+ final H handler) {
+ if (type == null) {
+ throw new NullPointerException("Cannot add a handler with a null type");
+ }
+ if (handler == null) {
+ throw new NullPointerException("Cannot add a null handler");
+ }
+
+ if (firingDepth > 0) {
+ enqueueAdd(type, source, handler);
+ } else {
+ doAddNow(type, source, handler);
+ }
+
+ return new HandlerRegistration() {
+ public void removeHandler() {
+ doRemove(type, source, handler);
+ }
+ };
+ }
+
+ private <H> void doAddNow(Event.Type<H> type, Object source, H handler) {
+ List<H> l = ensureHandlerList(type, source);
+ l.add(handler);
+ }
+
+ private <H> void doFire(Event<H> event, Object source) {
+ if (event == null) {
+ throw new NullPointerException("Cannot fire null event");
+ }
+ try {
+ firingDepth++;
+
+ if (source != null) {
+ event.setSource(source);
+ }
+
+ List<H> handlers = getDispatchList(event.getAssociatedType(), source);
+ Set<Throwable> causes = null;
+
+ ListIterator<H> it =
+ isReverseOrder ? handlers.listIterator(handlers.size()) : handlers.listIterator();
+ while (isReverseOrder ? it.hasPrevious() : it.hasNext()) {
+ H handler = isReverseOrder ? it.previous() : it.next();
+
+ try {
+ event.dispatch(handler);
+ } catch (Throwable e) {
+ if (causes == null) {
+ causes = new HashSet<Throwable>();
+ }
+ causes.add(e);
+ }
+ }
+
+ if (causes != null) {
+ throw new UmbrellaException(causes);
+ }
+ } finally {
+ firingDepth--;
+ if (firingDepth == 0) {
+ handleQueuedAddsAndRemoves();
+ }
+ }
+ }
+
+ private <H> void doRemoveNow(Event.Type<H> type, Object source, H handler) {
+ List<H> l = getHandlerList(type, source);
+
+ boolean removed = l.remove(handler);
+ assert removed : "redundant remove call";
+ if (removed && l.isEmpty()) {
+ prune(type, source);
+ }
+ }
+
+ private <H> void enqueueAdd(final Event.Type<H> type, final Object source, final H handler) {
+ defer(new Command() {
+ public void execute() {
+ doAddNow(type, source, handler);
+ }
+ });
+ }
+
+ private <H> void enqueueRemove(final Event.Type<H> type, final Object source, final H handler) {
+ defer(new Command() {
+ public void execute() {
+ doRemoveNow(type, source, handler);
+ }
+ });
+ }
+
+ private <H> List<H> ensureHandlerList(Event.Type<H> type, Object source) {
+ Map<Object, List<?>> sourceMap = map.get(type);
+ if (sourceMap == null) {
+ sourceMap = new HashMap<Object, List<?>>();
+ map.put(type, sourceMap);
+ }
+
+ // safe, we control the puts.
+ @SuppressWarnings("unchecked")
+ List<H> handlers = (List<H>) sourceMap.get(source);
+ if (handlers == null) {
+ handlers = new ArrayList<H>();
+ sourceMap.put(source, handlers);
+ }
+
+ return handlers;
+ }
+
+ private <H> List<H> getDispatchList(Event.Type<H> type, Object source) {
+ List<H> directHandlers = getHandlerList(type, source);
+ if (source == null) {
+ return directHandlers;
+ }
+
+ List<H> globalHandlers = getHandlerList(type, null);
+
+ List<H> rtn = new ArrayList<H>(directHandlers);
+ rtn.addAll(globalHandlers);
+ return rtn;
+ }
+
+ private <H> List<H> getHandlerList(Event.Type<H> type, Object source) {
+ Map<Object, List<?>> sourceMap = map.get(type);
+ if (sourceMap == null) {
+ return Collections.emptyList();
+ }
+
+ // safe, we control the puts.
+ @SuppressWarnings("unchecked")
+ List<H> handlers = (List<H>) sourceMap.get(source);
+ if (handlers == null) {
+ return Collections.emptyList();
+ }
+
+ return handlers;
+ }
+
+ private void handleQueuedAddsAndRemoves() {
+ if (deferredDeltas != null) {
+ try {
+ for (Command c : deferredDeltas) {
+ c.execute();
+ }
+ } finally {
+ deferredDeltas = null;
+ }
+ }
+ }
+
+ private void prune(Event.Type<?> type, Object source) {
+ Map<Object, List<?>> sourceMap = map.get(type);
+
+ List<?> pruned = sourceMap.remove(source);
+
+ assert pruned != null : "Can't prune what wasn't there";
+ assert pruned.isEmpty() : "Pruned unempty list!";
+
+ if (sourceMap.isEmpty()) {
+ map.remove(type);
+ }
+ }
+}
\ No newline at end of file
diff --git a/user/src/com/google/web/bindery/event/shared/UmbrellaException.java b/user/src/com/google/web/bindery/event/shared/UmbrellaException.java
new file mode 100644
index 0000000..3ed254b
--- /dev/null
+++ b/user/src/com/google/web/bindery/event/shared/UmbrellaException.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * A {@link RuntimeException} that collects a {@link Set} of child
+ * {@link Throwable}s together. Typically thrown after a loop, with all of the
+ * exceptions thrown during that loop, but delayed so that the loop finishes
+ * executing.
+ */
+public class UmbrellaException extends RuntimeException {
+
+ private static final String MSG =
+ "One or more exceptions caught, see full set in UmbrellaException#getCauses";
+ /**
+ * The causes of the exception.
+ */
+ private Set<Throwable> causes;
+
+ public UmbrellaException(Set<Throwable> causes) {
+ super(MSG, causes.size() == 0 ? null : causes.toArray(new Throwable[0])[0]);
+ this.causes = causes;
+ }
+
+ /**
+ * Required for GWT RPC serialization.
+ */
+ protected UmbrellaException() {
+ // Can't delegate to the other constructor or GWT RPC gets cranky
+ super(MSG);
+ this.causes = Collections.<Throwable> emptySet();
+ }
+
+ /**
+ * Get the set of exceptions that caused the failure.
+ *
+ * @return the set of causes
+ */
+ public Set<Throwable> getCauses() {
+ return causes;
+ }
+}
diff --git a/user/src/com/google/web/bindery/event/shared/testing/CountingEventBus.java b/user/src/com/google/web/bindery/event/shared/testing/CountingEventBus.java
new file mode 100644
index 0000000..4b657a4
--- /dev/null
+++ b/user/src/com/google/web/bindery/event/shared/testing/CountingEventBus.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared.testing;
+
+import com.google.web.bindery.event.shared.Event;
+import com.google.web.bindery.event.shared.Event.Type;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
+import com.google.web.bindery.event.shared.SimpleEventBus;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Wraps an {@link EventBus} to keep a count of registered handlers. Handy for
+ * tests.
+ */
+public class CountingEventBus extends EventBus {
+ private final Map<Type<?>, Integer> counts = new HashMap<Event.Type<?>, Integer>();
+ private final EventBus wrapped;
+
+ public CountingEventBus() {
+ this(new SimpleEventBus());
+ }
+
+ public CountingEventBus(EventBus wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ @Override
+ public <H> HandlerRegistration addHandler(Type<H> type, H handler) {
+ increment(type);
+ final HandlerRegistration superReg = wrapped.addHandler(type, handler);
+ return makeReg(type, superReg);
+ }
+
+ @Override
+ public <H> HandlerRegistration addHandlerToSource(final Type<H> type, Object source, H handler) {
+ increment(type);
+ final HandlerRegistration superReg = wrapped.addHandlerToSource(type, source, handler);
+ return makeReg(type, superReg);
+ }
+
+ @Override
+ public void fireEvent(Event<?> event) {
+ wrapped.fireEvent(event);
+ }
+
+ @Override
+ public void fireEventFromSource(Event<?> event, Object source) {
+ wrapped.fireEventFromSource(event, source);
+ }
+
+ public int getCount(Type<?> type) {
+ Integer count = counts.get(type);
+ return count == null ? 0 : count;
+ }
+
+ private void decrement(Type<?> type) {
+ counts.put(type, getCount(type) - 1);
+ }
+
+ private <H> void increment(final Type<H> type) {
+ counts.put(type, getCount(type) + 1);
+ }
+
+ private <H> HandlerRegistration makeReg(final Type<H> type, final HandlerRegistration superReg) {
+ return new HandlerRegistration() {
+ public void removeHandler() {
+ decrement(type);
+ superReg.removeHandler();
+ }
+ };
+ }
+}
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryEditorDriver.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryEditorDriver.java
index 4b25470..e5535e2 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryEditorDriver.java
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryEditorDriver.java
@@ -17,7 +17,7 @@
import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.EditorDriver;
-import com.google.gwt.event.shared.EventBus;
+import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
import com.google.web.bindery.requestfactory.shared.Violation;
@@ -87,6 +87,15 @@
String[] getPaths();
/**
+ * Initializes a driver that will not be able to support subscriptions. Calls
+ * to {@link com.google.gwt.editor.client.EditorDelegate#subscribe()} will do
+ * nothing.
+ *
+ * @param editor an {@link Editor} of type E
+ */
+ void initialize(E editor);
+
+ /**
* Overload of {@link #initialize(RequestFactory, Editor)} to allow a modified
* {@link EventBus} to be monitored for subscription services.
*
@@ -111,15 +120,6 @@
void initialize(RequestFactory requestFactory, E editor);
/**
- * Initializes a driver that will not be able to support subscriptions. Calls
- * to {@link com.google.gwt.editor.client.EditorDelegate#subscribe()} will do
- * nothing.
- *
- * @param editor an {@link Editor} of type E
- */
- void initialize(E editor);
-
- /**
* Show Violations returned from an attempt to submit a request. The
* violations will be converted into
* {@link com.google.gwt.editor.client.EditorError EditorError} objects whose
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractClientRequestFactory.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractClientRequestFactory.java
index 15267b7..b122674 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractClientRequestFactory.java
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractClientRequestFactory.java
@@ -15,7 +15,7 @@
*/
package com.google.web.bindery.requestfactory.gwt.client.impl;
-import com.google.gwt.event.shared.EventBus;
+import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport;
import com.google.web.bindery.requestfactory.shared.impl.AbstractRequestFactory;
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
index df21135..94f71ba 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/AbstractRequestFactoryEditorDriver.java
@@ -25,7 +25,7 @@
import com.google.gwt.editor.client.impl.DelegateMap;
import com.google.gwt.editor.client.impl.DelegateMap.KeyMethod;
import com.google.gwt.editor.client.impl.SimpleViolation;
-import com.google.gwt.event.shared.EventBus;
+import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.gwt.client.HasRequestContext;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/RequestFactoryEditorDelegate.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/RequestFactoryEditorDelegate.java
index 7b8b3af..1acfcd3 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/RequestFactoryEditorDelegate.java
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/impl/RequestFactoryEditorDelegate.java
@@ -18,8 +18,8 @@
import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.impl.AbstractEditorDelegate;
import com.google.gwt.editor.client.impl.Refresher;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
import com.google.web.bindery.requestfactory.shared.BaseProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxyChange;
diff --git a/user/src/com/google/web/bindery/requestfactory/gwt/client/testing/MockRequestFactoryEditorDriver.java b/user/src/com/google/web/bindery/requestfactory/gwt/client/testing/MockRequestFactoryEditorDriver.java
index 98da89c..5cc2223 100644
--- a/user/src/com/google/web/bindery/requestfactory/gwt/client/testing/MockRequestFactoryEditorDriver.java
+++ b/user/src/com/google/web/bindery/requestfactory/gwt/client/testing/MockRequestFactoryEditorDriver.java
@@ -18,7 +18,7 @@
import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.EditorError;
import com.google.gwt.editor.client.EditorVisitor;
-import com.google.gwt.event.shared.EventBus;
+import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
diff --git a/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryJarExtractor.java b/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryJarExtractor.java
index d3d609c..f1e4718 100644
--- a/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryJarExtractor.java
+++ b/user/src/com/google/web/bindery/requestfactory/server/RequestFactoryJarExtractor.java
@@ -30,7 +30,7 @@
import com.google.gwt.dev.asm.commons.Method;
import com.google.gwt.dev.util.Name;
import com.google.gwt.dev.util.Util;
-import com.google.gwt.event.shared.SimpleEventBus;
+import com.google.web.bindery.event.shared.SimpleEventBus;
import com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.ClassLoaderLoader;
import com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.ErrorContext;
import com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.Loader;
@@ -529,7 +529,7 @@
typeName = type.getClassName();
}
- public State call() throws Exception {
+ public State call() {
ClassWriter writer = new ClassWriter(0);
ClassVisitor cv = writer;
cv = new ClassProcessor(typeName, cv, state);
diff --git a/user/src/com/google/web/bindery/requestfactory/shared/EntityProxyChange.java b/user/src/com/google/web/bindery/requestfactory/shared/EntityProxyChange.java
index c146efb..ab013cb 100644
--- a/user/src/com/google/web/bindery/requestfactory/shared/EntityProxyChange.java
+++ b/user/src/com/google/web/bindery/requestfactory/shared/EntityProxyChange.java
@@ -15,10 +15,9 @@
*/
package com.google.web.bindery.requestfactory.shared;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.event.shared.GwtEvent;
-import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.web.bindery.event.shared.Event;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.HandlerRegistration;
/**
* Event posted by a {@link RequestFactory} when changes to an entity are
@@ -36,14 +35,14 @@
* @see RequestFactory#find(EntityProxyId)
*/
public class EntityProxyChange<P extends EntityProxy> extends
- GwtEvent<EntityProxyChange.Handler<P>> {
+ Event<EntityProxyChange.Handler<P>> {
/**
* Implemented by methods that handle EntityProxyChange events.
*
* @param <P> the proxy type
*/
- public interface Handler<P extends EntityProxy> extends EventHandler {
+ public interface Handler<P extends EntityProxy> {
/**
* Called when an {@link EntityProxyChange} event is fired.
*
@@ -87,11 +86,11 @@
/**
* Returns the type associated with this instance.
*
- * @return an instance of {@link com.google.gwt.event.shared.GwtEvent.Type Type} of type Handler<P>
+ * @return an instance of {@link Event.Type Type} of type Handler<P>
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
- public GwtEvent.Type<Handler<P>> getAssociatedType() {
+ public Event.Type<Handler<P>> getAssociatedType() {
/*
* The instance knows its handler is of type P, but the TYPE field itself
* does not, so we have to do an unsafe cast here.
diff --git a/user/src/com/google/web/bindery/requestfactory/shared/RequestFactory.java b/user/src/com/google/web/bindery/requestfactory/shared/RequestFactory.java
index 7f66954..c265cd9 100644
--- a/user/src/com/google/web/bindery/requestfactory/shared/RequestFactory.java
+++ b/user/src/com/google/web/bindery/requestfactory/shared/RequestFactory.java
@@ -15,7 +15,7 @@
*/
package com.google.web.bindery.requestfactory.shared;
-import com.google.gwt.event.shared.EventBus;
+import com.google.web.bindery.event.shared.EventBus;
/**
* Marker interface for the RequestFactory code generator.
diff --git a/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java b/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java
index dd61fa2..0e10a3a 100644
--- a/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java
+++ b/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestContext.java
@@ -29,7 +29,7 @@
import com.google.web.bindery.autobean.shared.impl.AbstractAutoBean;
import com.google.web.bindery.autobean.shared.impl.EnumMap;
import com.google.web.bindery.autobean.shared.impl.StringQuoter;
-import com.google.gwt.event.shared.UmbrellaException;
+import com.google.web.bindery.event.shared.UmbrellaException;
import com.google.web.bindery.requestfactory.shared.BaseProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxyChange;
diff --git a/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestFactory.java b/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestFactory.java
index a13e62d..4b3d69e 100644
--- a/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestFactory.java
+++ b/user/src/com/google/web/bindery/requestfactory/shared/impl/AbstractRequestFactory.java
@@ -16,7 +16,7 @@
package com.google.web.bindery.requestfactory.shared.impl;
import com.google.web.bindery.autobean.shared.AutoBeanFactory;
-import com.google.gwt.event.shared.EventBus;
+import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.ProxySerializer;
diff --git a/user/src/com/google/web/bindery/requestfactory/vm/InProcessRequestFactory.java b/user/src/com/google/web/bindery/requestfactory/vm/InProcessRequestFactory.java
index 3d931ca..d9129c3 100644
--- a/user/src/com/google/web/bindery/requestfactory/vm/InProcessRequestFactory.java
+++ b/user/src/com/google/web/bindery/requestfactory/vm/InProcessRequestFactory.java
@@ -19,7 +19,7 @@
import com.google.web.bindery.autobean.shared.AutoBeanFactory.Category;
import com.google.web.bindery.autobean.shared.AutoBeanFactory.NoWrap;
import com.google.web.bindery.autobean.vm.AutoBeanFactorySource;
-import com.google.gwt.event.shared.EventBus;
+import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.shared.BaseProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
@@ -27,11 +27,11 @@
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
import com.google.web.bindery.requestfactory.shared.ValueProxy;
+import com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.Dialect;
import com.google.web.bindery.requestfactory.shared.impl.AbstractRequestFactory;
import com.google.web.bindery.requestfactory.shared.impl.BaseProxyCategory;
import com.google.web.bindery.requestfactory.shared.impl.EntityProxyCategory;
import com.google.web.bindery.requestfactory.shared.impl.ValueProxyCategory;
-import com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.Dialect;
import com.google.web.bindery.requestfactory.vm.InProcessRequestContext.RequestContextHandler;
import java.lang.reflect.InvocationHandler;
diff --git a/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java b/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
index 7287d92..ea4ba53 100644
--- a/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
+++ b/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
@@ -15,17 +15,16 @@
*/
package com.google.gwt.activity.shared;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.EventHandler;
-import com.google.gwt.event.shared.GwtEvent;
-import com.google.gwt.event.shared.UmbrellaException;
-import com.google.gwt.event.shared.testing.CountingEventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceChangeEvent;
import com.google.gwt.place.shared.PlaceChangeRequestEvent;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
+import com.google.web.bindery.event.shared.Event;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.UmbrellaException;
+import com.google.web.bindery.event.shared.testing.CountingEventBus;
import junit.framework.TestCase;
@@ -49,11 +48,11 @@
}
}
- private static class Event extends GwtEvent<Handler> {
- private static GwtEvent.Type<EventHandler> TYPE = new GwtEvent.Type<EventHandler>();
+ private static class MyEvent extends Event<Handler> {
+ private static Event.Type<Handler> TYPE = new Event.Type<Handler>();
@Override
- public com.google.gwt.event.shared.GwtEvent.Type<Handler> getAssociatedType() {
+ public Event.Type<Handler> getAssociatedType() {
throw new UnsupportedOperationException("Auto-generated method stub");
}
@@ -63,7 +62,7 @@
}
}
- private static class Handler implements EventHandler {
+ private static class Handler {
};
private static class MyDisplay implements AcceptsOneWidget {
@@ -261,29 +260,29 @@
public void testDropHandlersOnStop() {
manager.setDisplay(realDisplay);
- assertEquals(0, eventBus.getCount(Event.TYPE));
+ assertEquals(0, eventBus.getCount(MyEvent.TYPE));
activity1 = new SyncActivity(null) {
@Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
super.start(panel, eventBus);
- bus.addHandler(Event.TYPE, new Handler());
+ bus.addHandler(MyEvent.TYPE, new Handler());
}
@Override
public void onStop() {
super.onStop();
- bus.addHandler(Event.TYPE, new Handler());
+ bus.addHandler(MyEvent.TYPE, new Handler());
}
};
PlaceChangeEvent event = new PlaceChangeEvent(place1);
eventBus.fireEvent(event);
- assertEquals(1, eventBus.getCount(Event.TYPE));
+ assertEquals(1, eventBus.getCount(MyEvent.TYPE));
event = new PlaceChangeEvent(place2);
eventBus.fireEvent(event);
- assertEquals(0, eventBus.getCount(Event.TYPE));
+ assertEquals(0, eventBus.getCount(MyEvent.TYPE));
// Make sure we didn't nuke the ActivityManager's own handlers
assertEquals(1, eventBus.getCount(PlaceChangeEvent.TYPE));
@@ -310,12 +309,12 @@
@Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
super.start(panel, eventBus);
- bus.addHandler(Event.TYPE, new Handler());
+ bus.addHandler(MyEvent.TYPE, new Handler());
}
@Override
public void onStop() {
super.onStop();
- bus.addHandler(Event.TYPE, new Handler());
+ bus.addHandler(MyEvent.TYPE, new Handler());
throw new UnsupportedOperationException("Auto-generated method stub");
}
};
@@ -333,7 +332,7 @@
try {
PlaceChangeEvent event = new PlaceChangeEvent(place1);
eventBus.fireEvent(event);
- assertEquals(1, eventBus.getCount(Event.TYPE));
+ assertEquals(1, eventBus.getCount(MyEvent.TYPE));
event = new PlaceChangeEvent(place2);
eventBus.fireEvent(event);
@@ -349,7 +348,7 @@
assertTrue(activity1.stopped);
assertNotNull(activity2.display);
- assertEquals(0, eventBus.getCount(Event.TYPE));
+ assertEquals(0, eventBus.getCount(MyEvent.TYPE));
}
/**
diff --git a/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java b/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java
index 1f1e329..5746f56 100644
--- a/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java
+++ b/user/test/com/google/gwt/editor/rebind/model/EditorModelTest.java
@@ -38,9 +38,9 @@
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.editor.client.ValueAwareEditor;
import com.google.gwt.editor.client.adapters.SimpleEditor;
-import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.TakesValue;
import com.google.gwt.user.client.ui.HasText;
+import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
import com.google.web.bindery.requestfactory.shared.Request;
@@ -503,6 +503,7 @@
assertNull(editorField.getSetterName());
}
+ @SuppressWarnings("deprecation")
private Set<Resource> getJavaResources() {
MockJavaResource[] javaFiles = {new MockJavaResource("t.AddressProxy") {
@Override
@@ -944,6 +945,7 @@
new RealJavaResource(EditorError.class),
new EmptyMockJavaResource(EntityProxy.class),
new EmptyMockJavaResource(EventBus.class),
+ new EmptyMockJavaResource(com.google.gwt.event.shared.EventBus.class),
new EmptyMockJavaResource(HasEditorDelegate.class),
new EmptyMockJavaResource(HasEditorErrors.class),
new RealJavaResource(HasText.class),
diff --git a/user/test/com/google/gwt/event/shared/HandlerManagerTest.java b/user/test/com/google/gwt/event/shared/HandlerManagerTest.java
index 7b96e17..b003e32 100644
--- a/user/test/com/google/gwt/event/shared/HandlerManagerTest.java
+++ b/user/test/com/google/gwt/event/shared/HandlerManagerTest.java
@@ -27,7 +27,6 @@
* Handler manager test. Very redundant with {@link SimpleEventBusTest}, but
* preserved to guard against regressions.
*/
-@SuppressWarnings("deprecation")
public class HandlerManagerTest extends HandlerTestBase {
public void testAddAndRemoveHandlers() {
@@ -352,6 +351,7 @@
assertFired(mouse1, mouse2, mouse3);
}
+ @SuppressWarnings("deprecation")
public void testNullSourceOkay() {
SimpleEventBus reg = new SimpleEventBus();
diff --git a/user/test/com/google/gwt/event/shared/ResettableEventBusTest.java b/user/test/com/google/gwt/event/shared/ResettableEventBusTest.java
index 9e14a8d..0044a4c 100644
--- a/user/test/com/google/gwt/event/shared/ResettableEventBusTest.java
+++ b/user/test/com/google/gwt/event/shared/ResettableEventBusTest.java
@@ -24,6 +24,7 @@
* Eponymous unit test.
*/
public class ResettableEventBusTest extends HandlerTestBase {
+
public void testSimple() {
CountingEventBus wrapped = new CountingEventBus();
ResettableEventBus subject = new ResettableEventBus(wrapped);
diff --git a/user/test/com/google/gwt/event/shared/SimpleEventBusTest.java b/user/test/com/google/gwt/event/shared/SimpleEventBusTest.java
index 3221e83..944cd77 100644
--- a/user/test/com/google/gwt/event/shared/SimpleEventBusTest.java
+++ b/user/test/com/google/gwt/event/shared/SimpleEventBusTest.java
@@ -17,82 +17,22 @@
package com.google.gwt.event.shared;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
-import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.DomEvent.Type;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
-import com.google.gwt.event.shared.testing.CountingEventBus;
import junit.framework.AssertionFailedError;
import java.util.Set;
/**
- * Eponymous unit test.
+ * Eponymous unit test. Redundant with
+ * {@link com.google.web.bindery.event.shared.SimpleEventBusTest}, here to
+ * ensure legacy compatibility.
*/
+@SuppressWarnings("deprecation")
public class SimpleEventBusTest extends HandlerTestBase {
- public void testAddAndRemoveHandlers() {
- CountingEventBus eventBus = new CountingEventBus(new SimpleEventBus());
- eventBus.addHandler(MouseDownEvent.getType(), mouse1);
- eventBus.addHandler(MouseDownEvent.getType(), mouse2);
- HandlerRegistration reg1 = eventBus.addHandler(MouseDownEvent.getType(),
- adaptor1);
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertEquals(3, eventBus.getCount(MouseDownEvent.getType()));
- assertFired(mouse1, mouse2, adaptor1);
- eventBus.addHandler(MouseDownEvent.getType(), mouse3);
- assertEquals(4, eventBus.getCount(MouseDownEvent.getType()));
-
- eventBus.addHandler(MouseDownEvent.getType(), mouse1);
- eventBus.addHandler(MouseDownEvent.getType(), mouse2);
- HandlerRegistration reg2 = eventBus.addHandler(MouseDownEvent.getType(),
- adaptor1);
-
- /*
- * You can indeed add handlers twice, they will only be removed one at a
- * time though.
- */
- assertEquals(7, eventBus.getCount(MouseDownEvent.getType()));
- eventBus.addHandler(ClickEvent.getType(), adaptor1);
- eventBus.addHandler(ClickEvent.getType(), click1);
- eventBus.addHandler(ClickEvent.getType(), click2);
-
- assertEquals(7, eventBus.getCount(MouseDownEvent.getType()));
- assertEquals(3, eventBus.getCount(ClickEvent.getType()));
-
- reset();
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertFired(mouse1, mouse2, mouse3, adaptor1);
- assertNotFired(click1, click2);
-
- // Gets rid of first instance.
- reg1.removeHandler();
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertFired(mouse1, mouse2, mouse3, adaptor1);
- assertNotFired(click1, click2);
-
- // Gets rid of second instance.
- reg2.removeHandler();
- reset();
- eventBus.fireEvent(new MouseDownEvent() {
- });
-
- assertFired(mouse1, mouse2, mouse3);
- assertNotFired(adaptor1, click1, click2);
-
- // Checks to see if click events are still working.
- reset();
- eventBus.fireEvent(new ClickEvent() {
- });
-
- assertNotFired(mouse1, mouse2, mouse3);
- assertFired(click1, click2, adaptor1);
- }
-
public void testConcurrentAdd() {
final SimpleEventBus eventBus = new SimpleEventBus();
final MouseDownHandler two = new MouseDownHandler() {
@@ -130,26 +70,6 @@
}
}
- public void testConcurrentRemove() {
- final SimpleEventBus eventBus = new SimpleEventBus();
-
- ShyHandler h = new ShyHandler();
-
- eventBus.addHandler(MouseDownEvent.getType(), mouse1);
- h.r = eventBus.addHandler(MouseDownEvent.getType(), h);
- eventBus.addHandler(MouseDownEvent.getType(), mouse2);
- eventBus.addHandler(MouseDownEvent.getType(), mouse3);
-
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertFired(h, mouse1, mouse2, mouse3);
- reset();
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertFired(mouse1, mouse2, mouse3);
- assertNotFired(h);
- }
-
class SourcedHandler implements MouseDownHandler {
final String expectedSource;
@@ -311,109 +231,6 @@
assertNotFired(two);
}
- public void testRemoveSelf() {
- final SimpleEventBus eventBus = new SimpleEventBus();
-
- MouseDownHandler h = new MouseDownHandler() {
- HandlerRegistration reg = eventBus.addHandler(MouseDownEvent.getType(),
- this);
-
- public void onMouseDown(MouseDownEvent event) {
- add(this);
- reg.removeHandler();
- }
- };
-
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertFired(h);
-
- reset();
-
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertNotFired(h);
- }
-
- public void testNoDoubleRemove() {
- final SimpleEventBus eventBus = new SimpleEventBus();
- HandlerRegistration reg = eventBus.addHandler(MouseDownEvent.getType(),
- mouse1);
- reg.removeHandler();
-
- boolean assertsOn = getClass().desiredAssertionStatus();
-
- if (assertsOn) {
- try {
- reg.removeHandler();
- fail("Should have thrown on remove");
- } catch (AssertionError e) { /* pass */
- }
- } else {
- reg.removeHandler();
- // Succeed on no assert failure
- }
- }
-
- public void testConcurrentAddAfterRemoveIsNotClobbered() {
- final SimpleEventBus eventBus = new SimpleEventBus();
-
- MouseDownHandler one = new MouseDownHandler() {
- HandlerRegistration reg = addIt();
-
- public void onMouseDown(MouseDownEvent event) {
- reg.removeHandler();
- addIt();
- add(this);
- }
-
- private HandlerRegistration addIt() {
- return eventBus.addHandler(MouseDownEvent.getType(), mouse1);
- }
- };
-
- eventBus.addHandler(MouseDownEvent.getType(), one);
-
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertFired(one);
-
- reset();
-
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertFired(one, mouse1);
- }
-
- public void testReverseOrder() {
- @SuppressWarnings("deprecation")
- final SimpleEventBus eventBus = new SimpleEventBus(true);
- final MouseDownHandler handler0 = new MouseDownHandler() {
- public void onMouseDown(MouseDownEvent event) {
- add(this);
- }
- };
- final MouseDownHandler handler1 = new MouseDownHandler() {
- public void onMouseDown(MouseDownEvent event) {
- assertNotFired(handler0);
- add(this);
- }
- };
- final MouseDownHandler handler2 = new MouseDownHandler() {
- public void onMouseDown(MouseDownEvent event) {
- assertNotFired(handler0, handler1);
- add(this);
- }
- };
- eventBus.addHandler(MouseDownEvent.getType(), handler0);
- eventBus.addHandler(MouseDownEvent.getType(), handler1);
- eventBus.addHandler(MouseDownEvent.getType(), handler2);
-
- reset();
- eventBus.fireEvent(new MouseDownEvent() {
- });
- assertFired(handler0, handler1, handler2);
- }
static class ThrowingHandler implements MouseDownHandler {
private final RuntimeException e;
diff --git a/user/test/com/google/gwt/user/client/ui/WidgetTest.java b/user/test/com/google/gwt/user/client/ui/WidgetTest.java
index 9d78fd7..8a2d482 100644
--- a/user/test/com/google/gwt/user/client/ui/WidgetTest.java
+++ b/user/test/com/google/gwt/user/client/ui/WidgetTest.java
@@ -18,6 +18,7 @@
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.junit.client.GWTTestCase;
@@ -44,13 +45,11 @@
return "com.google.gwt.user.User";
}
- @SuppressWarnings("deprecation")
public void testCreateHandlerManager() {
- final com.google.gwt.event.shared.HandlerManager manager = new com.google.gwt.event.shared.HandlerManager(
- null);
+ final HandlerManager manager = new HandlerManager(null);
Widget w = new Widget() {
@Override
- protected com.google.gwt.event.shared.HandlerManager createHandlerManager() {
+ protected HandlerManager createHandlerManager() {
return manager;
}
};
diff --git a/user/test/com/google/web/bindery/event/shared/BarEvent.java b/user/test/com/google/web/bindery/event/shared/BarEvent.java
new file mode 100644
index 0000000..35b21f9
--- /dev/null
+++ b/user/test/com/google/web/bindery/event/shared/BarEvent.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+/**
+ * For {@link EventBus} tests.
+ */
+public class BarEvent extends Event<BarEvent.Handler> {
+ interface Handler {
+ void onBar(BarEvent e);
+ }
+
+ static final Type<Handler> TYPE = new Type<Handler>();
+
+ public static HandlerRegistration register(EventBus bus, Handler handler) {
+ return bus.addHandler(TYPE, handler);
+ }
+
+ public static HandlerRegistration register(EventBus bus, Object source, Handler handler) {
+ return bus.addHandlerToSource(TYPE, source, handler);
+ }
+
+ @Override
+ public com.google.web.bindery.event.shared.Event.Type<Handler> getAssociatedType() {
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(Handler handler) {
+ handler.onBar(this);
+ }
+}
diff --git a/user/test/com/google/web/bindery/event/shared/EventBusTestBase.java b/user/test/com/google/web/bindery/event/shared/EventBusTestBase.java
new file mode 100644
index 0000000..129b182
--- /dev/null
+++ b/user/test/com/google/web/bindery/event/shared/EventBusTestBase.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+import junit.framework.TestCase;
+
+import java.util.HashSet;
+
+/**
+ * Support code for handler tests.
+ */
+public abstract class EventBusTestBase extends TestCase {
+
+ class Adaptor implements FooEvent.Handler, BarEvent.Handler {
+
+ public void onFoo(FooEvent event) {
+ add(this);
+ }
+
+ public void onBar(BarEvent event) {
+ add(this);
+ }
+
+ @Override
+ public String toString() {
+ return "adaptor 1";
+ }
+ }
+
+ Adaptor adaptor1 = new Adaptor();
+
+ private HashSet<Object> active = new HashSet<Object>();
+
+ FooEvent.Handler fooHandler1 = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ add(fooHandler1);
+ }
+
+ @Override
+ public String toString() {
+ return "fooHandler 1";
+ }
+ };
+
+ FooEvent.Handler fooHandler2 = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ add(fooHandler2);
+ }
+
+ @Override
+ public String toString() {
+ return "fooHandler 2";
+ }
+ };
+
+ FooEvent.Handler fooHandler3 = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ add(fooHandler3);
+ }
+
+ @Override
+ public String toString() {
+ return "fooHandler 3";
+ }
+ };
+
+ BarEvent.Handler barHandler1 = new BarEvent.Handler() {
+
+ public void onBar(BarEvent event) {
+ add(barHandler1);
+ }
+
+ @Override
+ public String toString() {
+ return "barHandler 1";
+ }
+ };
+
+ BarEvent.Handler barHandler2 = new BarEvent.Handler() {
+
+ public void onBar(BarEvent event) {
+ add(barHandler2);
+ }
+
+ @Override
+ public String toString() {
+ return "barHandler 2";
+ }
+ };
+
+ BarEvent.Handler barHandler3 = new BarEvent.Handler() {
+
+ public void onBar(BarEvent event) {
+ add(barHandler3);
+ }
+
+ @Override
+ public String toString() {
+ return "barHandler 3";
+ }
+ };
+
+ void add(Object handler) {
+ active.add(handler);
+ }
+
+ void assertFired(Object... handler) {
+ for (int i = 0; i < handler.length; i++) {
+ assertTrue(handler[i] + " should have fired", active.contains(handler[i]));
+ }
+ }
+
+ void assertNotFired(Object... handler) {
+ for (int i = 0; i < handler.length; i++) {
+ assertFalse(handler[i] + " should not have fired",
+ active.contains(handler[i]));
+ }
+ }
+
+ void reset() {
+ active.clear();
+ }
+
+}
diff --git a/user/test/com/google/web/bindery/event/shared/EventSharedSuite.java b/user/test/com/google/web/bindery/event/shared/EventSharedSuite.java
new file mode 100644
index 0000000..cf26579
--- /dev/null
+++ b/user/test/com/google/web/bindery/event/shared/EventSharedSuite.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Tests of shared Event code.
+ */
+public class EventSharedSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Tests of shared Event code");
+
+ suite.addTestSuite(SimpleEventBusTest.class);
+ suite.addTestSuite(ResettableEventBusTest.class);
+
+ return suite;
+ }
+
+ private EventSharedSuite() {
+ }
+}
diff --git a/user/test/com/google/web/bindery/event/shared/FooEvent.java b/user/test/com/google/web/bindery/event/shared/FooEvent.java
new file mode 100644
index 0000000..a63f53a
--- /dev/null
+++ b/user/test/com/google/web/bindery/event/shared/FooEvent.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+/**
+ * For {@link EventBus} tests.
+ */
+public class FooEvent extends Event<FooEvent.Handler> {
+ interface Handler {
+ void onFoo(FooEvent e);
+ }
+
+ static final Type<Handler> TYPE = new Type<Handler>();
+
+ public static HandlerRegistration register(EventBus bus, Handler handler) {
+ return bus.addHandler(TYPE, handler);
+ }
+
+ public static HandlerRegistration register(EventBus bus, Object source, Handler handler) {
+ return bus.addHandlerToSource(TYPE, source, handler);
+ }
+
+ @Override
+ public com.google.web.bindery.event.shared.Event.Type<Handler> getAssociatedType() {
+ return TYPE;
+ }
+
+ @Override
+ protected void dispatch(Handler handler) {
+ handler.onFoo(this);
+ }
+}
diff --git a/user/test/com/google/web/bindery/event/shared/ResettableEventBusTest.java b/user/test/com/google/web/bindery/event/shared/ResettableEventBusTest.java
new file mode 100644
index 0000000..b8591a8
--- /dev/null
+++ b/user/test/com/google/web/bindery/event/shared/ResettableEventBusTest.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+import com.google.web.bindery.event.shared.testing.CountingEventBus;
+
+/**
+ * Eponymous unit test.
+ */
+public class ResettableEventBusTest extends EventBusTestBase {
+ public void testSimple() {
+ CountingEventBus wrapped = new CountingEventBus();
+ ResettableEventBus subject = new ResettableEventBus(wrapped);
+
+ Event.Type<FooEvent.Handler> type = FooEvent.TYPE;
+
+ assertEquals(0, wrapped.getCount(type));
+
+ subject.addHandler(type, fooHandler1);
+ subject.addHandlerToSource(type, "baker", fooHandler2);
+ subject.addHandler(type, fooHandler3);
+
+ assertEquals(3, wrapped.getCount(type));
+
+ subject.fireEvent(new FooEvent());
+ assertFired(fooHandler1, fooHandler3);
+ assertNotFired(fooHandler2);
+
+ reset();
+
+ subject.fireEventFromSource(new FooEvent(), "baker");
+ assertFired(fooHandler1, fooHandler2, fooHandler3);
+
+ reset();
+
+ subject.removeHandlers();
+ assertEquals(0, wrapped.getCount(type));
+
+ subject.fireEvent(new FooEvent());
+ assertNotFired(fooHandler1, fooHandler2, fooHandler3);
+ }
+
+ public void testNestedResetInnerFirst() {
+ CountingEventBus wrapped = new CountingEventBus();
+ ResettableEventBus wideScope = new ResettableEventBus(wrapped);
+ ResettableEventBus narrowScope = new ResettableEventBus(wideScope);
+
+ Event.Type<FooEvent.Handler> type = FooEvent.TYPE;
+
+ wideScope.addHandler(type, fooHandler1);
+ narrowScope.addHandler(type, fooHandler2);
+
+ wrapped.fireEvent(new FooEvent());
+ assertFired(fooHandler1, fooHandler2);
+
+ reset();
+
+ /*
+ * When I remove handlers from the narrow resettable, it should have no
+ * effect on handlers registered with the wider instance.
+ */
+
+ narrowScope.removeHandlers();
+
+ wrapped.fireEvent(new FooEvent());
+ assertFired(fooHandler1);
+ assertNotFired(fooHandler2);
+ }
+
+ public void testNestedResetOuterFirst() {
+ CountingEventBus wrapped = new CountingEventBus();
+ ResettableEventBus wideScope = new ResettableEventBus(wrapped);
+ ResettableEventBus narrowScope = new ResettableEventBus(wideScope);
+
+ Event.Type<FooEvent.Handler> type = FooEvent.TYPE;
+
+ wideScope.addHandler(type, fooHandler1);
+ narrowScope.addHandler(type, fooHandler2);
+
+ wrapped.fireEvent(new FooEvent());
+ assertFired(fooHandler1, fooHandler2);
+
+ reset();
+
+ /*
+ * When I remove handlers from the first resettable, handlers registered by
+ * the narrower scoped one that wraps it should also be severed.
+ */
+
+ wideScope.removeHandlers();
+
+ wrapped.fireEvent(new FooEvent());
+ assertNotFired(fooHandler1);
+ assertNotFired(fooHandler2);
+ }
+
+ public void testManualRemoveMemory() {
+ SimpleEventBus eventBus = new SimpleEventBus();
+ ResettableEventBus subject = new ResettableEventBus(eventBus);
+
+ Event.Type<FooEvent.Handler> type = FooEvent.TYPE;
+
+ HandlerRegistration registration1 = subject.addHandler(type, fooHandler1);
+ HandlerRegistration registration2 = subject.addHandler(type, fooHandler2);
+ HandlerRegistration registration3 = subject.addHandler(type, fooHandler3);
+
+ registration1.removeHandler();
+ registration2.removeHandler();
+ registration3.removeHandler();
+
+ /*
+ * removing handlers manually should remove registration from the internal
+ * set.
+ */
+
+ assertEquals(0, subject.getRegistrationSize());
+
+ subject.removeHandlers();
+
+ // Expect nothing to happen. Especially no exceptions.
+ registration1.removeHandler();
+ }
+
+ public void testNestedRemoveMemory() {
+ SimpleEventBus eventBus = new SimpleEventBus();
+ ResettableEventBus wideScope = new ResettableEventBus(eventBus);
+ ResettableEventBus narrowScope = new ResettableEventBus(wideScope);
+
+ Event.Type<FooEvent.Handler> type = FooEvent.TYPE;
+
+ wideScope.addHandler(type, fooHandler1);
+ narrowScope.addHandler(type, fooHandler2);
+ narrowScope.addHandler(type, fooHandler3);
+
+ narrowScope.removeHandlers();
+ wideScope.removeHandlers();
+
+ /*
+ * Internal registeration should be empty after calling removeHandlers
+ */
+
+ assertEquals(0, wideScope.getRegistrationSize());
+ assertEquals(0, narrowScope.getRegistrationSize());
+
+ wideScope.addHandler(type, fooHandler1);
+ narrowScope.addHandler(type, fooHandler2);
+
+ /*
+ * Reverse remove order
+ */
+
+ wideScope.removeHandlers();
+ narrowScope.removeHandlers();
+
+ assertEquals(0, wideScope.getRegistrationSize());
+ assertEquals(0, narrowScope.getRegistrationSize());
+ }
+}
diff --git a/user/test/com/google/web/bindery/event/shared/SimpleEventBusTest.java b/user/test/com/google/web/bindery/event/shared/SimpleEventBusTest.java
new file mode 100644
index 0000000..29e6541
--- /dev/null
+++ b/user/test/com/google/web/bindery/event/shared/SimpleEventBusTest.java
@@ -0,0 +1,449 @@
+/*
+ * Copyright 2011 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.web.bindery.event.shared;
+
+import com.google.web.bindery.event.shared.testing.CountingEventBus;
+
+import junit.framework.AssertionFailedError;
+
+import java.util.Set;
+
+/**
+ * Eponymous unit test.
+ */
+public class SimpleEventBusTest extends EventBusTestBase {
+
+ interface Command {
+ void execute();
+ }
+
+ class ShyHandler implements FooEvent.Handler {
+ HandlerRegistration r;
+
+ public void onFoo(FooEvent event) {
+ add(this);
+ r.removeHandler();
+ }
+ }
+
+ class SourcedHandler implements FooEvent.Handler {
+ final String expectedSource;
+
+ SourcedHandler(String source) {
+ this.expectedSource = source;
+ }
+
+ public void onFoo(FooEvent event) {
+ add(this);
+ assertEquals(expectedSource, event.getSource());
+ }
+ }
+
+ static class ThrowingHandler implements FooEvent.Handler {
+ private final RuntimeException e;
+
+ public ThrowingHandler(RuntimeException e) {
+ this.e = e;
+ }
+
+ public void onFoo(FooEvent event) {
+ throw e;
+ }
+ }
+
+ public void testAddAndRemoveHandlers() {
+ CountingEventBus eventBus = new CountingEventBus(new SimpleEventBus());
+ FooEvent.register(eventBus, fooHandler1);
+ FooEvent.register(eventBus, fooHandler2);
+ HandlerRegistration reg1 = FooEvent.register(eventBus, adaptor1);
+ eventBus.fireEvent(new FooEvent());
+ assertEquals(3, eventBus.getCount(FooEvent.TYPE));
+ assertFired(fooHandler1, fooHandler2, adaptor1);
+ FooEvent.register(eventBus, fooHandler3);
+ assertEquals(4, eventBus.getCount(FooEvent.TYPE));
+
+ FooEvent.register(eventBus, fooHandler1);
+ FooEvent.register(eventBus, fooHandler2);
+ HandlerRegistration reg2 = FooEvent.register(eventBus, adaptor1);
+
+ /*
+ * You can indeed add handlers twice, they will only be removed one at a
+ * time though.
+ */
+ assertEquals(7, eventBus.getCount(FooEvent.TYPE));
+ eventBus.addHandler(BarEvent.TYPE, adaptor1);
+ eventBus.addHandler(BarEvent.TYPE, barHandler1);
+ eventBus.addHandler(BarEvent.TYPE, barHandler2);
+
+ assertEquals(7, eventBus.getCount(FooEvent.TYPE));
+ assertEquals(3, eventBus.getCount(BarEvent.TYPE));
+
+ reset();
+ eventBus.fireEvent(new FooEvent());
+ assertFired(fooHandler1, fooHandler2, fooHandler3, adaptor1);
+ assertNotFired(barHandler1, barHandler2);
+
+ // Gets rid of first instance.
+ reg1.removeHandler();
+ eventBus.fireEvent(new FooEvent());
+ assertFired(fooHandler1, fooHandler2, fooHandler3, adaptor1);
+ assertNotFired(barHandler1, barHandler2);
+
+ // Gets rid of second instance.
+ reg2.removeHandler();
+ reset();
+ eventBus.fireEvent(new FooEvent());
+
+ assertFired(fooHandler1, fooHandler2, fooHandler3);
+ assertNotFired(adaptor1, barHandler1, barHandler2);
+
+ // Checks to see if barHandler events are still working.
+ reset();
+ eventBus.fireEvent(new BarEvent());
+
+ assertNotFired(fooHandler1, fooHandler2, fooHandler3);
+ assertFired(barHandler1, barHandler2, adaptor1);
+ }
+
+ public void testAssertThrowsNpe() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+
+ try {
+ assertThrowsNpe(new Command() {
+ public void execute() {
+ FooEvent.register(eventBus, fooHandler1);
+ }
+ });
+ fail("expected AssertionFailedError");
+ } catch (AssertionFailedError e) {
+ /* pass */
+ }
+ }
+
+ public void testConcurrentAdd() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+ final FooEvent.Handler two = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ add(this);
+ }
+ };
+ FooEvent.Handler one = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ FooEvent.register(eventBus, two);
+ add(this);
+ }
+ };
+ FooEvent.register(eventBus, one);
+ FooEvent.register(eventBus, fooHandler1);
+ FooEvent.register(eventBus, fooHandler2);
+ FooEvent.register(eventBus, fooHandler3);
+ eventBus.fireEvent(new FooEvent());
+ assertFired(one, fooHandler1, fooHandler2, fooHandler3);
+ assertNotFired(two);
+
+ reset();
+ eventBus.fireEvent(new FooEvent());
+ assertFired(one, two, fooHandler1, fooHandler2, fooHandler3);
+ }
+
+ public void testConcurrentAddAfterRemoveIsNotClobbered() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+
+ FooEvent.Handler one = new FooEvent.Handler() {
+ HandlerRegistration reg = addIt();
+
+ public void onFoo(FooEvent event) {
+ reg.removeHandler();
+ addIt();
+ add(this);
+ }
+
+ private HandlerRegistration addIt() {
+ return FooEvent.register(eventBus, fooHandler1);
+ }
+ };
+
+ FooEvent.register(eventBus, one);
+
+ eventBus.fireEvent(new FooEvent());
+ assertFired(one);
+
+ reset();
+
+ eventBus.fireEvent(new FooEvent());
+ assertFired(one, fooHandler1);
+ }
+
+ public void testConcurrentAddAndRemoveByNastyUsersTryingToHurtUs() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+ final FooEvent.Handler two = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ add(this);
+ }
+
+ @Override
+ public String toString() {
+ return "two";
+ }
+ };
+ FooEvent.Handler one = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ FooEvent.register(eventBus, two).removeHandler();
+ add(this);
+ }
+
+ @Override
+ public String toString() {
+ return "one";
+ }
+ };
+ FooEvent.register(eventBus, one);
+ FooEvent.register(eventBus, fooHandler1);
+ FooEvent.register(eventBus, fooHandler2);
+ FooEvent.register(eventBus, fooHandler3);
+ eventBus.fireEvent(new FooEvent());
+ assertFired(one, fooHandler1, fooHandler2, fooHandler3);
+ assertNotFired(two);
+
+ reset();
+ eventBus.fireEvent(new FooEvent());
+ assertFired(one, fooHandler1, fooHandler2, fooHandler3);
+ assertNotFired(two);
+ }
+
+ public void testConcurrentRemove() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+
+ ShyHandler h = new ShyHandler();
+
+ FooEvent.register(eventBus, fooHandler1);
+ h.r = FooEvent.register(eventBus, h);
+ FooEvent.register(eventBus, fooHandler2);
+ FooEvent.register(eventBus, fooHandler3);
+
+ eventBus.fireEvent(new FooEvent());
+ assertFired(h, fooHandler1, fooHandler2, fooHandler3);
+ reset();
+ eventBus.fireEvent(new FooEvent());
+ assertFired(fooHandler1, fooHandler2, fooHandler3);
+ assertNotFired(h);
+ }
+
+ public void testFromSource() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+
+ SourcedHandler global = new SourcedHandler("able");
+ SourcedHandler able = new SourcedHandler("able");
+ SourcedHandler baker = new SourcedHandler("baker");
+
+ FooEvent.register(eventBus, global);
+ FooEvent.register(eventBus, "able", able);
+ FooEvent.register(eventBus, "baker", baker);
+
+ eventBus.fireEventFromSource(new FooEvent(), "able");
+ assertFired(global, able);
+ assertNotFired(baker);
+ }
+
+ public void testHandlersThrow() {
+ RuntimeException exception1 = new RuntimeException("first exception");
+ RuntimeException exception2 = new RuntimeException("second exception");
+
+ final SimpleEventBus eventBus = new SimpleEventBus();
+
+ FooEvent.register(eventBus, fooHandler1);
+ FooEvent.register(eventBus, new ThrowingHandler(exception1));
+ FooEvent.register(eventBus, fooHandler2);
+ FooEvent.register(eventBus, new ThrowingHandler(exception2));
+ FooEvent.register(eventBus, fooHandler3);
+
+ FooEvent event = new FooEvent();
+
+ try {
+ eventBus.fireEvent(event);
+ fail("eventBus should have thrown");
+ } catch (UmbrellaException e) {
+ Set<Throwable> causes = e.getCauses();
+ assertEquals("Exception should wrap the two thrown exceptions", 2, causes.size());
+ assertTrue("First exception should be under the umbrella", causes.contains(exception1));
+ assertTrue("Second exception should be under the umbrella", causes.contains(exception2));
+ }
+
+ /*
+ * Exception should not have prevented all three mouse handlers from getting
+ * the event.
+ */
+ assertFired(fooHandler1, fooHandler2, fooHandler3);
+ }
+
+ public void testNoDoubleRemove() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+ HandlerRegistration reg = FooEvent.register(eventBus, fooHandler1);
+ reg.removeHandler();
+
+ boolean assertsOn = getClass().desiredAssertionStatus();
+
+ if (assertsOn) {
+ try {
+ reg.removeHandler();
+ fail("Should have thrown on remove");
+ } catch (AssertionError e) { /* pass */
+ }
+ } else {
+ reg.removeHandler();
+ // Succeed on no assert failure
+ }
+ }
+
+ public void testNoSource() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+
+ SourcedHandler global = new SourcedHandler(null);
+ SourcedHandler able = new SourcedHandler("able");
+ SourcedHandler baker = new SourcedHandler("baker");
+
+ FooEvent.register(eventBus, global);
+ FooEvent.register(eventBus, "able", able);
+ FooEvent.register(eventBus, "baker", baker);
+
+ eventBus.fireEvent(new FooEvent());
+ assertFired(global);
+ assertNotFired(able, baker);
+ }
+
+ public void testNullChecks() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+ assertThrowsNpe(new Command() {
+ public void execute() {
+ eventBus.addHandler(null, fooHandler1);
+ }
+ });
+
+ assertThrowsNpe(new Command() {
+ public void execute() {
+ FooEvent.register(eventBus, "foo", null);
+ }
+ });
+ assertThrowsNpe(new Command() {
+ public void execute() {
+ FooEvent.register(eventBus, null, fooHandler1);
+ }
+ });
+ assertThrowsNpe(new Command() {
+ public void execute() {
+ eventBus.addHandlerToSource(null, "foo", fooHandler1);
+ }
+ });
+
+ assertThrowsNpe(new Command() {
+ public void execute() {
+ eventBus.fireEvent(null);
+ }
+ });
+
+ assertThrowsNpe(new Command() {
+ public void execute() {
+ eventBus.fireEventFromSource(null, "");
+ }
+ });
+
+ assertThrowsNpe(new Command() {
+ public void execute() {
+ eventBus.fireEventFromSource(new FooEvent() {
+ }, null);
+ }
+ });
+ assertThrowsNpe(new Command() {
+ public void execute() {
+ eventBus.fireEventFromSource(null, "baker");
+ }
+ });
+ }
+
+ public void testNullSourceOkay() {
+ SimpleEventBus reg = new SimpleEventBus();
+
+ FooEvent.Handler handler = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ add(this);
+ assertNull(event.getSource());
+ }
+ };
+ reg.addHandler(FooEvent.TYPE, handler);
+ reg.fireEvent(new FooEvent());
+ assertFired(handler);
+ }
+
+ public void testRemoveSelf() {
+ final SimpleEventBus eventBus = new SimpleEventBus();
+
+ FooEvent.Handler h = new FooEvent.Handler() {
+ HandlerRegistration reg = FooEvent.register(eventBus, this);
+
+ public void onFoo(FooEvent event) {
+ add(this);
+ reg.removeHandler();
+ }
+ };
+
+ eventBus.fireEvent(new FooEvent());
+ assertFired(h);
+
+ reset();
+
+ eventBus.fireEvent(new FooEvent());
+ assertNotFired(h);
+ }
+
+ public void testReverseOrder() {
+ @SuppressWarnings("deprecation")
+ final SimpleEventBus eventBus = new SimpleEventBus(true);
+ final FooEvent.Handler handler0 = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ add(this);
+ }
+ };
+ final FooEvent.Handler handler1 = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ assertNotFired(handler0);
+ add(this);
+ }
+ };
+ final FooEvent.Handler handler2 = new FooEvent.Handler() {
+ public void onFoo(FooEvent event) {
+ assertNotFired(handler0, handler1);
+ add(this);
+ }
+ };
+ FooEvent.register(eventBus, handler0);
+ FooEvent.register(eventBus, handler1);
+ FooEvent.register(eventBus, handler2);
+
+ reset();
+ eventBus.fireEvent(new FooEvent());
+ assertFired(handler0, handler1, handler2);
+ }
+
+ private void assertThrowsNpe(Command command) {
+ try {
+ command.execute();
+ fail("expected NullPointerException");
+ } catch (NullPointerException e) {
+ /* pass */
+ }
+ }
+}
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/FindServiceTest.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/FindServiceTest.java
index de1aab9..ca82e36 100644
--- a/user/test/com/google/web/bindery/requestfactory/gwt/client/FindServiceTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/FindServiceTest.java
@@ -15,7 +15,7 @@
*/
package com.google.web.bindery.requestfactory.gwt.client;
-import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.web.bindery.event.shared.HandlerRegistration;
import com.google.web.bindery.requestfactory.shared.EntityProxyChange;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.Receiver;
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryExceptionPropagationTest.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryExceptionPropagationTest.java
index 45cf3d8..48482c7 100644
--- a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryExceptionPropagationTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryExceptionPropagationTest.java
@@ -16,7 +16,7 @@
package com.google.web.bindery.requestfactory.gwt.client;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.UmbrellaException;
+import com.google.web.bindery.event.shared.UmbrellaException;
import com.google.web.bindery.requestfactory.shared.Receiver;
import com.google.web.bindery.requestfactory.shared.RequestContext;
import com.google.web.bindery.requestfactory.shared.ServerFailure;
@@ -302,7 +302,7 @@
}
@Override
- protected void gwtTearDown() throws Exception {
+ protected void gwtTearDown() {
GWT.setUncaughtExceptionHandler(defaultUncaughtExceptionHandler);
}
}
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryPolymorphicTest.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryPolymorphicTest.java
index 1e0fa52..83baef3 100644
--- a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryPolymorphicTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryPolymorphicTest.java
@@ -16,9 +16,9 @@
package com.google.web.bindery.requestfactory.gwt.client;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.junit.client.GWTTestCase;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.SimpleEventBus;
import com.google.web.bindery.requestfactory.shared.SimpleFooProxy;
import com.google.web.bindery.requestfactory.shared.TestRequestFactory;
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTestBase.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTestBase.java
index 02a347b..cac062b 100644
--- a/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTestBase.java
+++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/RequestFactoryTestBase.java
@@ -15,12 +15,12 @@
*/
package com.google.web.bindery.requestfactory.gwt.client;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.junit.client.GWTTestCase;
import com.google.web.bindery.autobean.shared.AutoBean;
import com.google.web.bindery.autobean.shared.AutoBeanUtils;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.SimpleEventBus;
-import com.google.gwt.junit.client.GWTTestCase;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.SimpleEventBus;
import com.google.web.bindery.requestfactory.shared.BaseProxy;
import com.google.web.bindery.requestfactory.shared.DefaultProxyStore;
import com.google.web.bindery.requestfactory.shared.EntityProxy;
diff --git a/user/test/com/google/web/bindery/requestfactory/gwt/client/SimpleRequestFactoryInstance.java b/user/test/com/google/web/bindery/requestfactory/gwt/client/SimpleRequestFactoryInstance.java
index daaf415..da4c61e 100644
--- a/user/test/com/google/web/bindery/requestfactory/gwt/client/SimpleRequestFactoryInstance.java
+++ b/user/test/com/google/web/bindery/requestfactory/gwt/client/SimpleRequestFactoryInstance.java
@@ -16,7 +16,7 @@
package com.google.web.bindery.requestfactory.gwt.client;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.SimpleEventBus;
+import com.google.web.bindery.event.shared.SimpleEventBus;
import com.google.web.bindery.requestfactory.shared.SimpleRequestFactory;
/**
diff --git a/user/test/com/google/web/bindery/requestfactory/server/BoxesAndPrimitivesJreTest.java b/user/test/com/google/web/bindery/requestfactory/server/BoxesAndPrimitivesJreTest.java
index 74e26a4..c38d6c5 100644
--- a/user/test/com/google/web/bindery/requestfactory/server/BoxesAndPrimitivesJreTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/server/BoxesAndPrimitivesJreTest.java
@@ -113,7 +113,7 @@
}
@Override
- protected void gwtSetUp() throws Exception {
+ protected void gwtSetUp() {
super.gwtSetUp();
errors = new VisibleErrorContext(Logger.getAnonymousLogger());
v = new RequestFactoryInterfaceValidator(errors,
diff --git a/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryJreTest.java b/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryJreTest.java
index dbe0645..d17b608 100644
--- a/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryJreTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/server/RequestFactoryJreTest.java
@@ -15,8 +15,8 @@
*/
package com.google.web.bindery.requestfactory.server;
-import com.google.gwt.event.shared.EventBus;
-import com.google.gwt.event.shared.SimpleEventBus;
+import com.google.web.bindery.event.shared.EventBus;
+import com.google.web.bindery.event.shared.SimpleEventBus;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryTest;
import com.google.web.bindery.requestfactory.server.testing.InProcessRequestTransport;
import com.google.web.bindery.requestfactory.shared.RequestFactory;
diff --git a/user/test/com/google/web/bindery/requestfactory/shared/BoxesAndPrimitivesTest.java b/user/test/com/google/web/bindery/requestfactory/shared/BoxesAndPrimitivesTest.java
index 2d3fde4..87f962e 100644
--- a/user/test/com/google/web/bindery/requestfactory/shared/BoxesAndPrimitivesTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/shared/BoxesAndPrimitivesTest.java
@@ -16,8 +16,8 @@
package com.google.web.bindery.requestfactory.shared;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.junit.client.GWTTestCase;
+import com.google.web.bindery.event.shared.SimpleEventBus;
/**
* Contains a set of checks of how primitive and boxed method declarations
@@ -224,7 +224,7 @@
}
@Override
- protected void gwtSetUp() throws Exception {
+ protected void gwtSetUp() {
factory = createFactory();
}
diff --git a/user/test/com/google/web/bindery/requestfactory/shared/ComplexKeysTest.java b/user/test/com/google/web/bindery/requestfactory/shared/ComplexKeysTest.java
index 7184cd9..8c43a16 100644
--- a/user/test/com/google/web/bindery/requestfactory/shared/ComplexKeysTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/shared/ComplexKeysTest.java
@@ -16,8 +16,8 @@
package com.google.web.bindery.requestfactory.shared;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.junit.client.GWTTestCase;
+import com.google.web.bindery.event.shared.SimpleEventBus;
/**
* Tests the use of non-trivial EntityProxy and ValueProxy key types.
@@ -213,7 +213,7 @@
}
@Override
- protected void gwtSetUp() throws Exception {
+ protected void gwtSetUp() {
factory = createFactory();
}
diff --git a/user/test/com/google/web/bindery/requestfactory/shared/LocatorTest.java b/user/test/com/google/web/bindery/requestfactory/shared/LocatorTest.java
index 14376bd..632ffb7 100644
--- a/user/test/com/google/web/bindery/requestfactory/shared/LocatorTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/shared/LocatorTest.java
@@ -16,8 +16,8 @@
package com.google.web.bindery.requestfactory.shared;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.junit.client.GWTTestCase;
+import com.google.web.bindery.event.shared.SimpleEventBus;
/**
* Tests the use of Locator objects.
@@ -120,7 +120,7 @@
}
@Override
- protected void gwtSetUp() throws Exception {
+ protected void gwtSetUp() {
factory = createFactory();
}
diff --git a/user/test/com/google/web/bindery/requestfactory/shared/ServiceInheritanceTest.java b/user/test/com/google/web/bindery/requestfactory/shared/ServiceInheritanceTest.java
index f4df2e6..ee604b9 100644
--- a/user/test/com/google/web/bindery/requestfactory/shared/ServiceInheritanceTest.java
+++ b/user/test/com/google/web/bindery/requestfactory/shared/ServiceInheritanceTest.java
@@ -16,8 +16,8 @@
package com.google.web.bindery.requestfactory.shared;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.junit.client.GWTTestCase;
+import com.google.web.bindery.event.shared.SimpleEventBus;
/**
* Tests the ability of instance services to inherit methods