Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.eclipse.jface.action
Class Action  view Action download Action.java

java.lang.Object
  extended byorg.eclipse.jface.action.Action
All Implemented Interfaces:
IAction

public abstract class Action
extends java.lang.Object
implements IAction

The standard abstract implementation of an action.

Subclasses must implement the IAction.run method to carry out the action's semantics.


Field Summary
private  int accelerator
          This action's accelerator; 0 means none.
private  java.lang.String actionDefinitionId
          This action's action definition id, or null if none.
private  java.lang.String description
          This action's description, or null if none.
private  org.eclipse.jface.resource.ImageDescriptor disabledImage
          This action's disabled image, or null if none.
private  boolean enabled
          Indicates this action is enabled.
private  org.eclipse.swt.events.HelpListener helpListener
          An action's help listener, or null if none.
private  org.eclipse.jface.resource.ImageDescriptor hoverImage
          This action's hover image, or null if none.
private  java.lang.String id
          This action's id, or null if none.
private  org.eclipse.jface.resource.ImageDescriptor image
          This action's image, or null if none.
private static java.util.Map keyCodes
          Table of key codes (key type: String, value type: Integer); null if not yet initialized.
private static java.util.Map keyStrings
          Table of string representations of keys (key type: Integer, value type: String); null> if not yet initialized.
private  org.eclipse.jface.util.ListenerList listeners
          List of registered listeners (element type: IPropertyChangeListener).
private static java.lang.String LOCALIZED_ALT
           
private static java.lang.String LOCALIZED_COMMAND
           
private static java.lang.String LOCALIZED_CTRL
          The localized uppercase versions of the modifer keys.
private static java.lang.String LOCALIZED_SHIFT
           
private static java.util.Map localizedKeyCodes
          Table of key codes (key type: String, value type: Integer); null if not yet initialized.
private  java.lang.String text
          This action's text, or null if none.
private  java.lang.String toolTipText
          This action's tool tip text, or null if none.
private static IMenuCreator VAL_DROP_DOWN_MENU
           
private static java.lang.String VAL_PUSH_BTN
           
private static java.lang.Integer VAL_RADIO_BTN_OFF
           
private static java.lang.Integer VAL_RADIO_BTN_ON
           
private static java.lang.Boolean VAL_TOGGLE_BTN_OFF
           
private static java.lang.Boolean VAL_TOGGLE_BTN_ON
           
private  java.lang.Object value
          Holds the action's menu creator (an IMenuCreator) or checked state (a Boolean for toggle button, or an Integer for radio button), or null if neither have been set.
 
Fields inherited from interface org.eclipse.jface.action.IAction
AS_CHECK_BOX, AS_DROP_DOWN_MENU, AS_PUSH_BUTTON, AS_RADIO_BUTTON, AS_UNSPECIFIED, CHECKED, DESCRIPTION, ENABLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT
 
Constructor Summary
protected Action()
          Creates a new action with no text and no image.
protected Action(java.lang.String text)
          Creates a new action with the given text and no image.
protected Action(java.lang.String text, org.eclipse.jface.resource.ImageDescriptor image)
          Creates a new action with the given text and image.
protected Action(java.lang.String text, int style)
          Creates a new action with the given text and style.
 
Method Summary
 void addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
          Adds a property change listener to this action.
static java.lang.String convertAccelerator(int keyCode)
          Converts an accelerator key code to a string representation.
static int convertAccelerator(java.lang.String acceleratorText)
          Parses the given accelerator text, and converts it to an accelerator key code.
private static int convertLocalizedAccelerator(java.lang.String acceleratorText)
          Parses the given accelerator text, and converts it to an accelerator key code.
private static java.lang.String extractAcceleratorText(java.lang.String text)
          Extracts the accelerator text from the given text.
static int findKeyCode(java.lang.String token)
          Maps a standard keyboard key name to an SWT key code.
static java.lang.String findKeyString(int keyCode)
          Maps an SWT key code to a standard keyboard key name.
private static int findLocalizedKeyCode(java.lang.String token)
          Find the supplied code for a localized key.
