Holger's Java API

## com.antelmann.util.gui
Class MyAbstractAction

    java.lang.Object
      javax.swing.AbstractAction
          com.antelmann.util.gui.MyAbstractAction

All Implemented Interfaces:
  LoggerProvider, ActionListener, Serializable, Cloneable, EventListener, Action

Direct Known Subclasses:
  SaveImageAction, ShowLicensesAction

    @Licensed
    public abstract class MyAbstractAction

extends AbstractAction
implements LoggerProvider

a base class for actions that provides some convenience for implementing actions

Since:
  10/23/08
Author:
  Holger Antelmann
See Also:
  Serialized Form

Field Summary
`protected ValueRetriever<? extends Component>` `parentRetriever`
`protected ValueRetriever<? extends User>` `userRetriever`

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
`MyAbstractAction()`
`MyAbstractAction(Icon icon)`
`MyAbstractAction(String name)`
`MyAbstractAction(String name, String description, Icon icon)`
`MyAbstractAction(String name, String description, Icon icon, Component parent)`
`MyAbstractAction(String name, String description, Icon icon, Component parent, Logger logger)`
`MyAbstractAction(String name, String description, Icon icon, Component parent, Logger logger, ValueRetriever<User> userRetriever, boolean requiresLicense)`

Method Summary
`void` `actionPerformed(ActionEvent ev)` initializes the parent component - if applicable - and calls performAction; if the parent was null, it is going to be reset at the end again, so that it gets dynamically reset on each call.
`boolean` `add(InterfaceMonitor im)`
`boolean` `addRequiredAccessRight(Object right)` returns true only if the given right was actually added; false if the right was already present
`void` `addRequiredAccessRights(Object... rights)`
`void` `checkAccess(User user)` checks the current user from the retriever for being able to access all required rights in order to access this action; this method is called upon `actionPerformed(ActionEvent)`.

`static

`<T> ListRetriever<T>`

`

`createListRetriever(List<T> list, String listDescription)`

`static

`<T extends DBEntry> ValueRetriever<DBReference>`

`

`createReferenceRetriever(ValueRetriever<T> retriever)`

`static

`<T extends DBEntry> ValueRetriever<Stub<T>>`

`

`createStubRetriever(T entry)`

`static

`<T extends DBEntry> ValueRetriever<Stub<T>>`

`

`createStubRetriever(ValueRetriever<T> retriever)`

`protected Component` `determineParentComponent(ActionEvent ev)` called by actionPerformed(ActionEvent) to allow the initialization of the parent component before performAction(ActionEvent) is called
`protected void` `doh(Throwable ex)`
`protected void` `doh(Throwable ex, Component parent)` handles an Exception the common way by logging it and then displaying it to the user

`

`<T> void`

`

`execute(Callable<T> call, Handler<? super T,?> handler)`
executes the given call in a new thread (as a background task) and then performs the handler with the value from the call in the event thread again

