2012-06-15 100 views
0

我已经关注了Dani的GWTP课程,但是使用带演示者的TabLayoutPanel并未涉及。在GWTP中,如何处理TabLayoutPanel事件?

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

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

这不像代码的正确位置 - 但它是什么?

你是如何在TabLayoutPanel和代码拆分内交付不同的选项卡?

回答

0

我想我已经弄明白了。

在与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()将为相应的“选项卡”演示者调用revealInParent()。