private static int findLocalizedModifier(java.lang.String token)
          Maps the localized modifier names to a code in the same manner as #findModifier.
static int findModifier(java.lang.String token)
          Maps standard keyboard modifier key names to the corresponding SWT modifier bit.
static java.lang.String findModifierString(int keyCode)
          Returns a string representation of an SWT modifier bit (SWT.CTRL, SWT.ALT, SWT.SHIFT, and SWT.COMMAND).
protected  void firePropertyChange(org.eclipse.jface.util.PropertyChangeEvent event)
          Notifies any property change listeners that a property has changed.
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Notifies any property change listeners that a property has changed.
 int getAccelerator()
          Returns the accelerator keycode for this action.
 java.lang.String getActionDefinitionId()
          Returns the action definition id of this action.
 java.lang.String getDescription()
          Returns the action's description if it has one.
 org.eclipse.jface.resource.ImageDescriptor getDisabledImageDescriptor()
          Returns the disabled image for this action as an image descriptor.
 org.eclipse.swt.events.HelpListener getHelpListener()
          Returns a help listener for this action.
 org.eclipse.jface.resource.ImageDescriptor getHoverImageDescriptor()
          Returns the hover image for this action as an image descriptor.
 java.lang.String getId()
          Returns a unique identifier for this action, or null if it has none.
 org.eclipse.jface.resource.ImageDescriptor getImageDescriptor()
          Returns the image for this action as an image descriptor.
 IMenuCreator getMenuCreator()
          Returns the menu creator for this action.
private static java.lang.String getModifierString(int keyCode)
           
 int getStyle()
          Return this action's style.
 java.lang.String getText()
          Returns the text for this action.
 java.lang.String getToolTipText()
          Returns the tool tip text for this action.
private static void initKeyCodes()
          Initializes the internal key code table.
private static void initKeyStrings()
          Initializes the internal key string table.
private static void initLocalizedKeyCodes()
          Initializes the localized internal key code table.
private static void initLocalizedModifiers()
          Initialize the list of localized modifiers
 boolean isChecked()
          Returns the checked status of this action.
 boolean isEnabled()
          Returns whether this action is enabled.
 void notifyResult(boolean success)
          Reports the outcome of the running of this action via the IAction.RESULT 55 property.
static java.lang.String removeAcceleratorText(java.lang.String text)
          Convenience method for removing any optional accelerator text from the given string.
static java.lang.String removeMnemonics(java.lang.String text)
          Convenience method for removing any mnemonics from the given string.
 void removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
          Removes the given listener from this action.
 void run()
          The default implementation of this IAction method does nothing.
 void runWithEvent(org.eclipse.swt.widgets.Event event)
          The default implementation of this IAction method ignores the event argument, and simply calls run().
 void setAccelerator(int keycode)
           Sets the accelerator keycode that this action maps to.
 void setActionDefinitionId(java.lang.String id)
          Sets the action definition id of this action.
 void setChecked(boolean checked)
          Sets the checked status of this action.
 void setDescription(java.lang.String text)
          Sets this action's description.
 void setDisabledImageDescriptor(org.eclipse.jface.resource.ImageDescriptor newImage)
          Sets the disabled image for this action, as an image descriptor.
 void setEnabled(boolean enabled)
          Sets the enabled state of this action.
 void setHelpListener(org.eclipse.swt.events.HelpListener listener)
          Sets a help listener for this action.
 void setHoverImageDescriptor(org.eclipse.jface.resource.ImageDescriptor newImage)
          Sets the hover image for this action, as an image descriptor.
 void setId(java.lang.String id)
          Sets the unique identifier for this action.
 void setImageDescriptor(org.eclipse.jface.resource.ImageDescriptor newImage)
          Sets the image for this action, as an image descriptor.
 void setMenuCreator(IMenuCreator creator)
          Sets the menu creator for this action.
 void setText(java.lang.String text)
          Sets the text for this action.
 void setToolTipText(java.lang.String toolTipText)
          Sets the tool tip text for this action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VAL_PUSH_BTN

private static final java.lang.String VAL_PUSH_BTN
See Also:
Constant Field Values

VAL_RADIO_BTN_ON

