diff --git a/src/com/philbeaudoin/gwtp/mvp/client/PresenterWidgetImpl.java b/src/com/philbeaudoin/gwtp/mvp/client/PresenterWidgetImpl.java index b86f38e62a..0f1fbeff7f 100644 --- a/src/com/philbeaudoin/gwtp/mvp/client/PresenterWidgetImpl.java +++ b/src/com/philbeaudoin/gwtp/mvp/client/PresenterWidgetImpl.java @@ -27,9 +27,9 @@ import com.philbeaudoin.gwtp.mvp.client.proxy.ResetPresentersEvent; /** -* @author Philippe Beaudoin -* @author Christian Goudreau -*/ + * @author Philippe Beaudoin + * @author Christian Goudreau + */ public abstract class PresenterWidgetImpl extends HandlerContainerImpl implements PresenterWidget { @@ -305,15 +305,16 @@ public void addContent( Object slot, PresenterWidget content ) { * what to do with this slot. */ public void clearContent( Object slot ) { - if( isVisible() ) { - // This presenter is visible, its time to call onReveal + List> slotChildren = activeChildren.get( slot ); + if( slotChildren != null ) { + // This presenter is visible, its time to call onHide // on the newly added child (and recursively on this child children) - List> slotChildren = activeChildren.get( slot ); - if( slotChildren != null ) { - for( PresenterWidgetImpl activeChild : slotChildren ) + if( isVisible() ) { + for( PresenterWidgetImpl activeChild : slotChildren ) { activeChild.notifyHide(); - slotChildren.clear(); + } } + slotChildren.clear(); } getView().setContent( slot, null ); } diff --git a/src/com/philbeaudoin/gwtp/mvp/client/gin/AbstractPresenterModule.java b/src/com/philbeaudoin/gwtp/mvp/client/gin/AbstractPresenterModule.java index b222d806c2..f96776c55a 100644 --- a/src/com/philbeaudoin/gwtp/mvp/client/gin/AbstractPresenterModule.java +++ b/src/com/philbeaudoin/gwtp/mvp/client/gin/AbstractPresenterModule.java @@ -18,6 +18,7 @@ import com.google.gwt.inject.client.AbstractGinModule; import com.google.inject.Singleton; +import com.philbeaudoin.gwtp.mvp.client.PresenterImpl; import com.philbeaudoin.gwtp.mvp.client.View; import com.philbeaudoin.gwtp.mvp.client.Presenter; import com.philbeaudoin.gwtp.mvp.client.PresenterWidget; @@ -66,7 +67,31 @@ protected void bindPresenterWidgetFactory( bind(presenterFactory).to(presenterFactoryImpl).in(Singleton.class); bind(viewFactory).to(viewFactoryImpl).in(Singleton.class); } - + + /** + * Convenience method for binding a singleton {@link PresenterWidget} with its {@link View}. + *

+ * Important! If you want to use the same {@link PresenterWidget} in many different places, + * you should consider making it non-singleton with {@link #bindPresenterWidget}. It is possible + * to use the same singleton {@link PresenterWidget} in different presenters, as long as these + * are not simultaneously visible. Also, if you do this, you must make sure to set the singleton + * presenter widget as content in its containing presenter {@link PresenterImpl#onReveal} and to + * remove it in the {@link PresenterImpl#onHide}. + * + * @param

The {@link PresenterWidget} type. + * @param The {@link View} type. + * @param presenter The {@link PresenterWidget} (a singleton). + * @param view The {@link View} interface. + * @param viewImpl The {@link View} implementation (a singleton). + */ + protected

void bindSingletonPresenterWidget( + Class

presenter, + Class view, + Class viewImpl ) { + bind( presenter ).in(Singleton.class); + bind( view ).to( viewImpl ).in(Singleton.class); + } + /** * Convenience method for binding a singleton presenter with its view and * its proxy, when using automatically generated proxy classes. @@ -127,7 +152,7 @@ protected

> void bi *

* Important! This is only be meant to be used by presenters associated * with non-singleton views, for example when the same view class is reused with - * many presenters. As such, you will need to also use the {@link #bindNonSingletonView} method. + * many presenters. As such, you will need to also use the {@link #bindSharedView} method. * If the view class is use only by one presenter, you should consider using * {@link #bindPresenter(Class, Class, Class, Class)} instead. * @@ -152,7 +177,7 @@ protected

> void bindPresenter( *

* Important! This is only be meant to be used by presenters associated * with non-singleton views, for example when the same view class is reused with - * many presenters. As such, you will need to also use the {@link #bindNonSingletonView} method. + * many presenters. As such, you will need to also use the {@link #bindSharedView} method. * If the view class is use only by one presenter, you should consider using * {@link #bindPresenter(Class, Class, Class, Class, Class)} instead. * @@ -187,7 +212,7 @@ protected

> void bindPresenter( * @param view The {@link View} interface. * @param viewImpl The {@link View} implementation (not a singleton). */ - protected void bindNonSingletonView( + protected void bindSharedView( Class view, Class viewImpl ) { bind( view ).to( viewImpl );