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|Exit
menu item defined by most applications.The
shutdown()
method ofApplication
checks 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 typeObject
according to the way resource texts are specified. Here either resource IDs can be passed in orMessage
objects. 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 anApplicationShutdownActionTask
bean with a custom prompt message to be displayed if there is still background activity. AMessage
object initialized with a resource ID is constructed and passed to theexitPromptMessageResource
property (the default resource group is used; it would also be possible to pass a resource group to theMessage
object). 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 Application
getApplication()
Returns the centralApplication
object.Object
getExitPromptMessageResource()
Returns the resource ID for the message of the exit prompt dialog.Object
getExitPromptTitleResource()
Returns the resource ID for the title of the exit prompt dialog.void
run()
Executes this task.void
setApplication(Application app)
Sets the centralApplication
object.void
setExitPromptMessageResource(Object exitPromptMessageResource)
Sets the resource ID for the message of the exit prompt dialog.void
setExitPromptTitleResource(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 aMessage
object. 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 aMessage
object. 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 centralApplication
object. This is the application this task is going to shut down.- Returns:
- the
Application
-
setApplication
public void setApplication(Application app)
Sets the centralApplication
object. 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:
setApplication
in interfaceApplicationClient
- Parameters:
app
- theApplication
object
-
run
public void run()
Executes this task. This implementation calls theApplication.shutdown(Object, Object)
method on theApplication
object passed tosetApplication(Application)
. If noApplication
was set, an exception is thrown.- Specified by:
run
in interfaceRunnable
- Throws:
IllegalStateException
- if noApplication
has been set
-
-