private static final java.lang.Integer VAL_RADIO_BTN_ON

VAL_RADIO_BTN_OFF

private static final java.lang.Integer VAL_RADIO_BTN_OFF

VAL_TOGGLE_BTN_ON

private static final java.lang.Boolean VAL_TOGGLE_BTN_ON

VAL_TOGGLE_BTN_OFF

private static final java.lang.Boolean VAL_TOGGLE_BTN_OFF

VAL_DROP_DOWN_MENU

private static final IMenuCreator VAL_DROP_DOWN_MENU

keyCodes

private static java.util.Map keyCodes
Table of key codes (key type: String, value type: Integer); null if not yet initialized.

See Also:
findKeyCode(java.lang.String) 55

localizedKeyCodes

private static java.util.Map localizedKeyCodes
Table of key codes (key type: String, value type: Integer); null if not yet initialized. The key is the localalized name of the key as it appears in menus.

See Also:
findLocalizedKeyCode(java.lang.String) 55

LOCALIZED_CTRL

private static java.lang.String LOCALIZED_CTRL
The localized uppercase versions of the modifer keys.


LOCALIZED_SHIFT

private static java.lang.String LOCALIZED_SHIFT

LOCALIZED_ALT

private static java.lang.String LOCALIZED_ALT

LOCALIZED_COMMAND

private static java.lang.String LOCALIZED_COMMAND

keyStrings

private static java.util.Map keyStrings
Table of string representations of keys (key type: Integer, value type: String); null> if not yet initialized.

See Also:
findKeyString(int) 55

listeners

private org.eclipse.jface.util.ListenerList listeners
List of registered listeners (element type: IPropertyChangeListener).


text

private java.lang.String text
This action's text, or null if none.


description

private java.lang.String description
This action's description, or null if none.


id

private java.lang.String id
This action's id, or null if none.


actionDefinitionId

private java.lang.String actionDefinitionId
This action's action definition id, or null if none.


toolTipText

private java.lang.String toolTipText
This action's tool tip text, or null if none.


helpListener

private org.eclipse.swt.events.HelpListener helpListener
An action's help listener, or null if none.


image

private org.eclipse.jface.resource.ImageDescriptor image
This action's image, or null if none.


hoverImage

private org.eclipse.jface.resource.ImageDescriptor hoverImage
This action's hover image, or null if none.


disabledImage

private org.eclipse.jface.resource.ImageDescriptor disabledImage
This action's disabled image, or null if none.


value

private java.lang.Object value
Holds the action's menu creator (an IMenuCreator) or checked state (a Boolean for toggle button, or an Integer for radio button), or null if neither have been set.

The value of this field affects the value of getStyle().


accelerator

private int accelerator
This action's accelerator; 0 means none.


enabled

private boolean enabled
Indicates this action is enabled.

Constructor Detail

Action

protected Action()
Creates a new action with no text and no image.

Configure the action later using the set methods.


Action

protected Action(java.lang.String text)
Creates a new action with the given text and no image. Calls the zero-arg constructor, then setText.


Action

protected Action(java.lang.String text,
                 org.eclipse.jface.resource.ImageDescriptor image)
Creates a new action with the given text and image. Calls the zero-arg constructor, then setText and setImageDescriptor.


Action

protected Action(java.lang.String text,
                 int style)
Creates a new action with the given text and style.

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
Description copied from interface: IAction
Adds a property change listener to this action. Has no effect if an identical listener is already registered.

Specified by:
addPropertyChangeListener in interface IAction

convertLocalizedAccelerator

private static int convertLocalizedAccelerator(java.lang.String acceleratorText)
Parses the given accelerator text, and converts it to an accelerator key code. Support for localized modifiers is for backwards compatibility with 1.0. Use setAccelerator(int) to set accelerators programatically or the accelerator tag in action definitions in plugin.xml.


convertAccelerator

public static int convertAccelerator(java.lang.String acceleratorText)
Parses the given accelerator text, and converts it to an accelerator key code.


convertAccelerator

public static java.lang.String convertAccelerator(int keyCode)
Converts an accelerator key code to a string representation.


getModifierString

