de.esprit.appsuite.task

## Class TaskAction<C extends ApplicationContext>

- java.lang.Object
- - javax.swing.AbstractAction
  - - de.esprit.common.gui.ZAction<C>
    - - de.esprit.appsuite.task.TaskAction<C>

- All Implemented Interfaces:
    ApplicationObject<C>, ErrorHandlerSupport, SimpleLogSupport, java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action
  Direct Known Subclasses:
    ClientTaskAction

      public class TaskAction<C extends ApplicationContext>
      extends ZAction<C>

  This action runs a monitored `AsyncTask` created by `createTask()`. The task is run within the `ExecutorService` of the `ApplicationContext`. During execution the built-in `SwingTaskMonitor` receives progress notifications and calls the according taskXXX methods. The `getActionCancel()` method provides an according action for canceling the task. Similar `createProgressBar()` provides a readily configured `ZProgressBar` attached to the task.
  Author:
    Rainer Buesch
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class javax.swing.AbstractAction

      `changeSupport, enabled`

    - ### Fields inherited from interface javax.swing.Action

      `ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TaskAction(C ctx)`
    `TaskAction(C ctx, NlsActionKey nls)`
    `TaskAction(C ctx, NlsActionKey nls, IconKey icon)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `actionFired(java.awt.event.ActionEvent e)` Is called when the action is fired.
    `protected void` | `actionPrepare()` Runs sync BEFORE the `ZAction.actionFired(ActionEvent)` method is called.
    `void` | `cancel()`
    `void` | `cancelAndWait()`
    `protected boolean` | `checkEnableCondition()` This condition is evaluated automatically after construction.
    `ZProgressBar` | `createProgressBar()`
    `protected AsyncTask` | `createTask()` Is called each time the action is fired.
    `TaskCancelAction` | `getActionCancel()`
    `AsyncTask` | `getCurrentTask()`
    `void` | `setTask(AsyncTask newTask)`
    `protected void` | `taskCancelled()` Is called after the has been cancelled.
    `protected void` | `taskFailed(java.lang.Exception e)` Is called after the task has been failed.
    `protected void` | `taskFinished()` Is called by the ET after the action has been finished, no matter whether it succeeded or failed.
    `protected void` | `taskStarted()` Is called when the task has been started
    `protected void` | `taskSucceeded()` Is called when the task has been succeeded

    - ### Methods inherited from class de.esprit.common.gui.ZAction

      `actionConfirmed, actionDenied, actionFailed, actionPerformed, actionSucceeded, fire, getApplicationContext, getButtonText, getIcon, getLogChannel, getMenuText, getName, getPressedIcon, getTipText, isForced, isHandleError, isLogDebug, isLogVerbose, isPermitted, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, performAvailabilityCheck, setBusyAnimationEnabled, setHandleError, setIcon, setIcon, setLogChannel, setName, setPressedIcon, setPressedIcon, setText, setTipText, setValidator, showError, showError, showError, showInfo, showInfo, showWarning, showWarning, toString`

    - ### Methods inherited from class javax.swing.AbstractAction

      `addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### TaskAction

          public TaskAction(C ctx)

    - #### TaskAction

          public TaskAction(C ctx,
                    NlsActionKey nls)

    - #### TaskAction

          public TaskAction(C ctx,
                    NlsActionKey nls,
                    IconKey icon)

  - ### Method Detail

    - #### setTask

          public void setTask(AsyncTask newTask)

    - #### getCurrentTask

          public AsyncTask getCurrentTask()

    - #### cancel

          public void cancel()

    - #### cancelAndWait

          public void cancelAndWait()

    - #### createProgressBar

          public ZProgressBar createProgressBar()

    - #### getActionCancel

          public TaskCancelAction getActionCancel()

    - #### checkEnableCondition

          protected boolean checkEnableCondition()

      Description copied from class: `ZAction`
      This condition is evaluated automatically after construction. The action enables/disables accordingly. Does not change the current enable state by default.
      Overrides:
        `checkEnableCondition` in class `ZAction<C extends ApplicationContext>`

    - #### actionPrepare

          protected void actionPrepare()
                                throws java.lang.Exception

      Description copied from class: `ZAction`
      Runs sync BEFORE the `ZAction.actionFired(ActionEvent)` method is called. Any preconditional checks or settings may be implemented here.
      Overrides:
        `actionPrepare` in class `ZAction<C extends ApplicationContext>`
      Throws:
        `java.lang.Exception`

    - #### actionFired

          protected final void actionFired(java.awt.event.ActionEvent e)
                                    throws java.lang.Exception

      Description copied from class: `ZAction`
      Is called when the action is fired. It contains the code being executed by this action.
      Specified by:
        `actionFired` in class `ZAction<C extends ApplicationContext>`
      Throws:
        `java.lang.Exception`

    - #### createTask

          protected AsyncTask createTask()
                                  throws java.lang.Exception

      Is called each time the action is fired. The returned AsyncTask is being executed within the applications default thread-pool. If the same `AsyncTask` instance should be executed on firing, then this method may return a singleton instead of creating a new task each time.
      Throws:
        `java.lang.Exception`
      See Also:
        `ZAction.actionConfirmed()`

    - #### taskStarted

          protected void taskStarted()

      Is called when the task has been started

    - #### taskSucceeded

          protected void taskSucceeded()

      Is called when the task has been succeeded

    - #### taskCancelled

          protected void taskCancelled()

      Is called after the has been cancelled.

    - #### taskFailed

          protected void taskFailed(java.lang.Exception e)

      Is called after the task has been failed.

    - #### taskFinished

          protected void taskFinished()

      Is called by the ET after the action has been finished, no matter whether it succeeded or failed.

Copyright © 2014 EsprIT-Systems. All Rights Reserved.