Class ApplicationShutdownActionTask
- java.lang.Object
-
- net.sf.jguiraffe.gui.app.ApplicationShutdownActionTask
-
- All Implemented Interfaces:
Runnable,ApplicationClient
public class ApplicationShutdownActionTask extends Object implements Runnable, ApplicationClient
A specialized action task for exiting the current application.
This action task simply calls the
Application.shutdown(Object, Object)method, which is the default way of terminating the currently running application. It can be associated with aFile|Exitmenu item defined by most applications.The
shutdown()method ofApplicationchecks whether currently still background tasks are running. If this is the case, a message box is displayed asking the user whether the application should shutdown anyway. Both the title and the message displayed by this message box can be specified. This class defines corresponding properties of typeObjectaccording to the way resource texts are specified. Here either resource IDs can be passed in orMessageobjects. If no specific values for these properties are set, default values are used referring to standard resources shipped with the library.The following example fragment shows how the action for terminating the application can be defined in a Jelly builder script:
<!-- The action task for quitting the application --> <di:bean name="exitTask" beanClass="net.sf.jguiraffe.gui.app.ApplicationShutdownActionTask"> <di:setProperty property="exitPromptMessageResource"> <di:bean beanClass="net.sf.jguiraffe.resources.Message"> <di:constructor> <di:param value="EXIT_MESSAGE"/> </di:constructor> </di:bean> </di:setProperty> </di:bean> <!-- The action itself --> <a:action name="exitAction" text="Exit" taskBean="exitTask"/>This fragment declares anApplicationShutdownActionTaskbean with a custom prompt message to be displayed if there is still background activity. AMessageobject initialized with a resource ID is constructed and passed to theexitPromptMessageResourceproperty (the default resource group is used; it would also be possible to pass a resource group to theMessageobject). The resource ID for the title of the exit prompt dialog is not set, so here the default is used.- Version:
- $Id: $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description ApplicationShutdownActionTask()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ApplicationgetApplication()Returns the centralApplicationobject.ObjectgetExitPromptMessageResource()Returns the resource ID for the message of the exit prompt dialog.ObjectgetExitPromptTitleResource()Returns the resource ID for the title of the exit prompt dialog.voidrun()Executes this task.voidsetApplication(Application app)Sets the centralApplicationobject.voidsetExitPromptMessageResource(Object exitPromptMessageResource)Sets the resource ID for the message of the exit prompt dialog.voidsetExitPromptTitleResource(Object exitPromtTitleResource)Sets the resource ID for the title of the exit prompt dialog.
-
-
-
Method Detail
-
getExitPromptMessageResource
public Object getExitPromptMessageResource()
Returns the resource ID for the message of the exit prompt dialog. This implementation never returns null; if the property was not set, a default value is returned.- Returns:
- the resource ID for the exit prompt dialog message
-
setExitPromptMessageResource
public void setExitPromptMessageResource(Object exitPromptMessageResource)
Sets the resource ID for the message of the exit prompt dialog. This dialog is displayed if there are still running background tasks when the application should shut down. The parameter object can be aMessageobject. Otherwise, it is interpreted as resource ID and resolved against the default resource group.- Parameters:
exitPromptMessageResource- the resource ID
-
getExitPromptTitleResource
public Object getExitPromptTitleResource()
Returns the resource ID for the title of the exit prompt dialog. This implementation never returns null; if the property was not set, a default value is returned.- Returns:
- the resource ID for the exit prompt dialog title
-
setExitPromptTitleResource
public void setExitPromptTitleResource(Object exitPromtTitleResource)
Sets the resource ID for the title of the exit prompt dialog. This dialog is displayed if there are still running background tasks when the application should shut down. The parameter object can be aMessageobject. Otherwise, it is interpreted as resource ID and resolved against the default resource group.- Parameters:
exitPromtTitleResource- the resource ID
-
getApplication
public Application getApplication()
Returns the centralApplicationobject. This is the application this task is going to shut down.- Returns:
- the
Application
-
setApplication
public void setApplication(Application app)
Sets the centralApplicationobject. If this bean is created by the dependency injection framework (which is the intended default way of using this class), this reference is automatically injected.- Specified by:
setApplicationin interfaceApplicationClient- Parameters:
app- theApplicationobject
-
run
public void run()
Executes this task. This implementation calls theApplication.shutdown(Object, Object)method on theApplicationobject passed tosetApplication(Application). If noApplicationwas set, an exception is thrown.- Specified by:
runin interfaceRunnable- Throws:
IllegalStateException- if noApplicationhas been set
-
-