Frage

Hey so I am just learning the gwtp framework and I have come across a bit of a dilemma. I have a LayoutPresenter at the top level that has a main content slot and menu content slot and I am trying to find a way to bind my presenters for each slot together if possible so when the main content is revealed it will automatically show the correct side menu. Currently I have a static boolean in the Menu's Presenter that get updated onReveal and onHide. I can then check if the menu is visible when the main content is revealed and if not I reveal it.

    public class MenuPresenter extends Presenter<MenuPresenter.MyView, MenuPresenter.MyProxy> {

private static boolean hidden = true;
    ...
    @Override
protected void revealInParent() {
    RevealContentEvent.fire(this, LayoutPresenter.SIDE, this);
}

@Override
protected void onReveal(){
    super.onReveal();
    hidden = false;
}

@Override
protected void onHide(){
    super.onHide();
    hidden = true;
}

public static boolean isHidden(){
    return hidden;
}
    }

Then in The main content Presenter:

    public class ContentPresenter extends
    Presenter<ContentPresenter.MyView, ContentPresenter.MyProxy> {

...

private final DispatchAsync dispather;
private final PlaceManager placeManager;

@Inject
public PhoneCallPresenter(final EventBus eventBus, final MyView view, final MyProxy proxy, final DispatchAsync dispatcher, final PlaceManager placeManager) {
    super(eventBus, view, proxy);
    this.dispather = dispatcher;
    this.placeManager = placeManager;
}

@Override
protected void revealInParent() {
    RevealContentEvent.fire(this, LayoutPresenter.CONTENT, this);
}

@Override
protected void onReveal() {
    super.onReveal();
    if (MenuPresenter.isHidden()){
        placeManager.revealPlace(new PlaceRequest(NameTokens.menu));
    }
}

}

War es hilfreich?

Lösung

As far as I understood the question, you want to have different side-menus for different main contents.
In this case there are two solutions:

  1. Treat the menu as a normal Presenter (you will probably have multiple of them for each main content type). You just need to annotate the corresponding MenuPresenter with the same history token as your main content Presenter. So for the above example you would have a PhoneCallMenuPresenter that is annotated with the same history token as your PhoneCallPresenter. When you navigate to /phonecall (or whatever your history token is), both PhoneCallPresenter and PhoneCallMenuPresenter will be revealed automatically . (you don't have to do anything).
  2. In case you want to have only one MenuPresenter and put the logic what to display in the Presenter itself, I would recommend to use a PresenterWidget instead of a normal Presenter. The MenuPresenterWidget will be injected into the LayoutPresenter and will be added to the LayoutPresenter.SIDE slot. You can define a setter for the MenuPresenterWidget to specify which main content is currently displayed (the setter will be called from the LayoutPresenter or you can override the onReset() method and check the current place request and decide what to display in the menu.

For solution 1 you have to have one MenuPresenter for each main content Presenter and potentially many code lines will be redundant (you could create a base MenuPresenter and derive from it). So in case you have a lot of business logic in the side-menu which is quite different from main content to main content, I would go with solution 1. In case you only display different links the overhead of creating a MenuPresenter per main content Presenter might be to high and I would go with solution 2 and create only one MenuPresenterWidget for all main content types and always show it.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top