public abstract class Presenter<V extends View,Proxy_ extends Proxy<?>> extends PresenterWidget<V>
Presenter
. If you need to separate logic from view
in a simple graphical component, you might consider using a PresenterWidget
.
For more details on the hierarchical organization of presenters, see PresenterWidget
.
Each presenter is associated to a Proxy
which is responsible for listening to the
various events of interest for this presenter. This makes it possible to lazily instantiate
the presenter and use GWT code splitting. Proxies are automatically generated for you
based on the information contained in the presenter. For this purpose, your presenter has to
define an embedded interface extending Proxy
or
ProxyPlace
. Then you should apply various
annotations to that interface in order to specify the characteristics of your presenter. For example,
the following code indicates that the presenter will use GWT code splitting and will be
reachable at url http://mydomain.com#main
:
public class MainPagePresenter extends Presenter<MainPagePresenter.MyView, MainPagePresenter.MyProxy> { public interface MyView extends View {} @ProxyCodeSplit @NameToken("main") public interface MyProxy extends ProxyPlace<MainPagePresenter> {} @Inject public MainPagePresenter(EventBus eventBus, MyView view, MyProxy proxy) { super(eventBus, view, proxy, Presenter.RevealType.Root); } }One of
ProxyStandard
,
ProxyCodeSplit
or
ProxyCodeSplitBundle
must always annotate the Proxy
interface.
To reveal a presenter associated to a ProxyPlace
you can simply navigate to an hyperlink corresponding to this place's name token. The
PlaceManager
offers a number of method for building
such hyperlinks. If you want to reveal it programatically, you should build a
PlaceRequest
and call one of the
following method:
PlaceManager.revealPlace(PlaceRequest)
PlaceManager.revealRelativePlace(PlaceRequest)
PlaceManager.revealRelativePlace(PlaceRequest, int)
Proxy
and does not have
a name token then you should call the forceReveal()
method. For such
presenters, it is customary to define an event responsible of revealing them in
order to enforce loose coupling. This event is then handled by the presenter
using the ProxyEvent
mechanism.
If the presenter is revealed and is not currently visible, then its revealInParent()
method
will be called.
To hide a presenter, you can reveal another one in the same slot or you can use
one of the methods described in PresenterWidget
.
A presenter has a number of lifecycle methods that you can hook on to:
HandlerContainerImpl.onBind()
PresenterWidget.onReveal()
PresenterWidget.onReset()
PresenterWidget.onHide()
HandlerContainerImpl.onUnbind()
PresenterWidget
triggers an internal chain of events that result
in these lifecycle methods being called. For an example, here is what happens when a presenter
is revealed (either via forceReveal()
, or through a
PlaceManager
method):
revealInParent()
is call and it asks to be set in one of its
parent slot by firing a
RevealContentEvent
PresenterWidget.onHide()
is called on the removed presenter and, recursively,
on its children (bottom-up: first the children, then the parent)RevealContentEvent
too, this continues recursively until a visible presenter is reached, or until a presenter fires
RevealRootContentEvent
or RevealRootLayoutContentEvent
PresenterWidget.onReveal()
is called on all the presenters
that were traversed. (top down: first the parent, then the children);PresenterWidget.onReset()
is called on all the
currently visible presenters (top-down: first the parent, then
the children).Modifier and Type | Class and Description |
---|---|
static class |
Presenter.RevealType
The RevealType define which event will be fired in the default
revealInParent() . |
Constructor and Description |
---|
Presenter(boolean autoBind,
EventBus eventBus,
V view,
Proxy_ proxy)
Creates a
Presenter that is not necessarily using automatic
binding. |
Presenter(EventBus eventBus,
V view,
Proxy_ proxy)
Creates a
Presenter that uses automatic binding. |
Presenter(EventBus eventBus,
V view,
Proxy_ proxy,
GwtEvent.Type<RevealContentHandler<?>> slot)
Creates a
Presenter that uses automatic binding. |
Presenter(EventBus eventBus,
V view,
Proxy_ proxy,
Presenter.RevealType revealType)
Creates a
Presenter that uses automatic binding. |
Presenter(EventBus eventBus,
V view,
Proxy_ proxy,
Presenter.RevealType revealType,
GwtEvent.Type<RevealContentHandler<?>> slot)
Creates a
Presenter that uses automatic binding. |
Modifier and Type | Method and Description |
---|---|
void |
bind()
Call this method after the object is constructed in order to bind all its
handlers.
|
void |
forceReveal()
Reveals the presenter, bypassing any service offered by the
PlaceManager . |
Proxy_ |
getProxy()
Returns the
Proxy attached to this presenter. |
protected Presenter.RevealType |
getRevealType()
Returns the
Presenter.RevealType of this presenter. |
protected GwtEvent.Type<RevealContentHandler<?>> |
getSlot()
Returns the slot where this presenter is to be revealed.
|
void |
prepareFromRequest(PlaceRequest request)
Prepare the state of the presenter given the information contained in
the
PlaceRequest . |
protected void |
revealInParent()
Requests that the presenter reveal itself in its parent presenter.
|
protected void |
setRevealType(Presenter.RevealType revealType)
Set the
Presenter.RevealType of this presenter. |
protected void |
setSlot(GwtEvent.Type<RevealContentHandler<?>> slot)
Set the slot where this presenter is to be revealed.
|
void |
unbind()
Call this method when you want to release the object and its handlers are
not needed anymore.
|
boolean |
useManualReveal()
Verifies if this presenter can be revealed automatically or if it is meant to be
revealed manually.
|
addHandler, addRegisteredHandler, addToPopupSlot, addToPopupSlot, addToSlot, addVisibleHandler, asWidget, clearSlot, fireEvent, getEventBus, getView, getWidget, isVisible, onHide, onReset, onReveal, removeFromPopupSlot, removeFromSlot, setInSlot, setInSlot
isBound, onBind, onUnbind, registerHandler
public Presenter(boolean autoBind, EventBus eventBus, V view, Proxy_ proxy)
Presenter
that is not necessarily using automatic
binding. Automatic binding will only work when instantiating this object using
Guice/GIN dependency injection. See
HandlerContainerImpl.HandlerContainerImpl(boolean)
for
more details on automatic binding.public Presenter(EventBus eventBus, V view, Proxy_ proxy)
Presenter
that uses automatic binding. This will
only work when instantiating this object using Guice/GIN dependency injection.
See HandlerContainerImpl.HandlerContainerImpl()
for more details on
automatic binding.public Presenter(EventBus eventBus, V view, Proxy_ proxy, Presenter.RevealType revealType)
Presenter
that uses automatic binding. This will
only work when instantiating this object using Guice/GIN dependency injection.
See HandlerContainerImpl.HandlerContainerImpl()
for more details on
automatic binding.eventBus
- The EventBus
.view
- The View
.proxy
- The Proxy
.revealType
- The Presenter.RevealType
.public Presenter(EventBus eventBus, V view, Proxy_ proxy, GwtEvent.Type<RevealContentHandler<?>> slot)
Presenter
that uses automatic binding. This will
only work when instantiating this object using Guice/GIN dependency injection.
See HandlerContainerImpl.HandlerContainerImpl()
for more details on
automatic binding.eventBus
- The EventBus
.view
- The View
.proxy
- The Proxy
.slot
- The slot where to reveal this presenter see GwtEvent.Type
and
RevealContentHandler
.public Presenter(EventBus eventBus, V view, Proxy_ proxy, Presenter.RevealType revealType, GwtEvent.Type<RevealContentHandler<?>> slot)
Presenter
that uses automatic binding. This will
only work when instantiating this object using Guice/GIN dependency injection.
See HandlerContainerImpl.HandlerContainerImpl()
for more details on
automatic binding.eventBus
- The EventBus
.view
- The View
.proxy
- The Proxy
.revealType
- The Presenter.RevealType
.slot
- The slot where to reveal this presenter see GwtEvent.Type
and RevealContentHandler
.public final void bind()
HandlerContainer
HandlerContainer.bind()
from the constructor
of a non-leaf class since it is meant to be called after the object has
been entirely constructed.
When automatic binding is used (see HandlerContainerImpl
), this will
be called immediately after the object is constructed through Guice/GIN dependency
injection mechanism.
If you are not using automatic binding, or if you later call
HandlerContainer.unbind()
on this object, you will have to call HandlerContainer.bind()
manually.
Multiple call to bind will not fail, the class will be bound once.bind
in interface HandlerContainer
bind
in class HandlerContainerImpl
public final void unbind()
HandlerContainer
HandlerContainer.bind()
again manually
if you ever want to reuse the object.unbind
in interface HandlerContainer
unbind
in class HandlerContainerImpl
public final void forceReveal()
PlaceManager
.
Since this method bypasses the PlaceManager
it will not:
Gatekeeper
prepareFromRequest(PlaceRequest)
.PlaceManager#setOnLeaveConfirmation(String) PlaceManager.setOnLeaveConfirmation
)ProxyPlace
use one of the method provided by the PlaceManager
.
For more details see Presenter
.public final Proxy_ getProxy()
Proxy
attached to this presenter.Proxy
.public boolean useManualReveal()
prepareFromRequest(PlaceRequest)
method.
In order to use manual reveal, override this method to return true
.
Then, in your prepareFromRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest)
, you can either:
ManualRevealCallback
,
which will automatically reveal the presenter upon success.ProxyPlace.manualReveal(Presenter)
when
your data is available. In this case you also have to call
ProxyPlace.manualRevealFailed()
if loading fails, otherwise your application will become unusable.false
.true
if you want to use manual reveal, or false
to use
automatic reveal.public void prepareFromRequest(PlaceRequest request)
PlaceRequest
. This method is called when the
PlaceManager
navigates
to this Presenter
. You should override the method to extract any
parameters you need from the request. Make sure you call your parent's
prepareFromRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest)
method.
If your presenter needs to fetch some information from the server while
preparing itself, consider using manual reveal. See useManualReveal()
.
If your presenter does not handle any parameter and does not want to fetch
extra information, then there is no need to override this method.request
- The PlaceRequest
.protected Presenter.RevealType getRevealType()
Presenter.RevealType
of this presenter.Presenter.RevealType
.protected void setRevealType(Presenter.RevealType revealType)
Presenter.RevealType
of this presenter.
If the parent type is not null, the slot will be ignored in revealInParent()
.revealType
- The Presenter.RevealType
.protected GwtEvent.Type<RevealContentHandler<?>> getSlot()
GwtEvent.Type
and RevealContentHandler
.protected void setSlot(GwtEvent.Type<RevealContentHandler<?>> slot)
revealInParent()
if the parent type is not null.slot
- The slot where to reveal this presenter see GwtEvent.Type
and
RevealContentHandler
.protected void revealInParent()
RevealContentEvent
,
a RevealRootContentEvent
or a RevealRootLayoutContentEvent
.Copyright © 2010-2014 ArcBees. All Rights Reserved.