Skip to content

Commit

Permalink
Complete - task 91: Consider allowing singleton PresenterWidgets
Browse files Browse the repository at this point in the history
http://code.google.com/p/gwt-platform/issues/detail?id=91

See AbstractPresenterModule#bindSingletonPresenterWidget


Former-commit-id: 5ad36b6
  • Loading branch information
PhilBeaudoin committed May 28, 2010
1 parent a9de1b4 commit e2a60b0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
19 changes: 10 additions & 9 deletions src/com/philbeaudoin/gwtp/mvp/client/PresenterWidgetImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<V extends View>
extends HandlerContainerImpl implements PresenterWidget {

Expand Down Expand Up @@ -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<PresenterWidgetImpl<?>> 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<PresenterWidgetImpl<?>> 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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,7 +67,31 @@ protected <P, V> 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}.
* <p />
* <b>Important!</b> 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 <P> The {@link PresenterWidget} type.
* @param <V> 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 <P extends PresenterWidget, V extends View> void bindSingletonPresenterWidget(
Class<P> presenter,
Class<V> view,
Class<? extends V> 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.
Expand Down Expand Up @@ -127,7 +152,7 @@ protected <P extends Presenter, V extends View, Proxy_ extends Proxy<P>> void bi
* <p />
* <b>Important!</b> 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.
*
Expand All @@ -152,7 +177,7 @@ protected <P extends Presenter, Proxy_ extends Proxy<P>> void bindPresenter(
* <p />
* <b>Important!</b> 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.
*
Expand Down Expand Up @@ -187,7 +212,7 @@ protected <P extends Presenter,Proxy_ extends Proxy<P>> void bindPresenter(
* @param view The {@link View} interface.
* @param viewImpl The {@link View} implementation (not a singleton).
*/
protected <V extends View> void bindNonSingletonView(
protected <V extends View> void bindSharedView(
Class<V> view,
Class<? extends V> viewImpl ) {
bind( view ).to( viewImpl );
Expand Down

0 comments on commit e2a60b0

Please sign in to comment.