private static java.lang.String getModifierString(int keyCode)

extractAcceleratorText

private static java.lang.String extractAcceleratorText(java.lang.String text)
Extracts the accelerator text from the given text. Returns null if there is no accelerator text, and the empty string if there is no text after the accelerator delimeter (tab or '@').


findKeyCode

public static int findKeyCode(java.lang.String token)
Maps a standard keyboard key name to an SWT key code. Key names are converted to upper case before comparison. If the key name is a single letter, for example "S", its character code is returned.

The following key names are known (case is ignored):

  • "BACKSPACE"
  • "TAB"
  • "RETURN"
  • "ENTER"
  • "ESC"
  • "ESCAPE"
  • "DELETE"
  • "SPACE"
  • "ARROW_UP", "ARROW_DOWN", "ARROW_LEFT", and "ARROW_RIGHT"
  • "PAGE_UP" and "PAGE_DOWN"
  • "HOME"
  • "END"
  • "INSERT"
  • "F1", "F2" through "F12"


findLocalizedKeyCode

private static int findLocalizedKeyCode(java.lang.String token)
Find the supplied code for a localized key. As #findKeyCode but localized to the current locale. Support for localized modifiers is for backwards compatibility with 1.0. Use setAccelerator(int) to set accelerators programatically or the accelerator tag in action definitions in plugin.xml.


findKeyString

public static java.lang.String findKeyString(int keyCode)
Maps an SWT key code to a standard keyboard key name. The key code is stripped of modifiers (SWT.CTRL, SWT.ALT, SWT.SHIFT, and SWT.COMMAND). If the key code is not an SWT code (for example if it a key code for the key 'S'), a string containing a character representation of the key code is returned.

Since:
2.0

findModifier

public static int findModifier(java.lang.String token)
Maps standard keyboard modifier key names to the corresponding SWT modifier bit. The following modifier key names are recognized (case is ignored): "CTRL", "SHIFT", "ALT", and "COMMAND". The given modifier key name is converted to upper case before comparison.


findLocalizedModifier

private static int findLocalizedModifier(java.lang.String token)
Maps the localized modifier names to a code in the same manner as #findModifier. Support for localized modifiers is for backwards compatibility with 1.0. Use setAccelerator(int) to set accelerators programatically or the accelerator tag in action definitions in plugin.xml.


initLocalizedModifiers

private static void initLocalizedModifiers()
Initialize the list of localized modifiers


findModifierString

public static java.lang.String findModifierString(int keyCode)
Returns a string representation of an SWT modifier bit (SWT.CTRL, SWT.ALT, SWT.SHIFT, and SWT.COMMAND). Returns null if the key code is not an SWT modifier bit.

Since:
2.0

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Notifies any property change listeners that a property has changed. Only listeners registered at the time this method is called are notified. This method avoids creating an event object if there are no listeners registered, but calls firePropertyChange(PropertyChangeEvent) if there are.


firePropertyChange

protected void firePropertyChange(org.eclipse.jface.util.PropertyChangeEvent event)
Notifies any property change listeners that a property has changed. Only listeners registered at the time this method is called are notified.


getAccelerator

public int getAccelerator()
Description copied from interface: IAction
Returns the accelerator keycode for this action. The result is the bit-wise OR of zero or more modifier masks and a key, as explained in MenuItem.getAccelerator.

Specified by:
getAccelerator in interface IAction

getActionDefinitionId

public java.lang.String getActionDefinitionId()
Description copied from interface: IAction
Returns the action definition id of this action.

Specified by:
getActionDefinitionId in interface IAction

getDescription

public java.lang.String getDescription()
Description copied from interface: IAction
Returns the action's description if it has one. Otherwise it returns getToolTipText().

Specified by:
getDescription in interface IAction

getDisabledImageDescriptor

public org.eclipse.jface.resource.ImageDescriptor getDisabledImageDescriptor()
Description copied from interface: IAction
Returns the disabled image for this action as an image descriptor.

This method is associated with the IMAGE property; property change events are reported when its value changes.

Specified by:
getDisabledImageDescriptor in interface IAction

getHelpListener

