I'm trying to learn both GWT-recommended MVP and their Activities & Places API (yes, I know they are two different things, but they seem play nicely into each other).
In a lot of code examples of Activities/Places, I keep seeing the following similar code in the AbstractActivity impls:
@Override
public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
view.setPresenter(this);
containerWidget.setWidget(view.asWidget());
}
I believe the first line (view.setPresenter(this);) is to create bi-directionality between the View and the Presenter. But I'm not sure what the 2nd line (containerWidget.setWidget(view.asWidget());) accomplishes. So, 2 questions:
- What is
containerWidget? Where does it come from? Is it what is attached to theRootPanel? In other words, what is the value of setting our View to it? - Why does the
AbstractActivity#start(...)method accept anEventBusarg? Is it required and/or typical to send/receive events to/from the bus from inside this method?

Activities are objects in charge of the interactions on a given part of the UI, in a given time. They are started/stopped by their relative
ActivityManagers in response of URL changes (i.e.,PlaceChangeEvents).An
ActivityManageris in charge of a given area of the UI, a display (of course, if you have multiple managers; the whole UI - thebody- in the other case). Such managers internally hold a reference to theAcceptsOneWidgetthey own (the one you pass from a call toActivityManager.setDisplay()method), as well as anEventBusobject (the one you pass from anActivityManagerinstantiation).So...
containerWidgetis the display. It could be aRootLayoutPanel.get(), or a specific panel of the whole UI (must be anAcceptsOneWidgetone). You attach your view, to it.EventBusof thestart()method is aResettableEventBuswrapper of the original one holded by theActivityManager. This way, when the activity is stopped, any handler attached to such bus, will be automatically de-registered. You generally want to rely on this bus, rather than using the global one.