【问题标题】:Can somedy explain me the TAB SAMPLE (gwtp)?有人可以解释一下 TAB SAMPLE (gwtp) 吗?
【发布时间】:2012-06-22 02:18:00
【问题描述】:

我正在使用 GWTP。我做了嵌套演示者教程。但是没有关于 SAMPLE TAB 应用程序的教程(如果您切换到管理员模式,则会出现管理员选项卡)。有人可以解释一下这个应用程序的主要概念吗? Tkx。

【问题讨论】:

  • 至少你能做到吗?如果是,我需要你的帮助:P

标签: gwt-platform


【解决方案1】:

更新:更新:现在您可以从这里下载可行的示例 Maven 项目:gwtp-sample-tab.zip

我在我的项目中成功使用了选项卡式演示者功能(我发现示例代码也没有编译)。我认为首先是让它发挥作用,然后学习它并逐渐感受到它的好处:)

这是我做的步骤:

1) 复制以下文件

BaseTab.java
BaseTabPanel.java
SimpleTab.java
SimpleTabPanel.java
SimpleTab.ui.xml
SimpleTabPanel.ui.xml
UiModule.java

the sample code 到您的项目。比如我复制到这个包:com.widenhome.web.client.ui。另外请记得在 ClientGinjector 类中配置 UiModule。

2) 通过 GWTP eclipse 插件创建一个普通的演示者(MyPresenter)

3) 更改 EventBus 在 Presenter 中导入 this

import com.google.web.bindery.event.shared.EventBus;

4) 确保 MyPresenterView.ui.xml 具有以下代码或类似代码:

<g:HTMLPanel>
  <npui:SimpleTabPanel ui:field="tabPanel" />
  <g:SimplePanel ui:field="contentPanel" />
</g:HTMLPanel>

5) 将presenter改为扩展TabContainerPresenter而不是Presenter

public class MyPresenter extends
    TabContainerPresenter<MyPresenter.MyView, MyPresenter.MyProxy>

6) 在 MyPresenter 中定义多个变量,或者您可以复制/粘贴以下代码:

/**
 * This will be the event sent to our "unknown" child presenters, in order
 * for them to register their tabs.
 */
@RequestTabs
public static final Type<RequestTabsHandler> TYPE_RequestTabs = new Type<RequestTabsHandler>();

/**
 * Fired by child proxie's when their tab content is changed.
 */
@ChangeTab
public static final Type<ChangeTabHandler> TYPE_ChangeTab = new Type<ChangeTabHandler>();

/**
 * Use this in leaf presenters, inside their {@link #revealInParent} method.
 */
@ContentSlot
public static final Type<RevealContentHandler<?>> TYPE_SetTabContent = new Type<RevealContentHandler<?>>();

7) 更改 MyPresenter 的构造函数以使用变量:

@Inject
public MyPresenter(final EventBus eventBus, final MyView view, final MyProxy proxy) {
    super(eventBus, view, proxy, TYPE_SetTabContent, TYPE_RequestTabs, TYPE_ChangeTab);
}

8) 现在我们可以开始创建标签展示器了(例如 MyFirstTabPresenter)。只需通过 GWTP eclipse 插件再次创建一个普通的演示者

9) 在 MyFirstTabPresenter 中,更改 MyProxy 以使其“扩展” TabContentProxyPlace 而不是 ProxyPlace

10) 创建@TabInfo 方法,请参见@TabInfo 注解的javadoc,这里也可以使用其他方式。例如,我是这样做的:

@TabInfo(container = MyPresenter.class)
static TabData getTabLabel(ClientGinjector ginjector) {
    return new TabDataBasic("My First Tab", 0);
}

11) 在MyFirstTabPresenter 类的revealInParent() 方法中,请确保它有以下代码或类似代码:

@Override
protected void revealInParent() {
    RevealContentEvent.fire(this, MyPresenter.TYPE_SetTabContent, this);
}

这都与选项卡式演示者配置有关。现在您可以添加一些逻辑来加载一些数据以显示在 MyFirstPresenter 的视图中。

我希望这可以帮助您开始使用GWTP Tabbed Presenter,如果您有任何问题,请告诉我,我会逐步编辑并完善它,以便它可以帮助更多人开始使用它。

顺便说一句,我也将这个帖子发布到my blog 以帮助更多人。

谢谢,
家宽

【讨论】:

    【解决方案2】:

    它甚至没有编译。通过嵌套演示者触发多个演示者的唯一方法 - 这太复杂了。我用简单的 GWT History 机制构建了一个多演示者应用程序,没有任何痛苦。这个框架让 GWT History(目标机制)变得非常深奥。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      • 2016-12-12
      • 2011-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多