I have totally restructured my app to follow the "page setup by event"
type idea that you've suggested in your email. I have been through all
four samples in the samples repo but can't answer my own question.
I have set up based on the "nested sample" but now I have a
HeaderPresenter like you have in your email, present on all pages,
Home, AboutUs, ContactUs. So essentially it's a singleton and will
never be removed/replaced.
Ok, now I see how you have this idea in your "leaf" presenters:
@Override
protected void revealInParent() {
RevealContentEvent.fire(eventBus, MainPresenter.TYPE_SetMainContent,
this);
}
... but now, what about the Header? I can't get it to be injected or
revealed. I'm not sure what the correct way is (maintaining loose
coupling). Currently I have:
@Override
protected void revealInParent() {
RevealContentEvent.fire(eventBus,
MainPresenter.TYPE_SetHeaderContent, this);
}
... in my HeaderPresenter, and then in my MainPagePresenter I have:
@ContentSlot
public static final Type<RevealContentHandler<?>> TYPE_SetMainContent
=
new Type<RevealContentHandler<?>>();
@ContentSlot
public static final Type<RevealContentHandler<?>>
TYPE_SetHeaderContent =
new Type<RevealContentHandler<?>>();
... and then in my MainPageView:
@Override
public void setContent(Object slot, Widget content) {
if (slot == MainPresenter.TYPE_SetMainContent) {
setMainContent(content);
} else if (slot == MainPresenter.TYPE_SetHeaderContent) {
setHeaderContent(content);
} else {
super.setContent(slot, content);
}
}
private void setHeaderContent(Widget content) {
mainHeaderPanel.clear();
if (content != null)
mainHeaderPanel.add(content);
}
private void setMainContent(Widget content) {
mainContentPanel.clear();
if (content != null)
mainContentPanel.add(content);
> > > > > > > > implements, so the coupling is loose but...
>
> read more »