2012-06-15 68 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()。