public org.eclipse.swt.events.HelpListener getHelpListener()
Description copied from interface: IAction
Returns a help listener for this action.

Specified by:
getHelpListener in interface IAction

getHoverImageDescriptor

public org.eclipse.jface.resource.ImageDescriptor getHoverImageDescriptor()
Description copied from interface: IAction
Returns the hover image for this action as an image descriptor.

Hover images will be used on platforms that support changing the image when the user hovers over the item. This method is associated with the IMAGE property; property change events are reported when its value changes.

Specified by:
getHoverImageDescriptor in interface IAction

getId

public java.lang.String getId()
Description copied from interface: IAction
Returns a unique identifier for this action, or null if it has none.

Specified by:
getId in interface IAction

getImageDescriptor

public org.eclipse.jface.resource.ImageDescriptor getImageDescriptor()
Description copied from interface: IAction
Returns the image for this action as an image descriptor.

This method is associated with the IMAGE property; property change events are reported when its value changes.

Specified by:
getImageDescriptor in interface IAction

getMenuCreator

public IMenuCreator getMenuCreator()
Description copied from interface: IAction
Returns the menu creator for this action.

Specified by:
getMenuCreator in interface IAction

getStyle

public int getStyle()
Description copied from interface: IAction
Return this action's style.

Specified by:
getStyle in interface IAction

getText

public java.lang.String getText()
Description copied from interface: IAction
Returns the text for this action.

This method is associated with the TEXT property; property change events are reported when its value changes.

Specified by:
getText in interface IAction

getToolTipText

public java.lang.String getToolTipText()
Description copied from interface: IAction
Returns the tool tip text for this action.

This method is associated with the TOOL_TIP_TEXT property; property change events are reported when its value changes.

Specified by:
getToolTipText in interface IAction

initKeyCodes

private static void initKeyCodes()
Initializes the internal key code table.


initLocalizedKeyCodes

private static void initLocalizedKeyCodes()
Initializes the localized internal key code table.


initKeyStrings

private static void initKeyStrings()
Initializes the internal key string table.


isChecked

public boolean isChecked()
Description copied from interface: IAction
Returns the checked status of this action. Applicable only if the style is AS_CHECK_BOX or AS_RADIO_BUTTON.

This method is associated with the CHECKED property; property change events are reported when its value changes.

Specified by:
isChecked in interface IAction

isEnabled

public boolean isEnabled()
Description copied from interface: IAction
Returns whether this action is enabled.

This method is associated with the ENABLED property; property change events are reported when its value changes.

Specified by:
isEnabled in interface IAction

removeAcceleratorText

public static java.lang.String removeAcceleratorText(java.lang.String text)
Convenience method for removing any optional accelerator text from the given string. The accelerator text appears at the end of the text, and is separated from the main part by a single tab character '\t'.


removeMnemonics

public static java.lang.String removeMnemonics(java.lang.String text)
Convenience method for removing any mnemonics from the given string. For example, removeMnemonics("&Open") will return "Open".

Since:
3.0

removePropertyChangeListener

public void removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener listener)
Description copied from interface: IAction
Removes the given listener from this action. Has no effect if an identical listener is not registered.

Specified by:
removePropertyChangeListener in interface IAction

run

public void run()
The default implementation of this IAction method does nothing. Subclasses should override this method if they do not need information from the triggering event, or override runWithEvent(Event) if they do.

Specified by:
run in interface IAction

runWithEvent

public void runWithEvent(org.eclipse.swt.widgets.Event event)
The default implementation of this IAction method ignores the event argument, and simply calls run(). Subclasses should override this method if they need information from the triggering event, or override run() if not.

Specified by:
runWithEvent in interface IAction
Since:
2.0

setActionDefinitionId

public void setActionDefinitionId(java.lang.String id)
Description copied from interface: IAction
Sets the action definition id of this action.

Specified by:
setActionDefinitionId in interface IAction

setChecked

public void setChecked(boolean checked)
Description copied from interface: IAction
Sets the checked status of this action. Applicable for the styles AS_CHECK_BOX or AS_RADIO_BUTTON.

Fires a property change event for the CHECKED property if the checked status actually changes as a consequence.

