ProxyEvent and PopupView and PresenterWidget

101 views
Skip to first unread message

Danilo Reinert

unread,
Jun 5, 2013, 10:23:09 PM6/5/13
to gwt-pl...@googlegroups.com
I've seen one post covering this issue but I still need clear information on how to approach this problem.

My context: I have 1 PopupView shared by 2 PresenterWidget and I want my presenters to Handle the events responsible for showing using ProxyEvent feature.

Simply binding these PresenterWidget won't work because a PresenterWidget is not an Singleton. I've tried to unsuccesfully bind them as Singleton. Then i tried to manually bind them as EagerSingleton but it still didn't work.

It happens that these PresenterWidgets won't have only one parent, in fact, they can have multiple. So I can't just chose one parent to handle the showing events. Ideally, each PresenterWidget should handle your own show event as ProxyEvent.

It not being possible, I'm thinking in create a View-less Presenter (or something like that - https://groups.google.com/forum/?fromgroups#!searchin/gwt-platform/no$20view$20presenter/gwt-platform/9OzKrUnBhu4/bQoW7GyIIwMJ) to handle the events and add the presenterWidget to popupSlot when necessary.

What sould I do?

Danilo Reinert

unread,
Jun 6, 2013, 7:23:12 AM6/6/13
to gwt-pl...@googlegroups.com
After some code reading I got some conclusions, please correct if I'm wrong.

* PresenterWidgets doesn't have the ability to "wake up" because they are not places. 
* They need a parent place to exist and have to be injected into it.
* They can't be proxied for the same reason. That's why @ProxyPlace does not work on them.

So, in order to solve my problem, I would need to put an always visible hidden presenter at the root of my ApplicationPage, and make this Presenter the listener of all my showing events. Unfortunately, this solution doesn't follow the Open-Closed Principle.

Anxious for ideas.

--
D. Reinert

Jonas

unread,
Jun 10, 2013, 3:02:15 AM6/10/13
to gwt-pl...@googlegroups.com
If you have some sort of root presenter that handles the layout then the logic for listening to the events could be placed there. If that's not applicable, and you don't want to create an empty presenter, one approach could be to manually create a new class that you bind as eager singleton and that listens manually on the event bus for the events. This is basically how proxies work (bound as eager singleton) and why they can wake up presenters using proxy events.

Danilo Reinert

unread,
Jun 18, 2013, 3:02:34 PM6/18/13
to gwt-pl...@googlegroups.com
That's how I solved the problem:

Instead of putting the logic of handle the events in the root presenter, which would hurt the principle of Separation of Concerns, I let this logic inside the PresenterWidget.

But, How could I "wake up" the PresenterWidget inside himself?

Well, It happens that he is awaken at boot time, and in the construction he registers his self as the listener of his opening event. For showing him up, I injected the RootPresenter in the PresenterWidget and in the handling method I put himself into the PopupSlot.

In practice...

class MyPresenterWidget ... implements MyOpeningEvent {
  
  MyPresenterWidget(EventBus eventBus, ApplicationPresenter applicationPresenter) {
    ...
    eventBus.addHandler(MyOpeningEvent.TYPE, this);
  }

  public void onMyOpening() {
    ...
    applicationPresenter.addToPopupSlot(this);
  }

}

The insight was to bind the PresenterWidget as EagerSingleton.

It would be good to have some auto-generated proxy feature for PresenterWidgets. :)

--
D. Reinert
Reply all
Reply to author
Forward
0 new messages