Question

I'm new to GWT, and I've been reviewing the MVP implementation which uses the rpcService and the eventBus. I was wondering how a tab panel can be implemented such that each tab has its own sub-view. I have been waffling between making a custom widget that derives from a panel, or to figuring out how to make a presenter use another presenter, or to make a compound presenter class which handles it all for me.

Does anyone have advice on how to separate the functionality for each tab as opposed to keeping the implementation within one view/presenter pair?

Was it helpful?

Solution 2

I solved this without faking a main tab, but using the one provided with GWT's basic SDK. I did this by:

  1. Add an ArrayList of Presenters to the MainTabPresenter
  2. Constructed each tab's present plus view within the 'go' method of the MainTabPresenter
  3. Called 'go(null)' on each of the tab presenters.
  4. Handled the null situation on each.
  5. Implemented a method in the MainTabView to add the tabs to the DecoratedTabPanel

It all works like a charm. The MainTabPresenter so very thin, and allows for complete implementations of View/Presenters to be written into their own files.

OTHER TIPS

I was in the same situation, but decided to change my implementation to simulate a TabPanel. If your views and presenters don't need to interact with each other (e.g. dragging something from one tab to another) then I think it'll be easier to separate functionality by loading your View into a shared SimplePanel. You can simulate the tabbed portion of the TabPanel with a widget that listens for PlaceChangeEvents (to change the highlighted tab) and sends goTo commands to the PlaceController your app is using (to handle clicks on the different headers).

It took a couple of hours to implement this, and the resulting code is much cleaner. My initial attempt involved listening for PlaceChangeEvents and then calling the appropriate tabPanel.selectTab() function, but trying to figure out how to start and stop the presenters for the different tabs was too jumbled up - like you suggest, you'd have to implement your own compound view model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top