Added a getter for the ResettableEventBus object. Review at http://gwt-code-reviews.appspot.com/1569803 Review by: rjrjr@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10699 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/activity/shared/ActivityManager.java b/user/src/com/google/gwt/activity/shared/ActivityManager.java index c961357..1fcf681 100644 --- a/user/src/com/google/gwt/activity/shared/ActivityManager.java +++ b/user/src/com/google/gwt/activity/shared/ActivityManager.java
@@ -91,6 +91,18 @@ } /** + * Returns an event bus which is in use by the currently running activity. + * <p> + * Any handlers attached to the returned event bus will be de-registered when + * the current activity is stopped. + * + * @return the event bus used by the current activity + */ + public EventBus getActiveEventBus() { + return stopperedEventBus; + } + + /** * Deactivate the current activity, find the next one from our ActivityMapper, * and start it. * <p>
diff --git a/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java b/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java index 62a4af8..bdb969f 100644 --- a/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java +++ b/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
@@ -138,6 +138,37 @@ private ActivityManager manager = new ActivityManager( myMap, eventBus); + + public void testActiveEventBus() { + final AsyncActivity asyncActivity1 = new AsyncActivity(new MyView()); + final AsyncActivity asyncActivity2 = new AsyncActivity(new MyView()); + + ActivityMapper map = new ActivityMapper() { + public Activity getActivity(Place place) { + if (place.equals(place1)) { + return asyncActivity1; + } + if (place.equals(place2)) { + return asyncActivity2; + } + + return null; + } + }; + + manager = new ActivityManager(map, eventBus); + manager.setDisplay(realDisplay); + + eventBus.fireEvent(new PlaceChangeEvent(place1)); + com.google.gwt.event.shared.EventBus activeEventBus = + manager.getActiveEventBus(); + + activeEventBus.addHandler(Event.TYPE, new Handler()); + assertEquals(1, eventBus.getCount(Event.TYPE)); + + eventBus.fireEvent(new PlaceChangeEvent(place2)); + assertEquals(0, eventBus.getCount(Event.TYPE)); + } public void testAsyncDispatch() { final AsyncActivity asyncActivity1 = new AsyncActivity(new MyView());