Revision: 10214
Author: [email protected]
Date: Tue May 24 11:10:36 2011
Log: Public ([email protected]):
Adds two protected static methods to EventBus that expose otherwise
inaccessible methods on Event (setSource and dispatch) to subclasses
of EventBus. Allows alternative EventBus implementations without
muddying the public API events show to handlers.
Tweaks the original patch (1443804) by making SimpleEventBus use the
new methods, and updating javadoc and a method name.
Review at http://gwt-code-reviews.appspot.com/1450802
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=10214
Modified:
/trunk/user/src/com/google/web/bindery/event/shared/Event.java
/trunk/user/src/com/google/web/bindery/event/shared/EventBus.java
/trunk/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java
=======================================
--- /trunk/user/src/com/google/web/bindery/event/shared/Event.java Mon Apr
18 16:25:25 2011
+++ /trunk/user/src/com/google/web/bindery/event/shared/Event.java Tue May
24 11:10:36 2011
@@ -106,9 +106,10 @@
/**
* 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)}.
+ * {@link EventBus#fireEventFromSource(Event, Object)}.
*
* @param handler handler
+ * @see EventBus#dispatchEvent(Event, Object)
*/
protected abstract void dispatch(H handler);
@@ -118,6 +119,7 @@
*
* @param source the source of this event.
* @see EventBus#fireEventFromSource(Event, Object)
+ * @see EventBus#setSourceOfEvent(Event, Object)
*/
protected void setSource(Object source) {
this.source = source;
=======================================
--- /trunk/user/src/com/google/web/bindery/event/shared/EventBus.java Mon
Apr 18 16:25:25 2011
+++ /trunk/user/src/com/google/web/bindery/event/shared/EventBus.java Tue
May 24 11:10:36 2011
@@ -29,6 +29,26 @@
* @see com.google.web.bindery.event.shared.testing.CountingEventBus
*/
public abstract class EventBus {
+
+ /**
+ * Invokes {@code event.dispatch} with {@code handler}.
+ * <p>
+ * Protected to allow EventBus implementations in different packages to
+ * dispatch events even though the {@code event.dispatch} method is
protected.
+ */
+ protected static <H> void dispatchEvent(Event<H> event, H handler) {
+ event.dispatch(handler);
+ }
+
+ /**
+ * Sets {@code source} as the source of {@code event}.
+ * <p>
+ * Protected to allow EventBus implementations in different packages to
set an
+ * event source even though the {@code event.setSource} method is
protected.
+ */
+ protected static void setSourceOfEvent(Event<?> event, Object source) {
+ event.setSource(source);
+ }
/**
* Adds an unfiltered handler to receive events of this type from all
sources.
@@ -70,7 +90,7 @@
* from executing.
*
* @throws UmbrellaException wrapping exceptions thrown by handlers
- *
+ *
* @param event the event to fire
*/
public abstract void fireEvent(Event<?> event);
=======================================
--- /trunk/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java
Mon Apr 18 16:25:25 2011
+++ /trunk/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java
Tue May 24 11:10:36 2011
@@ -178,7 +178,7 @@
firingDepth++;
if (source != null) {
- event.setSource(source);
+ setSourceOfEvent(event, source);
}
List<H> handlers = getDispatchList(event.getAssociatedType(),
source);
@@ -190,7 +190,7 @@
H handler = isReverseOrder ? it.previous() : it.next();
try {
- event.dispatch(handler);
+ dispatchEvent(event, handler);
} catch (Throwable e) {
if (causes == null) {
causes = new HashSet<Throwable>();
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors