【问题标题】:In GWTP how can TabLayoutPanel events be handled?在 GWTP 中如何处理 TabLayoutPanel 事件?
【发布时间】:2012-06-20 22:36:54
【问题描述】:

我已经学习了 Dani 的 GWTP 课程,但未涵盖将 TabLayoutPanel 与演示者一起使用。

我有一个带有 3 个选项卡的 TabLayoutPanel(每个选项卡上都有一个 VerticalPanel)。我使用了@ProxyCodeSplit,以便独立加载每个选项卡的代码。

如果在 Eclipse 中,在 GWT 的设计器中,我为 OnBeforeSelection 添加了一个处理程序,那么代码会自动添加到我的视图中。然后视图可以加载适当的演示者。

感觉这不是代码的正确位置 - 但它是吗?

您如何在 TabLayoutPanel 和代码拆分中处理不同的选项卡?

【问题讨论】:

    标签: gwt gwtp


    【解决方案1】:

    我想我已经弄清楚了。

    在带有 TabLayoutPanel 的演示者中(我们称之为 MainPresenter):

    @ContentSlot public static final Type<RevealContentHandler<?>> SLOT_first = new Type<RevealContentHandler<?>>();
    @ContentSlot public static final Type<RevealContentHandler<?>> SLOT_second = new Type<RevealContentHandler<?>>();
    
    public interface MyView extends View {
        public void setMainPresenter(MainPresenter presenter);
        public TabLayoutPanel getTeamsPanel();
    }
    
    @Inject PlaceManager placeMananger;
    @Inject FirstPresenter firstPresenter;
    @Inject SecondPresenter secondPresenter;
    
    @ProxyCodeSplit
    public interface MyProxy extends Proxy<MainPresenter> {
    }
    
    @Inject
    public MainPresenter(final EventBus eventBus, final MyView view,
            final MyProxy proxy) {
        super(eventBus, view, proxy);
        view.setMainPresenter(this);
    }
    
    @Override
    protected void revealInParent() {
        RevealRootContentEvent.fire(this, this);
    }
    
    public void setTabContents(Integer tab) {
        if (tab == 0) {
            placeMananger.revealPlace(new PlaceRequest("first"));
        } else if (tab == 1) {
            placeMananger.revealPlace(new PlaceRequest("second"));
    }
    

    然后在您的 MainView 中实现方法 setMainPresenter() 以在本地存储引用。实现通常的 setInSlot(),然后添加这个选项卡处理程序:

    @UiHandler("mainTabs")
    void onMainTabsBeforeSelection(BeforeSelectionEvent<Integer> event) {
        mainPresenter.setTabContents(event.getItem());
    }
    

    每次用户更改选项卡时,处理程序都会调用 MainPresenter。 setTabContents() 将为适当的“选项卡”Presenter 调用revealInParent()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      • 2021-02-19
      • 2023-03-19
      • 2010-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多