|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.scopemvc.controller.basic.BasicController
Full implementation of Controller
that
adds:
SwingView
) via the
CHANGE_MODEL_CONTROL_ID ControlID. Note that the PropertyView that a
top-level Controller owns must not have a Selector set: this is only
allowed for child Controllers that are delegated by a parent to handle a
subview and associated submodel that is part of the parent model: the
binding will be handled by the parent in this case. ControlException
handling
by using ViewContext.showError(java.lang.String, java.lang.String)
. To implement a subclass of BasicController:
setModelAndView(java.lang.Object, org.scopemvc.core.View)
may be useful here. doHandleControl(org.scopemvc.core.Control)
to recognise the ID of incoming
Control
s and respond to them
appropriately. For example: protected void doHandleControl(Control inControl) throws ControlException { if (inControl.matchesID(FOO_CONTROL_ID)) { doFoo(inControl.getParameter()); } else if (inControl.matchesID(BAR_CONTROL_ID)) { doBar(inControl.getParameter()); } }
SwingView
and is not needed for ServletView
with the default
implementation in XSLPage
.
Field Summary | |
static java.lang.String |
CHANGE_MODEL_CONTROL_ID
An internal Control calls changeModel(). |
static java.lang.String |
EXIT_CONTROL_ID
A convenience Control that can be used when a Controller wants to exit. |
static java.lang.String |
HANDLE_CONTROL_RUNTIME_ERROR_MSG_ID
ID of error message for RuntimeExceptions caught by BasicController. |
static java.lang.String |
HIDE_VIEW_CONTROL_ID
ID of common Control that is handled by BasicController to hide the current view. |
Constructor Summary | |
BasicController()
Construct subclasses by either using a passed model object and View, or creating new ones. |
Method Summary | |
void |
addChild(BasicController inChild)
Add a child Controller. |
protected void |
bindModelToView(View inView,
java.lang.Object inModel)
Bind a model object to a View if that is possible (model and view must be not null, the view must not have a selector marking it as being handled by a parent view) |
protected void |
doHandleControl(Control inControl)
Custom implementation of some presentation logic. |
java.util.List |
getChildren()
Returns the list of child Controllers. |
java.lang.Object |
getModel()
Return the model bound to this Controller |
Controller |
getParent()
Get the parent of this Controller |
Controller |
getTopParent()
Convenience method. |
View |
getView()
Return the View bound to this Controller. |
void |
handleControl(Control inControl)
Application writers see doHandleControl(org.scopemvc.core.Control) . |
protected void |
handleControlException(ControlException inException)
Called by handleControl(org.scopemvc.core.Control) when a Control throws a ControlException . |
protected void |
hideView()
Hide the View bound to this Controller. |
protected void |
hideView(View inView)
Hide the given View |
protected void |
passControlToParent(Control inControl)
Feed a Control to the parent Controller up the chain of command. |
void |
removeChild(BasicController inChild)
Remove a child Controller from this Controller. |
void |
setModel(java.lang.Object inModel)
Sets the model object that this Controller links to its View. |
void |
setModelAndView(java.lang.Object inModel,
View inView)
Change to both a new model object and new View, binding the two together properly. |
protected void |
setParent(BasicController inParent)
Hook this Controller into the chain of responsiblity as a child of the passed Controller. |
void |
setView(View inView)
Sets the View that this Controller links to its model object. |
protected void |
showError(java.lang.String inErrorTitle,
java.lang.String inErrorMessage)
Convenience to show an error using the current ViewContext . |
protected void |
showView()
Show the view bound to this Controller. |
protected void |
showView(View inView)
Show the given view. |
void |
shutdown()
Shutdown the Controller and its bound View and Model. |
void |
startup()
Starts the Controller and its bound View and Model. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String HANDLE_CONTROL_RUNTIME_ERROR_MSG_ID
public static final java.lang.String HIDE_VIEW_CONTROL_ID
public static final java.lang.String CHANGE_MODEL_CONTROL_ID
public static final java.lang.String EXIT_CONTROL_ID
A convenience Control that can be used when a Controller wants to exit. For an application Controller this means exitting the application, but for a sub-controller it probably means just an exit from that local area of functionality. This impl causes this Control to propagate up the chain of responsibility so that if unhandled the application will exit.
The parameter of this Control is the Controller that issued it (ie the
one that's shutting down), or null if just issued by this
.
The default impl here propagates the Control up, changing the shutdown
Controller as it goes up, until it meets the top of the Controller tree
at which point ViewContext.exit()
is called: for Swing this does
System.exit and for Servlets it is ignored. If you use this Control,
recognise it at some parent of the Controller that can issue it, and take
appropriate action.
Constructor Detail |
public BasicController()
Construct subclasses by either using a passed model object and View, or
creating new ones. Use setModel(java.lang.Object)
and setView(org.scopemvc.core.View)
or setModelAndView(java.lang.Object, org.scopemvc.core.View)
. Never show a View on construction: initialisation
should set the application up without actually starting it by showing a
View. An initial startup action implemented in startup() can show a View
when called after construction.
Throw a ControlException from subclasses if something goes wrong.
Method Detail |
public final java.util.List getChildren()
public final Controller getParent()
getParent
in interface Controller
public final java.lang.Object getModel()
getModel
in interface Controller
public final View getView()
getView
in interface Controller
public final Controller getTopParent()
getTopParent
in interface Controller
public final void setModel(java.lang.Object inModel)
setModelAndView(java.lang.Object, org.scopemvc.core.View)
rather
than calling setModel and setView separately.
setModel
in interface Controller
inModel
- The new model valuepublic final void setView(View inView)
setModelAndView(java.lang.Object, org.scopemvc.core.View)
rather than calling setModel() and setView()
separately.
setView
in interface Controller
inView
- The new view valuepublic final void setModelAndView(java.lang.Object inModel, View inView)
inModel
- new model object, can be nullinView
- new View, cannot be nullpublic final void addChild(BasicController inChild)
inChild
- The child Controller to add.public final void removeChild(BasicController inChild)
inChild
- The child Controller to remove.public final void handleControl(Control inControl)
doHandleControl(org.scopemvc.core.Control)
. This base
implementation handles
handleControl
in interface Controller
inControl
- The Control to handlehandleControl(org.scopemvc.core.Control)
public void startup()
Starts the Controller and its bound View and Model.
Call this method after creating the Controller to make it perform its initial action. This method is not called automatically by Scope, so you have to call it yourself.
public void shutdown()
Shutdown the Controller and its bound View and Model.
Can be called by a parent Controller to shutdown and remove this from the chain of responsibility.
protected final void setParent(BasicController inParent)
addChild(org.scopemvc.controller.basic.BasicController)
inParent
- The new parent valueprotected final void passControlToParent(Control inControl)
inControl
- The Control to delegate to the parent Controllerprotected final void showView()
protected final void showView(View inView)
inView
- The View to showprotected final void hideView()
protected final void hideView(View inView)
inView
- The View to hideprotected final void showError(java.lang.String inErrorTitle, java.lang.String inErrorMessage)
ViewContext
.
inErrorTitle
- The title for the error message windowinErrorMessage
- The content of the error messageprotected void bindModelToView(View inView, java.lang.Object inModel)
inView
- the View to bindinModel
- the model object to bind to the Viewprotected void doHandleControl(Control inControl) throws ControlException
Custom implementation of some presentation logic.
Override this to recognise Controls that this Controller can handle. Any unhandled Controls are passed up the chain of responsibility to parent Controllers.
protected void doHandleControl(Control inControl) throws ControlException { if (inControl.matchesID(FOO_CONTROL_ID)) { doFoo(inControl.getParameter()); } else if (inControl.matchesID(BAR_CONTROL_ID)) { doBar(inControl.getParameter()); } }
If something goes wrong when running some presentation logic, throw a
ControlException
which results
in a call to handleControlException(org.scopemvc.core.ControlException)
).
inControl
- The Control to handle
ControlException
- If something goes wrong when running some
presentation logicprotected void handleControlException(ControlException inException)
handleControl(org.scopemvc.core.Control)
when a Control
throws a ControlException
. showError(java.lang.String, java.lang.String)
method.
inException
- An exception thrown when something goes wrong with the
presentation logic.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |