Nested presenters with GWTP
Asked Answered
H

2

11

I have content slots in my mainpresenter, how can i put, when app load, put the home presenter in one slot and the menu slot in the another ?

or isn't possible?

thanks in advance.

Hildick answered 28/9, 2011 at 3:57 Comment(0)
L
16

Yes you can ! In the following example code, I assume that your HomePresenter is a place and extends Presenter, and your MenuPresenter extends PresenterWidget.
In your MainPresenter :

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

@Override
protected void onReveal() {
    super.onReveal();
    setInSlot(MENU_SLOT, menuPresenter);
}

In your HomePresenter :

@Override
protected void revealInParent() {
    RevealContentEvent.fire(this, MainPresenter.MAIN_SLOT, this);
}

Then in MainView :

@UiField Panel mainContainer;
@UiField Panel menuContainer;

@Override
public void setInSlot(Object slot, Widget content) {
    if (slot == MainPresenter.MAIN_SLOT) {
        mainContainer.clear();
        mainContainer.add(content);
    } else if (slot == MainPresenter.MENU_SLOT) {
        menuContainer.clear();
        menuContainer.add(content);
    } else {
        super.setInSlot(slot, content);
    }
}
Laurinelaurita answered 28/9, 2011 at 7:21 Comment(3)
@Mikael, your answer really helps. But I have a question. Here what you do is add-remove-add-remove.. content(Widget) to mainContainer(Panel). Isn't this an overhead? Can't we do something like hide-show of content(Widget)?Luben
@Luben Actually, I don't see how to do it in any other way. The setInSlot() method has to do with the composition of a UI with separate presenters, so at some point you will have to inject a widget in a panel. Also, clearing a panel doesn't mean that the contained widget is discarded, it can be re-injected later.Laurinelaurita
@MikaelCouzic, thanks for your reply. I understood your point.Luben
S
1

For users of GWTP 1.5+, note that a lot of new changes have been introduced to slots, and revealing presenters. The case in question may now be accomplished using a NestedSlot for the page content and a PermanentSlot for a menu that you want displayed on all of your pages.

Fortunately, these changes are well documented. See the GWTP slot documentation for an explanation on the new slot types with examples on how to use them.

Shimberg answered 25/2, 2016 at 20:49 Comment(1)
Reading through the documentation now for two days but I still can't answer this rather simple question ^^Garcon

© 2022 - 2024 — McMap. All rights reserved.