Class SwingShutDownTask

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.lang.Runnable, java.util.concurrent.Callable<java.lang.Boolean>, java.util.EventListener, ShutDownTask

    public class SwingShutDownTask
    extends AbstractShutDownTask
    Provides a base for using Swing to ask if shutdown should conditionally continue.

    Sequence:

    1. checkPromptNeeded determines if ready to shutdown. If so, return ready.
    2. Issue a prompt, asking if the user wants to continue or do something else
    3. Recheck until something decided.

    If no "action" name is provided, only the continue and cancel options are shown.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.lang.String action  
      (package private) java.awt.Component component  
      (package private) java.lang.String warning  
    • Constructor Summary

      Constructors 
      Constructor Description
      SwingShutDownTask​(java.lang.String name, java.lang.String warning, java.lang.String action, java.awt.Component component)
      Constructor specifies the warning message and action to take
    • Constructor Detail

      • SwingShutDownTask

        public SwingShutDownTask​(java.lang.String name,
                                 java.lang.String warning,
                                 java.lang.String action,
                                 java.awt.Component component)
        Constructor specifies the warning message and action to take
        Parameters:
        name - the name of the task (used in logs)
        warning - the prompt to display
        action - the action button to display
        component - the parent component of the dialog
    • Method Detail

      • call

        public final java.lang.Boolean call()
        Ask if shut down is allowed.

        The shut down manager calls this method first on all the tasks before starting to execute the method ShutDownTask.run() on the tasks.

        If this method returns false on any task, the shut down process must be aborted. This implementation merely sets the "doRun" property to true, and should be overridden for any real checking. Note that overriding implementations should call AbstractShutDownTask.setDoRun(boolean) correctly. This implementation displays a dialog allowing a user continue stopping the app, abort stopping the app, or take a custom action. Closing the dialog without choosing any button is treated as aborting stopping the app.

        Specified by:
        call in interface java.util.concurrent.Callable<java.lang.Boolean>
        Specified by:
        call in interface ShutDownTask
        Overrides:
        call in class AbstractShutDownTask
        Returns:
        true if it is OK to shut down, false to abort shut down.
        See Also:
        didPrompt(), doPrompt()
      • run

        public void run()
        Take the necessary action. This method cannot abort the shutdown, and must not require user interaction to complete successfully. This method will be run in parallel to other ShutDownTasks. This implementation calls didPrompt() if the user took the prompt action.
      • checkPromptNeeded

        protected boolean checkPromptNeeded()
        Provide a subclass-specific check as to whether it's OK to shutdown. If not, issue a prompt before continuing. Default implementation never passes, causing message to be emitted.
        Returns:
        true if ready to shutdown, and no prompt needed. false to present dialog before shutdown proceeds
      • didPrompt

        protected void didPrompt()
        Handle the request to address a potential blocker to stopping. This method is called in run() and must not interact with the user.

        This is a dummy implementation, intended to be overloaded.

      • doPrompt

        protected boolean doPrompt()
        Handle the request to address a potential blocker to stopping. This method is called in call() and can interact with the user.

        This is a dummy implementation, intended to be overloaded.

        Returns:
        true if ready to shutdown, false to end shutdown