0

我有以下课程:

// 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();
    }
}
  1. 显然,我没有正确实现DashboardActivityMapperDashboardActivity所以当我尝试在MyWebAppModule#onModuleLoad. 有人可以帮我正确实施吗?一旦我得到一个工作示例,我确信我将能够连接活动框架中的其余“点”。
  2. 除非我遗漏了什么,否则ActivityManager manager上述内容似乎没有添加到任何其他类中。这个对吗?GWT 会确保它在内存中保持活动状态,以便它始终在监听eventBusI pass it for PlaceChangeEvents 吗?还是我需要将它添加/注册到任何东西?

提前致谢!

4

1 回答 1

0
  1. DashboardActivityMapper负责在到达DashboardActivity给定位置(例如HomePlace)时创建和返回 a 。这是您缺少的信息吗?
    请参阅https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces#ActivityMapper

  2. 只要EventBus有一个句柄ActivityManager(所以它可以向它发送事件)。但是,在使用非空值调用时在其方法中ActivityManager注册自身(并在将 a传递给时取消注册自身),并且您不调用(顺便说一下,甚至不会显示活动)EventBussetDisplaynullsetDisplaysetDisplay

于 2012-11-08T15:06:16.160 回答