com.swfm.mica.core
Class MiAction

java.lang.Object
  extended bycom.swfm.mica.core.MiAction
All Implemented Interfaces:
MiiAction, MiiActionNames, MiiActionTypes
Direct Known Subclasses:
MiActionCallback, MiEditorCommandsHandler

public class MiAction
extends java.lang.Object
implements MiiAction, MiiActionTypes, MiiActionNames

An action has a number of valid action types and an action handler. When assigned to a MiPart (see MiPart#appendActionHandler) this action waits for one of it's valid action types to be dispatched to the MiPart. When one of these valid action types occurs, the MiPart calls this action's action handler with this action as the parameter. Action types consist of two parts. The top 4 bits are reserved for the action's phases bits. The bottom 28 bits are reserved for the action's action type, which is not a mask. This approach allows a single action type and any combination of the 4 action phases to be encoded into a sinlge integer (int). For example: MiiAction dragAndDropActionEvent = new MiAction(this, Mi_DATA_IMPORT_ACTION | Mi_REQUEST_ACTION_PHASE | Mi_EXECUTE_ACTION_PHASE); This action, when assigned to a MiPart, will have it's action handler called whenever a Mi_DATA_IMPORT_ACTION action in a Mi_REQUEST_ACTION_PHASE or a Mi_EXECUTE_ACTION_PHASE is generated.

Version:
%I% %G%
Author:
Michael L. Davis
See Also:
MiActionManager

Field Summary
     
Constructor Summary
MiAction(MiiActionHandler handler, int validActionType)
          Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action type occurs in any MiPart this action is assigned to.
MiAction(MiiActionHandler handler, int[] validActionTypes, java.lang.Object userInfo)
          Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.
MiAction(MiiActionHandler handler, int validActionType1, int validActionType2)
          Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.
MiAction(MiiActionHandler handler, int validActionType1, int validActionType2, int validActionType3)
          Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.
MiAction(MiiActionHandler handler, int validActionType1, int validActionType2, int validActionType3, java.lang.Object userInfo)
          Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.
MiAction(MiiActionHandler handler, int validActionType1, int validActionType2, java.lang.Object userInfo)
          Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.
MiAction(MiiActionHandler handler, int validActionType, java.lang.Object userInfo)
          Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action type occurs in any MiPart this action is assigned to.
 
Method Summary
 void addValidActions(MiiAction actions)
          Adds the valid action types of the given action to the valid action types of this action.
 void addValidActionsRequestedFromPartsOfObserved(MiiAction actions)
          Adds the valid action types of the given action to the valid action types of this action if they are requested from the parts of the observed MiPart.
 MiiActionHandler getActionHandler()
          Gets the action handler this action will be dispatched to.
 MiPart getActionSource()
          Gets the MiPart that originally generated the action.
static java.lang.String getActionSpec(int actionType)
          Gets the textual description of the given action type suitable for parsing later into the given type.
static java.lang.String getActionString(int actionType)
          Gets the textual description of the given action type.
 java.lang.Object getActionSystemInfo()
          Gets the system information field of this action.
 int getActionType()
          Gets the actual type of this dispatched action.
 java.lang.Object getActionUserInfo()
          Gets the user information field of this action.
 int getNumberOfResources()
          Gets the number of resources assigned to this MiPart.
 MiPart getObservedObject()
          Gets the MiPart that dispatched the action to the MiiActionHandler.
 int getPhase()
          Gets the phase of this dispatched action.
 java.lang.Object getResource(java.lang.String name)
          Gets the value of the given named resource.
 java.lang.String getResourceName(int index)
          Gets the name of the ith resource assigned to this MiPart.
 java.lang.String getValidActionsString()
          For debug, gets a text string describing the action types that this action is watching for/handling.
 boolean hasActionType(int actionType)
          Gets whether the actual type of this dispatched action is the same as the given type.
 boolean isInterestedInActionsOfPartsOfObserved()
          Gets whether this action is interested in actions of the parts of the MiPart this action is assigned to.
 boolean isPhase(int phase)
          Gets whether the given phase is the phase of this dispatched action.
 boolean isValidActionType(int actionType)
          Gets whether given action type is an action type for which this action will be dispatched to it's action handler.
 boolean isVetoed()
          Gets whether this action, in the request phase, is saying no to the request.
 boolean processAction(MiiAction action)
          Processes the given action (probably _this_ MiAction) Default behavior is to call this MiAction's registered action handler.
 void removeResource(java.lang.String name)
          Removes the named resource.
 void setActionHandler(MiiActionHandler handler)
          Sets the action handler this action will be dispatched to.
 void setActionSource(MiPart source)
          Sets the MiPart that originally generated the action.
 void setActionSystemInfo(java.lang.Object info)
          Sets the system information field of this action.
 void setActionType(int actionType)
          Sets the actual type of this dispatched action.
 void setActionUserInfo(java.lang.Object info)
          Sets the user information field of this action.
 void setObservedObject(MiPart observed)
          Sets the MiPart that dispatched the action to the MiiActionHandler.
 void setResource(java.lang.String name, java.lang.Object value)
          Adds (if necessary) and sets the given named resource to the given value.
 void setVetoed(boolean flag)
          Sets whether this action, in the request phase, is saying no to the request.
 java.lang.String toString()
          Gets the textual description of action type of this action.
static int typeFromString(java.lang.String spec)
          Gets the action corresponding to the given textual description.
 void veto()
          Specifies that this action, in the request phase, is saying no to the request.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MiAction

public MiAction(MiiActionHandler handler,
                int validActionType)
Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action type occurs in any MiPart this action is assigned to.

Parameters:
handler - the action handler for this action
validActionType - the action type for this action

MiAction

public MiAction(MiiActionHandler handler,
                int validActionType,
                java.lang.Object userInfo)
Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action type occurs in any MiPart this action is assigned to.

Parameters:
handler - the action handler for this action
validActionType - the action type for this action
userInfo - the user information for this action

MiAction

public MiAction(MiiActionHandler handler,
                int validActionType1,
                int validActionType2)
Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.

Parameters:
handler - the action handler for this action
validActionType1 - an action type for this action
validActionType2 - an action type for this action

MiAction

public MiAction(MiiActionHandler handler,
                int validActionType1,
                int validActionType2,
                java.lang.Object userInfo)
Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.

Parameters:
handler - the action handler for this action
validActionType1 - an action type for this action
validActionType2 - an action type for this action
userInfo - the user information for this action

MiAction

public MiAction(MiiActionHandler handler,
                int validActionType1,
                int validActionType2,
                int validActionType3)
Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.

Parameters:
handler - the action handler for this action
validActionType1 - an action type for this action
validActionType2 - an action type for this action
validActionType3 - an action type for this action

MiAction

public MiAction(MiiActionHandler handler,
                int validActionType1,
                int validActionType2,
                int validActionType3,
                java.lang.Object userInfo)
Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.

Parameters:
handler - the action handler for this action
validActionType1 - an action type for this action
validActionType2 - an action type for this action
validActionType3 - an action type for this action
userInfo - the user information for this action

MiAction

public MiAction(MiiActionHandler handler,
                int[] validActionTypes,
                java.lang.Object userInfo)
Constructs a new MiAction which will dispatch itself to the given action handler whenever the given action types occur in any MiPart this action is assigned to.

Parameters:
handler - the action handler for this action
validActionTypes - the action types for this action
userInfo - the user information for this action
Method Detail

addValidActionsRequestedFromPartsOfObserved

public void addValidActionsRequestedFromPartsOfObserved(MiiAction actions)
Adds the valid action types of the given action to the valid action types of this action if they are requested from the parts of the observed MiPart.

Parameters:
actions - the action whose valid action types to add to the valid action types of this action

addValidActions

public void addValidActions(MiiAction actions)
Adds the valid action types of the given action to the valid action types of this action.

Parameters:
actions - the action whose valid action types to add to the valid action types of this action

processAction

public boolean processAction(MiiAction action)
Processes the given action (probably _this_ MiAction) Default behavior is to call this MiAction's registered action handler. This is not currently used by Mica.

Parameters:
action - the action to process
Returns:
true if it is OK to send action to the next action handler false if it is NOT OK to send action to the next action handler

setActionSource

public void setActionSource(MiPart source)
Sets the MiPart that originally generated the action. This is set automatically by Mica whenever the action is dispatched.

Specified by:
setActionSource in interface MiiAction
Parameters:
source - the part that generated the action

getActionSource

public MiPart getActionSource()
Gets the MiPart that originally generated the action.

Specified by:
getActionSource in interface MiiAction
Returns:
the part that generated the action

setObservedObject

public void setObservedObject(MiPart observed)
Sets the MiPart that dispatched the action to the MiiActionHandler. This is set automatically by Mica whenever the action is dispatched.

Specified by:
setObservedObject in interface MiiAction
Parameters:
observed - the part that dispatched the action

getObservedObject

public MiPart getObservedObject()
Gets the MiPart that dispatched the action to the MiiActionHandler.

Specified by:
getObservedObject in interface MiiAction
Returns:
the part that dispatched the action

isInterestedInActionsOfPartsOfObserved

public boolean isInterestedInActionsOfPartsOfObserved()
Gets whether this action is interested in actions of the parts of the MiPart this action is assigned to. Use Mi_ACTIONS_OF_PARTS_OF_OBSERVED when specifying valid actions if this behavior is desired.

Specified by:
isInterestedInActionsOfPartsOfObserved in interface MiiAction
Returns:
true if interested

setActionHandler

public void setActionHandler(MiiActionHandler handler)
Sets the action handler this action will be dispatched to.

Specified by:
setActionHandler in interface MiiAction
Parameters:
handler - the action handler to send this action to

getActionHandler

public MiiActionHandler getActionHandler()
Gets the action handler this action will be dispatched to.

Specified by:
getActionHandler in interface MiiAction
Returns:
the action handler to send this action to

setActionType

public void setActionType(int actionType)
Sets the actual type of this dispatched action. This type is one of the valid types of this action. MiiActionHandler. This is set automatically by Mica whenever the action is dispatched.

Specified by:
setActionType in interface MiiAction
Returns:
the part that dispatched the action
See Also:
isValidActionType(int)

getActionType

public int getActionType()
Gets the actual type of this dispatched action. Includes action and phase information.

Specified by:
getActionType in interface MiiAction
Returns:
the action type of this action
See Also:
isValidActionType(int)

hasActionType

public boolean hasActionType(int actionType)
Gets whether the actual type of this dispatched action is the same as the given type. Includes action and phase information.

Specified by:
hasActionType in interface MiiAction
Returns:
true if the given action type is the same action type this action has.
See Also:
getActionType(), isValidActionType(int)

setActionUserInfo

public void setActionUserInfo(java.lang.Object info)
Sets the user information field of this action.

Specified by:
setActionUserInfo in interface MiiAction
Parameters:
info - the information supplied by the programmer.
See Also:
getActionUserInfo()

getActionUserInfo

public java.lang.Object getActionUserInfo()
Gets the user information field of this action.

Specified by:
getActionUserInfo in interface MiiAction
Returns:
the information supplied by the programmer.
See Also:
setActionUserInfo(java.lang.Object)

setActionSystemInfo

public void setActionSystemInfo(java.lang.Object info)
Sets the system information field of this action. This used when the MiPart that generated the action thinks additional information is required to completely describe the action. For example the Mi_COPY_ACTION action is generated by a MiPart that is being copied and has system info equal to the new MiPart copy. This is set automatically by Mica whenever the action is dispatched, if the specific action need it.

Specified by:
setActionSystemInfo in interface MiiAction
Parameters:
info - the information supplied by the generator of the action or null.
See Also:
setActionUserInfo(java.lang.Object), getActionSystemInfo()

getActionSystemInfo

public java.lang.Object getActionSystemInfo()
Gets the system information field of this action. This used when the MiPart that generated the action thinks additional information is required to completely describe the action. For example the Mi_COPY_ACTION action is generated by a MiPart that is being copied and has system info equal to the new MiPart copy.

Specified by:
getActionSystemInfo in interface MiiAction
Returns:
the information supplied by the generator of the action or null.
See Also:
getActionUserInfo(), setActionSystemInfo(java.lang.Object)

isValidActionType

public boolean isValidActionType(int actionType)
Gets whether given action type is an action type for which this action will be dispatched to it's action handler.

Specified by:
isValidActionType in interface MiiAction
Returns:
true if the given action type is a valid action type or this action
See Also:
isValidActionType(int)

isPhase

public boolean isPhase(int phase)
Gets whether the given phase is the phase of this dispatched action. Possible values are: Mi_REQUEST_ACTION_PHASE Mi_CANCEL_ACTION_PHASE Mi_COMMIT_ACTION_PHASE Mi_CANCEL_ACTION_PHASE

Specified by:
isPhase in interface MiiAction
Parameters:
phase - the possible phase of this action
Returns:
true if the given phase equals the current phase of this action

getPhase

public int getPhase()
Gets the phase of this dispatched action. Possible values are: Mi_REQUEST_ACTION_PHASE Mi_CANCEL_ACTION_PHASE Mi_COMMIT_ACTION_PHASE Mi_CANCEL_ACTION_PHASE

Specified by:
getPhase in interface MiiAction
Returns:
the phase of this action
See Also:
setResource(java.lang.String, java.lang.Object)

veto

public void veto()
Specifies that this action, in the request phase, is saying no to the request.

Specified by:
veto in interface MiiAction

isVetoed

public boolean isVetoed()
Gets whether this action, in the request phase, is saying no to the request.

Specified by:
isVetoed in interface MiiAction
Returns:
true if vetoed

setVetoed

public void setVetoed(boolean flag)
Sets whether this action, in the request phase, is saying no to the request.

Specified by:
setVetoed in interface MiiAction
Parameters:
flag - true if vetoed

setResource

public void setResource(java.lang.String name,
                        java.lang.Object value)
Adds (if necessary) and sets the given named resource to the given value. Every action can have an unlimited number of programmer-specified resources.

Specified by:
setResource in interface MiiAction
Parameters:
name - the resource name
value - the resource value (non-null)
See Also:
getResource(java.lang.String)

getResource

public java.lang.Object getResource(java.lang.String name)
Gets the value of the given named resource. If to the given value. Every action can have an unlimited number of programmer-specified resources.

Specified by:
getResource in interface MiiAction
Parameters:
name - the resource name
See Also:
setResource(java.lang.String, java.lang.Object)

removeResource

public void removeResource(java.lang.String name)
Removes the named resource. This is the same as setting the resource's value to null.

Parameters:
name - the name of the resource
See Also:
setResource(java.lang.String, java.lang.Object), getResource(java.lang.String)

getNumberOfResources

public int getNumberOfResources()
Gets the number of resources assigned to this MiPart.

Returns:
the number of resources
See Also:
getResourceName(int)

getResourceName

public java.lang.String getResourceName(int index)
Gets the name of the ith resource assigned to this MiPart.

Parameters:
index - the index of the resource
Returns:
the name of the resource
Throws:
java.lang.IllegalArgumentException - If index is out of range.
See Also:
getNumberOfResources()

getActionString

public static java.lang.String getActionString(int actionType)
Gets the textual description of the given action type. This describes both the phase and the type of the given action type.

Parameters:
actionType - the action to describe
Returns:
the description
See Also:
getActionSpec(int), #getActionPhasesString, #getActionTypesString

getActionSpec

public static java.lang.String getActionSpec(int actionType)
Gets the textual description of the given action type suitable for parsing later into the given type. action type.

Parameters:
actionType - the action to describe
Returns:
the description
See Also:
getActionString(int)

toString

public java.lang.String toString()
Gets the textual description of action type of this action. This is only meaningful while this action is being dispatched.

Returns:
the description
See Also:
getActionString(int)

typeFromString

public static int typeFromString(java.lang.String spec)
                          throws java.lang.IllegalArgumentException
Gets the action corresponding to the given textual description.

Parameters:
spec - the description
Returns:
the action type
Throws:
java.lang.IllegalArgumentException
See Also:
getActionString(int)

getValidActionsString

public java.lang.String getValidActionsString()
For debug, gets a text string describing the action types that this action is watching for/handling. The toString() method returns a string describing the current action type.

Specified by:
getValidActionsString in interface MiiAction
Returns:
a text string describing the valid action types for this action