Ralph
Ralph

Reputation: 161

GWTP using double nesting

I'm trying to use double nesting in GWTP. The SimpleNestedSample does only 1 level. I want to have (at least) 2 levels. However, my lowest-level presenter never gets revealed (or even instantiated). In the ClientGinjectorBase.java I have the following:

public interface ClientGinjectorBase extends Ginjector
{
  EventBus getEventBus();
  PlaceManager getPlaceManager();
  Provider<MainPresenter> getMainPresenter();
  AsyncProvider<DesktopPresenter> getDesktopPresenter();
  AsyncProvider<WebshopAppPresenter> getWebshopAppPresenter();
}

In my ClientModule.java I have the following:

public class ClientModule extends AbstractPresenterModule
{
  @Override
  public void configure()
  {
    install(new DefaultModule(DesktopPlaceManager.class));
    bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.desktopPage);

    bindPresenter(
      MainPresenter.class,
      MainPresenter.MyView.class,
      MainView.class, MainPresenter.MyProxy.class);

    bindPresenter(
      DesktopPresenter.class,
      DesktopPresenter.MyView.class,
      DesktopView.class, DesktopPresenter.MyProxy.class);

    bindPresenter(
      WebshopAppPresenter.class,
      WebshopAppPresenter.MyView.class,
      WebshopAppView.class, WebshopAppPresenter.MyProxy.class);
  }
}

Perhaps there is something obvious going wrong but I would appreciate some tips.

Thanks!!

Upvotes: 0

Views: 645

Answers (1)

Sydney
Sydney

Reputation: 12222

The code you posted is not relevant to answer your question. Let's say you have 4 presenters:

  • MainPresenter
  • HeaderPresenter
  • NavigationPresenter
  • Home Presenter

The MainPresenter will contain the 3 other presenters. When a place is revealed (home), an event is fired.

HomePresenter code:

@Override
protected void revealInParent() {
    // trigger the setInSlot of MainPageView
    RevealContentEvent.fire(this, MainPagePresenter.TYPE_SetMainContent,
            this);
}

Then this event is handled by setInSlot of MainPageView which adds the content to one of the slot. That's why MainPresenter should have 3 slots with following code:

@ContentSlot
public static final Type<RevealContentHandler< ? >> TYPE_SetMainContent = new Type<RevealContentHandler< ? >>();

@ContentSlot
public static final Type<RevealContentHandler< ? >> TYPE_SetHeaderContent = new Type<RevealContentHandler< ? >>();

@ContentSlot
public static final Type<RevealContentHandler< ? >> TYPE_SetNavigationContent = new Type<RevealContentHandler< ? >>();

private boolean headerNavigationDisplayed = false;

@Inject
public MainPagePresenter(final EventBus eventBus, final MyView view,
        final MyProxy proxy) {
    super(eventBus, view, proxy);
}

@Override
protected void revealInParent() {
    // trigger setInSlot in the RootView
    RevealRootContentEvent.fire(this, this);
}

@Override
protected void onReveal() {
    super.onReveal();
    if (!headerNavigationDisplayed) {
        // Fire this event to force reveal the header and navigation
        // presenters
        MainContentSetEvent.fire(this, "ThreePart");
        headerNavigationDisplayed = true;
    }
}

When the MainPagePresenter is revealed. It fires a custom event MainContentSetEvent. I have a parameter but it's not necessary for you. To handle this event the HeaderPresenter must implementstheMainContentSetHandler` interface. Put the following code:

@Override
protected void revealInParent() {
    RevealContentEvent.fire(this, MainPagePresenter.TYPE_SetHeaderContent,
            this);
}

@ProxyEvent
@Override
public void onMainContentSet(MainContentSetEvent event) {
    forceReveal();
}

Do the same for the NavigationPresenter. Put the following code:

@Override
protected void revealInParent() {
        RevealContentEvent.fire(this,
                MainPagePresenter.TYPE_SetNavigationContent, this);
}

@ProxyEvent
@Override
public void onMainContentSet(MainContentSetEvent event) {
    layout = event.getLayout();
    forceReveal();
}

On the view side, put the following code in MainPageView:

@Override
public void setInSlot(Object slot, Widget content) {
    if (slot == MainPagePresenter.TYPE_SetMainContent) {
        setMainContent(content);
    } else if (slot == MainPagePresenter.TYPE_SetHeaderContent) {
        setHeaderContent(content);
    } else if (slot == MainPagePresenter.TYPE_SetNavigationContent) {
        setNavigationContent(content);
    } else {
        super.setInSlot(slot, content);
    }
}

If you want to understand the whole mechanism, run in a debug mode, it's easier to understand the hierarchy of calls. I only put the relevant code, since you are aware of the SimpleNestetExample, you should be able to write the missing code.

Upvotes: 1

Related Questions