`Thread` `execute(Task<?> backgroundTask, Task<?> finishingTaskInEventThread)` executes the first given task in the background and then the second later in the event thread again.
`static Component` `findParent(EventObject ev)`
`Object` `getFormValue(Form form, Object defaultValue)`
`Object` `getFormValue(Form form, ValueRetriever<?> retriever)`
`String` `getHelpText()`
`InterfaceMonitor[]` `getInterfaceMonitors()`
`Logger` `getLogger()` acess to the (non-null) Logger suitable for logging entries in the context of this instance
`Component` `getParent()`
`ValueRetriever<? extends Component>` `getParentRetriever()`
`protected Set<Object>` `getRequiredUserRights()`
`Filter<? super User>` `getUserAccessFilter()`
`ValueRetriever<? extends User>` `getUserRetriever()`
`boolean` `isAccessibleBy(User user)` utilizes `checkAccess(User)` to answer the question (while temporarily disabling password requirements)
`protected abstract void` `performAction(ActionEvent ev, Component parent)`
`boolean` `remove(InterfaceMonitor im)`
`boolean` `requiresLicense()`
`boolean` `requiresPassword()` returns whether this action requires to re-enter the login password to be able to continue (false by default), which is only applicable if a userRetriever is set to a non-null value.
`String` `runCommand(boolean captureOutput, String... command)` convenience method to simply run a given command on the command line
`Thread` `runInBackground(Task<?> task)` returns the started thread
`void` `setDisjunctAccessFilter(Object... accessRights)` sets a special user access filter
`void` `setHelpText(String helpText)`
`void` `setMnemonicKey(int mnemonicKey)` see `KeyEvent`
`void` `setParent(Component parent)`
`void` `setParentRetriever(ValueRetriever<? extends Component> parentRetriever)`
`void` `setRequiresLicense(boolean flag)`
`void` `setRequiresPassword(boolean requiresPassword)` allows to enforce that the user currently logged in needs to re-enter his/her password to be able to continue.
`void` `setUserAccessFilter(Filter<? super User> userAccessFilter)` allows to specify a filter for users that is checked when `checkAccess(User)` is called if set to a non-null value
`void` `setUserRetriever(ValueRetriever<? extends User> userRetriever)`

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, toString, wait, wait, wait`

Field Detail

### userRetriever

    protected ValueRetriever<? extends User> userRetriever

### parentRetriever

    protected ValueRetriever<? extends Component> parentRetriever

Constructor Detail

### MyAbstractAction

    public MyAbstractAction()

### MyAbstractAction

    public MyAbstractAction(String name)

### MyAbstractAction

    public MyAbstractAction(Icon icon)

### MyAbstractAction

    public MyAbstractAction(String name,
                            String description,
                            Icon icon)

### MyAbstractAction

    public MyAbstractAction(String name,
                            String description,
                            Icon icon,
                            Component parent)

### MyAbstractAction

    public MyAbstractAction(String name,
                            String description,
                            Icon icon,
                            Component parent,
                            Logger logger)

### MyAbstractAction

    public MyAbstractAction(String name,
                            String description,
                            Icon icon,
                            Component parent,
                            Logger logger,
                            ValueRetriever<User> userRetriever,
                            boolean requiresLicense)

Method Detail

### performAction

    protected abstract void performAction(ActionEvent ev,
                                          Component parent)
                                   throws Exception

  Throws:
    `Exception`

### getUserAccessFilter

    public Filter<? super User> getUserAccessFilter()

  See Also:
    `setUserAccessFilter(Filter)`

### setUserAccessFilter

    public void setUserAccessFilter(Filter<? super User> userAccessFilter)

  allows to specify a filter for users that is checked when `checkAccess(User)` is called if set to a non-null value

  See Also:
    `checkAccess(User)`, `UserFilter`

### setDisjunctAccessFilter

    public void setDisjunctAccessFilter(Object... accessRights)

  sets a special user access filter

  See Also:
    `setUserAccessFilter(Filter)`

### setMnemonicKey

    public void setMnemonicKey(int mnemonicKey)

  see `KeyEvent`

### setHelpText

    public void setHelpText(String helpText)

### getHelpText

    public String getHelpText()

### getUserRetriever

    public ValueRetriever<? extends User> getUserRetriever()

### setUserRetriever

    public void setUserRetriever(ValueRetriever<? extends User> userRetriever)

### requiresPassword

    public boolean requiresPassword()

  returns whether this action requires to re-enter the login password to be able to continue (false by default), which is only applicable if a userRetriever is set to a non-null value.

  See Also:
    `setRequiresPassword(boolean)`, `setUserRetriever(ValueRetriever)`

### getLogger

    public Logger getLogger()

  Description copied from interface: `LoggerProvider`
  acess to the (non-null) Logger suitable for logging entries in the context of this instance

  Specified by:
    `getLogger` in interface `LoggerProvider`

### requiresLicense

    public boolean requiresLicense()

### setRequiresLicense

    public void setRequiresLicense(boolean flag)

### getRequiredUserRights

    protected Set<Object> getRequiredUserRights()

### setRequiresPassword

    public void setRequiresPassword(boolean requiresPassword)

  allows to enforce that the user currently logged in needs to re-enter his/her password to be able to continue. Setting this to true will only work if a `Database` is associated with this instance.

  See Also:
    `checkAccess(User)`

### createStubRetriever

    public static <T extends DBEntry> ValueRetriever<Stub<T>> createStubRetriever(T entry)

### createStubRetriever

    public static <T extends DBEntry> ValueRetriever<Stub<T>> createStubRetriever(ValueRetriever<T> retriever)

### createReferenceRetriever

    public static <T extends DBEntry> ValueRetriever<DBReference> createReferenceRetriever(ValueRetriever<T> retriever)

### createListRetriever

    public static <T> ListRetriever<T> createListRetriever(List<T> list,
                                                           String listDescription)

### isAccessibleBy

    public boolean isAccessibleBy(User user)

  utilizes `checkAccess(User)` to answer the question (while temporarily disabling password requirements)

### checkAccess

    public void checkAccess(User user)
                     throws AccessControlException

  checks the current user from the retriever for being able to access all required rights in order to access this action; this method is called upon `actionPerformed(ActionEvent)`. When overriding this method it is a good idea to call this method through super.checkAccess(user) to have the usual stuff checked automatically and then to your own checks.

  Throws:
    `AccessControlException` - if the check fails (which also happens if no user was given)

### addRequiredAccessRights

    public void addRequiredAccessRights(Object... rights)

### addRequiredAccessRight

    public boolean addRequiredAccessRight(Object right)

  returns true only if the given right was actually added; false if the right was already present

### getParentRetriever

    public ValueRetriever<? extends Component> getParentRetriever()

### setParentRetriever

    public void setParentRetriever(ValueRetriever<? extends Component> parentRetriever)

### determineParentComponent

    protected Component determineParentComponent(ActionEvent ev)

  called by actionPerformed(ActionEvent) to allow the initialization of the parent component before performAction(ActionEvent) is called

### findParent

    public static Component findParent(EventObject ev)

### setParent

    public void setParent(Component parent)

### getParent

    public Component getParent()

### runCommand

    public String runCommand(boolean captureOutput,
                             String... command)
                      throws IOException,
                             InterruptedException

  convenience method to simply run a given command on the command line

  Parameters:
    `command` - the command to be run
    `captureOutput` - if true, the output of the command is captured and returned
  Returns:
    the output of the command or null if captureOutput is false
  Throws:
    `IOException`
    `InterruptedException`

### execute

    public <T> void execute(Callable<T> call,
                            Handler<? super T,?> handler)

  executes the given call in a new thread (as a background task) and then performs the handler with the value from the call in the event thread again

  Parameters:
    `call` -
    `handler` -

### runInBackground

    public Thread runInBackground(Task<?> task)

  returns the started thread

### execute

    public Thread execute(Task<?> backgroundTask,
                          Task<?> finishingTaskInEventThread)

  executes the first given task in the background and then the second later in the event thread again. The returned thread is finished after the background task is finished; the other event is put on the event thread for later (to allow waiting for the thread to finish within the event thread).

  Returns:
    the started thread

### actionPerformed

    @Licensed
    public void actionPerformed(ActionEvent ev)

  initializes the parent component - if applicable - and calls performAction; if the parent was null, it is going to be reset at the end again, so that it gets dynamically reset on each call. Also, before `performAction(ActionEvent, Component)` is executed, this method calls `checkAccess(User)` and will show a warning as well as terminate if the access check fails (only if there was a database configured with this instance, though). Exceptions are handled by calling doh(Exception).

  Specified by:
    `actionPerformed` in interface `ActionListener`

### getFormValue

    public Object getFormValue(Form form,
                               Object defaultValue)
                        throws IOException

  Throws:
    `IOException`

### getFormValue

    public Object getFormValue(Form form,
                               ValueRetriever<?> retriever)
                        throws IOException

  Throws:
    `IOException`
  See Also:
    `FormHelper.getFormValue(Form, ValueRetriever, String)`

### add

    public boolean add(InterfaceMonitor im)

### remove

    public boolean remove(InterfaceMonitor im)

### getInterfaceMonitors

    public InterfaceMonitor[] getInterfaceMonitors()

### doh

    protected void doh(Throwable ex)

### doh

    protected void doh(Throwable ex,
                       Component parent)

  handles an Exception the common way by logging it and then displaying it to the user

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads