我有以下课程:
// The "backing bean" for DashboardDisplay.ui.xml (which is omitted for brevity).
public class DashboardDisplay extends Composite implements AcceptsOneWidget {
private EventBus eventBus;
private PlaceController placeController;
private IsWidget content = null;
public DashboardDisplay(EventBus eventBus, PlaceController placeController) {
super();
setEventBus(eventBus);
setPlaceController(placeController);
}
// Getters and setters for all properties
// ...
@Override
public void setWidget(IsWidget widget) {
setContent(widget);
}
}
public class DashboardActivity extends AbstractActivity {
private AcceptsOneWidget container;
private ActivityManager manager;
private DashboardDisplay display;
public DashboardActivity(AcceptsOneWidget container, ActivityManager manager,
DashboardDisplay display) {
super();
setContainer(container);
setManager(manager);
setDisplay(display);
// I *believe* this ensures that the 'panel' passed in to the
// start method is always our 'container'. Yes?
manager.setDisplay(container);
}
// Getters and setters for all properties
// ...
@Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
display.setEventBus(eventBus);
panel.setWidget(display);
}
}
public class DashboardActivityMapper implements ActivityMapper {
private DashboardActivity activity = null;
// Getters and setter for activity.
@Override
public Activity getActivity(Place place) {
// Leaving arguments null because I'm confused about the object graph
// (read below).
return new DashboardActivity(null, null, null);
}
}
所以我开始对活动框架有一些表面上的理解,但对它仍然很陌生,以至于当我尝试远离Hello、GWT示例时,我几乎立刻就遇到了 API 的障碍。
在我的应用程序的主 GWT 模块中MyWebAppModule
,我正在尝试实例化和配置这 3 个对象。但是因为我仍然不确定如何使用他们的 API,所以我遇到了实现问题:
public class MyWebAppModule implements EntryPoint {
@Override
public void onModuleLoad() {
// I'll worry about DI and getting GIN to work after
// I figure this basic stuff out.
EventBus eventBus = new SimpleEventBus();
PlaceController placeController = new PlaceController(eventBus);
MyWebAppPlaceHistoryMapper placeMapper = new MyWebAppPlaceHistoryMapper();
HomePlace homePlace = new HomePlace();
// WHERE THE PROBLEM STARTS
DashboardActivityMapper activityMapper = new DashboardActivityMapper();
ActivityManager manager = new ActivityManager(activityMapper, eventBus);
// Really not sure how to inject/configure this properly.
DashboardActivity dashboardActivity = new DashboardActivity(null, null, null);
// WHERE THE PROBLEM ENDS
PlaceHistoryHandler historian = new PlaceHistoryHandler(placeMapper);
historian.register(placeController, eventBus, homePlace);
historian.handleCurrentHistory();
}
}
- 显然,我没有正确实现
DashboardActivityMapper
,DashboardActivity
所以当我尝试在MyWebAppModule#onModuleLoad
. 有人可以帮我正确实施吗?一旦我得到一个工作示例,我确信我将能够连接活动框架中的其余“点”。 - 除非我遗漏了什么,否则
ActivityManager manager
上述内容似乎没有添加到任何其他类中。这个对吗?GWT 会确保它在内存中保持活动状态,以便它始终在监听eventBus
I pass it forPlaceChangeEvent
s 吗?还是我需要将它添加/注册到任何东西?
提前致谢!