Action Handlers

To solve the Action problems we extend it, and create the ActionHandler interface.

BaseAction
« static »
- actions : List
- actionHandler : ActionHandler
+ BaseAction(int)
+ BaseAction(int, String)
+ BaseAction(int, String, int, int, int)
+ getID() : int
+ getName() : String
+ actionPerformed(ActionEvent)
« static »
+ setActionHandler(ActionHandler)
+ setEnabled(int, boolean)
« Interface »
ActionHandler
+ performAction(BaseAction, ActionEvent)

LookupManager
+ LookupManager(MainScreen)
+ performAction(BaseAction, ActionEvent)
PartsLookupManager
+ PartsLookupManager(LookupManager)
+ performAction(BaseAction, ActionEvent)
public class BaseAction extends AbstractAction {

    // static members
    private static List actions = new LinkedList();
    private static ActionHandler actionHandler = null;

    public static void setEnabled(int id, boolean enabled) {
        Iterator i = actions.iterator();

        while (i.hasNext()) {
            BaseAction action = (BaseAction) i.next();
            if (action.getID() == id) {
                action.setEnabled(enabled);
            }
        }
    }

    public static void setActionHandler(ActionHandler handler) {
        actionHandler = handler;
    }

    // instance members
    public void actionPerformed(ActionEvent event) {
        actionHandler.performAction(this, event);
    }

    public BaseAction(int id, String name) {
        super(name);
        this.id = id;
        actions.add(this);
    }
}