Class 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 a File|Exit menu item defined by most applications.

    The shutdown() method of Application 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 type Object according to the way resource texts are specified. Here either resource IDs can be passed in or Message 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 an ApplicationShutdownActionTask bean with a custom prompt message to be displayed if there is still background activity. A Message object initialized with a resource ID is constructed and passed to the exitPromptMessageResource property (the default resource group is used; it would also be possible to pass a resource group to the Message 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 Detail

      • ApplicationShutdownActionTask

        public ApplicationShutdownActionTask()
    • 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 a Message 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 a Message 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 central Application object. This is the application this task is going to shut down.
        Returns:
        the Application
      • setApplication

        public void setApplication​(Application app)
        Sets the central Application 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 interface ApplicationClient
        Parameters:
        app - the Application object