PeteGashek / puzzlebazar

Automatically exported from code.google.com/p/puzzlebazar
0 stars 0 forks source link

Provide a way to reset a presenter #73

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Sometimes I use a place that have nothing in it waiting for the user to 
choose a link in the menu to add something inside that presenter. 

There's a problem when we go back, we can't reset the parent to it's 
initial state (if needed)

Here's what I've done inside the proxy. Personnally I think a reset 
function has to be in the presenter itself.

    @Override
    public void onPresenterRevealed(Presenter presenter) {
        super.onPresenterRevealed(presenter);

        AppPresenter appPresenter = (AppPresenter) presenter;
        appPresenter.clearContent();
    }

Original issue reported on code.google.com by goudreau...@gmail.com on 21 Mar 2010 at 1:37

GoogleCodeExporter commented 9 years ago

Original comment by philippe.beaudoin on 21 Mar 2010 at 1:38

GoogleCodeExporter commented 9 years ago
Oh and I forgot my clear content method :

    public void clearContent() {
        view.clearContent();

        if (mainContentPresenter != null) 
            mainContentPresenter.notifyHide();

        mainContentPresenter = null;
    }

Original comment by goudreau...@gmail.com on 21 Mar 2010 at 1:52

GoogleCodeExporter commented 9 years ago

Original comment by philippe.beaudoin on 23 Mar 2010 at 5:23

GoogleCodeExporter commented 9 years ago

Original comment by philippe.beaudoin on 23 Mar 2010 at 5:28

GoogleCodeExporter commented 9 years ago

Original comment by philippe.beaudoin on 23 Mar 2010 at 5:29

GoogleCodeExporter commented 9 years ago
When doing this, consider cleaning ProxyPlaceAbstract#handleRequest() that does 
a nasty 
little trick to notify the PlaceManager when the presenter is already visible. 
I 
believe this was done to fix the following issue:

When in the #!main page, entering an invalid history token would bring us back 
to the 
main page, but the URL bar would still display the faulty URL.

I have to make sure this bug is not back after the fix.

Original comment by philippe.beaudoin on 25 Mar 2010 at 5:20

GoogleCodeExporter commented 9 years ago
The PresenterWidget#onReset() method can now be used for this. The way it 
(should) 
be called is the following:
- A new request to reveal a presenter is made (either by calling 
Presenter#reveal() 
or by changing the URL)
- Every presenter that needs to be revealed is. If the currently active page is 
being requested again, this means no presenter is revealed.
- After all the onHide and onReveal call are done, the 
PresenterWidget#onReset() 
method is called on every visible presenter, starting from the top-level 
presenter 
and going down to leaf-level presenters.

Original comment by philippe.beaudoin on 25 Mar 2010 at 11:03

GoogleCodeExporter commented 9 years ago
So, If I want to Hide leaf-level presenters. I would call onReset on my 
onReveal call 
from the top-level presenter and ask to remove my leaf-level presenter ?

Original comment by goudreau...@gmail.com on 25 Mar 2010 at 11:11

GoogleCodeExporter commented 9 years ago
Let's say you want to clear a slot within MyPresenter everytime a reset happens 
and 
this presenter is visible. The way to do this is:

public class MyPresenter {
 ...
   public void onReset() {
      super.onReset();
      clearContent( mySlot );
   }
}

However, thinking about it right now, this may raise an exception (because the 
list 
of children is being iterated over by the reset() method and you manipulate it 
with 
the clearContent() method... Yucky.) If you get an exception, a work around 
would be 
to replace the second line with a deferred command:

DeferredCommand.addCommand( new Command(){ @Override public void execute() { 
clearContent( mySlot ); } } );

Original comment by philippe.beaudoin on 25 Mar 2010 at 11:30

GoogleCodeExporter commented 9 years ago
Re-thinking about it, this _should_ work without a deferred command, as 
iterating 
through the children occurs after the call to onReveal(). 

Also, if you want to remove a single child presenter, this is not supported 
yet. It 
should be addressed with Issue 91.

Original comment by philippe.beaudoin on 25 Mar 2010 at 11:32

GoogleCodeExporter commented 9 years ago
BTW: Never call onReset yourself. It's called automatically for you.

Original comment by philippe.beaudoin on 25 Mar 2010 at 11:33

GoogleCodeExporter commented 9 years ago
Ok, I've tried to update my project with those change. And my default presenter 
isn't 
showing up anymore !

I'll probably have to change my AppPresenter to be more gwtp friendly, but I 
didn't 
figure out yet what to change.

My AppPresenter is a ProxyPlace that's added to rootpanel at init.

my reveal in parent is empty, since it's the root.
    @Override
    protected void revealInParent() {}

I've tried to do as you've done within pagepresenter. Without any success. Will 
I have 
to create a mainPage ? Place and get rid of the place in my app presenter ? 
What's is 
the good strategy to adopt ?

Original comment by goudreau...@gmail.com on 26 Mar 2010 at 2:22

GoogleCodeExporter commented 9 years ago
Views should no longer be added to the RootPanel manually at init time. This is 
because gwtp 
now offers a RootProxy that takes care of some GWT quirks when switching from 
using a 
RootPanel to using a RootLayoutPanel in the same app. This RootProxy is also 
the one taking 
care of the reset event, since it's the entry point to the top-level presenter. 
If you add 
your view to the RootPanel manually this will fail.

Instead of using the root panel, fire the RevealRootContentEvent, as such:
    RevealRootContentEvent.fire( eventBus, this );

Take a look at PagePresenter for an idea of the best practices for creating 
your top-level 
presenter.

Original comment by philippe.beaudoin on 26 Mar 2010 at 5:33

GoogleCodeExporter commented 9 years ago
I think that what I was missing is the binding in my Gin module :
RootProxy.class . asEagerSingleton()

Il try this in few minutes.

Original comment by goudreau...@gmail.com on 26 Mar 2010 at 5:41

GoogleCodeExporter commented 9 years ago
Moved to GWTP:
http://code.google.com/p/gwt-platform/issues/detail?id=15

Original comment by philippe.beaudoin on 27 Mar 2010 at 6:11