Specified by:
setChecked in interface IAction

setDescription

public void setDescription(java.lang.String text)
Description copied from interface: IAction
Sets this action's description. Typically the description is shown as a (longer) help text in the status line.

Fires a property change event for the DESCRIPTION property if the description actually changes as a consequence.

Specified by:
setDescription in interface IAction

setDisabledImageDescriptor

public void setDisabledImageDescriptor(org.eclipse.jface.resource.ImageDescriptor newImage)
Description copied from interface: IAction
Sets the disabled image for this action, as an image descriptor.

Disabled images will be used on platforms that support changing the image when the item is disabled.Fires a property change event for the IMAGE property if the image actually changes as a consequence.

Specified by:
setDisabledImageDescriptor in interface IAction

setEnabled

public void setEnabled(boolean enabled)
Description copied from interface: IAction
Sets the enabled state of this action.

When an action is in the enabled state, the control associated with it is active; triggering it will end up inkoking this action's run method.

Fires a property change event for the ENABLED property if the enabled state actually changes as a consequence.

Specified by:
setEnabled in interface IAction

setHelpListener

public void setHelpListener(org.eclipse.swt.events.HelpListener listener)
Description copied from interface: IAction
Sets a help listener for this action.

Specified by:
setHelpListener in interface IAction

setHoverImageDescriptor

public void setHoverImageDescriptor(org.eclipse.jface.resource.ImageDescriptor newImage)
Description copied from interface: IAction
Sets the hover image for this action, as an image descriptor.

Hover images will be used on platforms that support changing the image when the user hovers over the item.Fires a property change event for the IMAGE property if the image actually changes as a consequence.

Specified by:
setHoverImageDescriptor in interface IAction

setId

public void setId(java.lang.String id)
Description copied from interface: IAction
Sets the unique identifier for this action. This is used to identify actions when added to a contribution manager. It should be set when the action is created. It should not be modified once the action is part of an action contribution item.

Specified by:
setId in interface IAction

setImageDescriptor

public void setImageDescriptor(org.eclipse.jface.resource.ImageDescriptor newImage)
Description copied from interface: IAction
Sets the image for this action, as an image descriptor.

Fires a property change event for the IMAGE property if the image actually changes as a consequence.

Specified by:
setImageDescriptor in interface IAction

setMenuCreator

public void setMenuCreator(IMenuCreator creator)
Sets the menu creator for this action.

Note that if this method is called, it overrides the check status.

Specified by:
setMenuCreator in interface IAction

setText

public void setText(java.lang.String text)
Sets the text for this action.

Fires a property change event for the TEXT property if the text actually changes as a consequence.

The accelerator is identified by the last index of a tab character. If there are no tab characters, then it is identified by the last index of a '@' character. If neither, then there is no accelerator text. Note that if you want to insert a '@' character into the text (but no accelerator, you can simply insert a '@' or a tab at the end of the text.

Specified by:
setText in interface IAction

setToolTipText

public void setToolTipText(java.lang.String toolTipText)
Sets the tool tip text for this action.

Fires a property change event for the TOOL_TIP_TEXT property if the tool tip text actually changes as a consequence.

Specified by:
setToolTipText in interface IAction

setAccelerator

public void setAccelerator(int keycode)
Description copied from interface: IAction

Sets the accelerator keycode that this action maps to. This is a bitwise OR of zero or more SWT key modifier masks (i.e. SWT.CTRL or SWT.ALT) and a character code. For example, for Ctrl+Z, use SWT.CTRL | 'Z'. Use 0 for no accelerator.

This method should no longer be used for actions in the Eclipse workbench. IWorkbenchCommandSupport and IWorkbenchContextSupport provide all the functionality required for key bindings. If you set an accelerator using this method, then it will not work in the workbench if it conflicts any existing key binding, or if there is a different key binding defined for this action's definition id. The definition id should be used instead -- referring to the command in the workbench from which the key binding should be retrieved.

Specified by:
setAccelerator in interface IAction

notifyResult

public final void notifyResult(boolean success)
Reports the outcome of the running of this action via the IAction.RESULT 55 property.

Since:
3.0