Class Action
- All Implemented Interfaces:
IAction
- Direct Known Subclasses:
AddMemoryRenderingActionDelegate,BaseSelectionListenerAction,BooleanPropertyAction,ChangeCompareFilterPropertyAction,ChangePropertyAction,ClearOutputAction,CloseConsoleAction,org.eclipse.ui.internal.actions.CommandAction,DebugCommandAction,FileBufferOperationAction,FrameAction,GlobalBuildAction,GotoLastEditPositionAction,GotoNextEditPositionAction,LaunchAction,LaunchAsAction,LaunchShortcutsAction,MergeViewerAction,NavigationAction,NewExampleAction,NewProjectAction,NewWizardAction,NewWizardDropDownAction,OpenCheatSheetAction,OpenInNewWindowAction,OpenLaunchDialogAction,OpenPerspectiveAction,OpenPreferencesAction,OperationHistoryActionHandler,PartEventAction,PerspectiveAction,PinPropertySheetAction,PluginAction,QuickStartAction,ResourceAction,RulerBreakpointAction,RunToLineAction,SelectionProviderAction,TextEditorPropertyAction,TextNavigationAction,TextViewerAction,ToggleBreakpointAction,ViewPreferencesAction
Subclasses must implement the IAction.run method to carry out
the action's semantics.
-
Field Summary
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, HANDLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAction()Creates a new action with no text and no image.protectedCreates a new action with the given text and no image.protectedCreates a new action with the given text and style.protectedAction(String text, ImageDescriptor image) Creates a new action with the given text and image. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertAccelerator(int keyCode) Converts an accelerator key code to a string representation.static intconvertAccelerator(String acceleratorText) Parses the given accelerator text, and converts it to an accelerator key code.static intfindKeyCode(String token) Maps a standard keyboard key name to an SWT key code.static StringfindKeyString(int keyCode) Maps an SWT key code to a standard keyboard key name.static intfindModifier(String token) Maps standard keyboard modifier key names to the corresponding SWT modifier bit.static StringfindModifierString(int keyCode) Returns a string representation of an SWT modifier bit (SWT.CTRL, SWT.ALT, SWT.SHIFT, and SWT.COMMAND).intReturns the accelerator keycode for this action.Returns the action definition id of this action.Returns the action's description if it has one.Returns the disabled image for this action as an image descriptor.Returns a help listener for this action.Returns the hover image for this action as an image descriptor.getId()Returns a unique identifier for this action, ornullif it has none.Returns the image for this action as an image descriptor.Returns the menu creator for this action.intgetStyle()Return this action's style.getText()Returns the text for this action.Returns the tool tip text for this action.booleanReturns the checked status of this action.booleanReturns whether this action is enabled.booleanReturns whether this action is handled.final voidnotifyResult(boolean success) Reports the outcome of the running of this action via theIAction.RESULTproperty.static StringremoveAcceleratorText(String text) Convenience method for removing any optional accelerator text from the given string.static StringremoveMnemonics(String text) Convenience method for removing any mnemonics from the given string.voidrun()The default implementation of thisIActionmethod does nothing.voidrunWithEvent(Event event) The default implementation of thisIActionmethod ignores the event argument, and simply callsrun().voidsetAccelerator(int keycode) Sets the accelerator keycode that this action maps to.voidSets the action definition id of this action.voidsetChecked(boolean checked) Sets the checked status of this action.voidsetDescription(String text) Sets this action's description.voidsetDisabledImageDescriptor(ImageDescriptor newImage) Sets the disabled image for this action, as an image descriptor.voidsetEnabled(boolean enabled) Sets the enabled state of this action.voidsetHelpListener(HelpListener listener) Sets a help listener for this action.voidsetHoverImageDescriptor(ImageDescriptor newImage) Sets the hover image for this action, as an image descriptor.voidSets the unique identifier for this action.voidsetImageDescriptor(ImageDescriptor newImage) Sets the image for this action, as an image descriptor.voidsetMenuCreator(IMenuCreator creator) Sets the menu creator for this action.voidSets the text for this action.voidsetToolTipText(String toolTipText) Sets the tool tip text for this action.Methods inherited from class org.eclipse.jface.action.AbstractAction
addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListenerMethods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
-
Constructor Details
-
Action
protected Action()Creates a new action with no text and no image.Configure the action later using the set methods.
-
Action
Creates a new action with the given text and no image. Calls the zero-arg constructor, thensetText.- Parameters:
text- the string used as the text for the action, ornullif there is no text- See Also:
-
Action
Creates a new action with the given text and image. Calls the zero-arg constructor, thensetTextandsetImageDescriptor.- Parameters:
text- the action's text, ornullif there is no textimage- the action's image, ornullif there is no image- See Also:
-
Action
Creates a new action with the given text and style.- Parameters:
text- the action's text, ornullif there is no textstyle- one ofAS_PUSH_BUTTON,AS_CHECK_BOX,AS_DROP_DOWN_MENU,AS_RADIO_BUTTON, andAS_UNSPECIFIED.
-
-
Method Details
-
convertAccelerator
Converts an accelerator key code to a string representation.- Parameters:
keyCode- the key code to be translated- Returns:
- a string representation of the key code
-
convertAccelerator
Parses the given accelerator text, and converts it to an accelerator key code.- Parameters:
acceleratorText- the accelerator text- Returns:
- the SWT key code, or 0 if there is no accelerator
-
findKeyCode
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"
- Parameters:
token- the key name- Returns:
- the SWT key code,
-1if no match was found - See Also:
-
findKeyString
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.- Parameters:
keyCode- the key code to be translated- Returns:
- the string representation of the key code
- Since:
- 2.0
- See Also:
-
findModifier
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.- Parameters:
token- the modifier key name- Returns:
- the SWT modifier bit, or
0if no match was found - See Also:
-
findModifierString
Returns a string representation of an SWT modifier bit (SWT.CTRL, SWT.ALT, SWT.SHIFT, and SWT.COMMAND). Returnsnullif the key code is not an SWT modifier bit.- Parameters:
keyCode- the SWT modifier bit to be translated- Returns:
- the string representation of the SWT modifier bit, or
nullif the key code was not an SWT modifier bit - Since:
- 2.0
- See Also:
-
removeAcceleratorText
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 the last tab character'\t'(or the last'@'if there is no tab).- Parameters:
text- the text- Returns:
- the text sans accelerator
-
removeMnemonics
Convenience method for removing any mnemonics from the given string. For example,removeMnemonics("&Open")will return"Open".- Parameters:
text- the text- Returns:
- the text sans mnemonics
- Since:
- 3.0
-
getAccelerator
public int getAccelerator()Description copied from interface:IActionReturns the accelerator keycode for this action. The result is the bit-wise OR of zero or more modifier masks and a key, as explained inMenuItem.getAccelerator.- Returns:
- the accelerator keycode
- See Also:
-
getActionDefinitionId
Description copied from interface:IActionReturns the action definition id of this action.- Returns:
- the action definition id of this action, or
nullif none
-
getDescription
Description copied from interface:IActionReturns the action's description if it has one. Otherwise it returnsgetToolTipText().- Returns:
- a description for the action; may be
null
-
getDisabledImageDescriptor
Description copied from interface:IActionReturns the disabled image for this action as an image descriptor.This method is associated with the
IMAGEproperty; property change events are reported when its value changes.- Returns:
- the image, or
nullif this action has no image - See Also:
-
getHelpListener
Description copied from interface:IActionReturns a help listener for this action.- Returns:
- a help listener for this action
-
getHoverImageDescriptor
Description copied from interface:IActionReturns 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
IMAGEproperty; property change events are reported when its value changes.- Returns:
- the image, or
nullif this action has no image - See Also:
-
getId
Description copied from interface:IActionReturns a unique identifier for this action, ornullif it has none.- Returns:
- the action id, or
nullif none
-
getImageDescriptor
Description copied from interface:IActionReturns the image for this action as an image descriptor.This method is associated with the
IMAGEproperty; property change events are reported when its value changes.- Returns:
- the image, or
nullif this action has no image - See Also:
-
getMenuCreator
Description copied from interface:IActionReturns the menu creator for this action.- Returns:
- the menu creator, or
nullif none
-
getStyle
public int getStyle()Description copied from interface:IActionReturn this action's style.- Returns:
- one of
AS_PUSH_BUTTON,AS_CHECK_BOX,AS_RADIO_BUTTONandAS_DROP_DOWN_MENU.
-
getText
Description copied from interface:IActionReturns the text for this action.This method is associated with the
TEXTproperty; property change events are reported when its value changes.- Returns:
- the text, or
nullif none - See Also:
-
getToolTipText
Description copied from interface:IActionReturns the tool tip text for this action.This method is associated with the
TOOL_TIP_TEXTproperty; property change events are reported when its value changes.- Returns:
- the tool tip text, or
nullif none - See Also:
-
isChecked
public boolean isChecked()Description copied from interface:IActionReturns the checked status of this action. Applicable only if the style isAS_CHECK_BOXorAS_RADIO_BUTTON.This method is associated with the
CHECKEDproperty; property change events are reported when its value changes.- Returns:
- the checked status
- See Also:
-
isEnabled
public boolean isEnabled()Description copied from interface:IActionReturns whether this action is enabled.This method is associated with the
ENABLEDproperty; property change events are reported when its value changes.- Returns:
trueif enabled, andfalseif disabled- See Also:
-
isHandled
public boolean isHandled()Description copied from interface:IActionReturns whether this action is handled. In the default case, this is alwaystrue. However, if the action delegates some of its behaviour to some other object, then this method should answer whether such an object is currently available.- Returns:
trueif all of the action's behaviour is available;falseotherwise.
-
notifyResult
public final void notifyResult(boolean success) Reports the outcome of the running of this action via theIAction.RESULTproperty.- Parameters:
success-trueif the action succeeded andfalseif the action failed or was not completed- Since:
- 3.0
- See Also:
-
run
public void run()The default implementation of thisIActionmethod does nothing. Subclasses should override this method if they do not need information from the triggering event, or overriderunWithEvent(Event)if they do.- See Also:
-
runWithEvent
The default implementation of thisIActionmethod ignores the event argument, and simply callsrun(). Subclasses should override this method if they need information from the triggering event, or overriderun()if not.- Parameters:
event- the SWT event which triggered this action being run- Since:
- 2.0
- See Also:
-
setAccelerator
public void setAccelerator(int keycode) Description copied from interface:IActionSets 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.
IWorkbenchCommandSupportandIWorkbenchContextSupportprovide 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.- Parameters:
keycode- the keycode to be accepted.
-
setActionDefinitionId
Description copied from interface:IActionSets the action definition id of this action.- Parameters:
id- the action definition id
-
setChecked
public void setChecked(boolean checked) Description copied from interface:IActionSets the checked status of this action. Applicable for the stylesAS_CHECK_BOXorAS_RADIO_BUTTON.Fires a property change event for the
CHECKEDproperty if the checked status actually changes as a consequence.- Parameters:
checked- the new checked status- See Also:
-
setDescription
Description copied from interface:IActionSets 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
DESCRIPTIONproperty if the description actually changes as a consequence.- Parameters:
text- the description, ornullto clear the description- See Also:
-
setDisabledImageDescriptor
Description copied from interface:IActionSets 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
IMAGEproperty if the image actually changes as a consequence.- Parameters:
newImage- the image, ornullif this action should not have an image- See Also:
-
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:IActionSets 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
runmethod.Fires a property change event for the
ENABLEDproperty if the enabled state actually changes as a consequence.- Parameters:
enabled-trueto enable, andfalseto disable- See Also:
-
setHelpListener
Description copied from interface:IActionSets a help listener for this action.- Parameters:
listener- a help listener for this action
-
setHoverImageDescriptor
Description copied from interface:IActionSets 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
IMAGEproperty if the image actually changes as a consequence.- Parameters:
newImage- the image, ornullif this action should not have an image- See Also:
-
setId
Description copied from interface:IActionSets 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.- Parameters:
id- the action id- See Also:
-
setImageDescriptor
Description copied from interface:IActionSets the image for this action, as an image descriptor.Fires a property change event for the
IMAGEproperty if the image actually changes as a consequence.Note: This operation is a hint and is not supported in all contexts on platforms that do not have this concept (for example, Windows NT). Furthermore, some platforms (such as GTK), cannot display both a check box and an image at the same time. Instead, they hide the image and display the check box.
- Parameters:
newImage- the image, ornullif this action should not have an image- See Also:
-
setMenuCreator
Sets the menu creator for this action.Note that if this method is called, it overrides the check status.
- Parameters:
creator- the menu creator, ornullif none
-
setText
Description copied from interface:IActionSets the text for this action.An accelerator is identified by the last index of a '\t' character. If there are no '\t' characters, then it is identified by the last index of an '@' character. If neither, then there is no accelerator text. Note that if you want to insert an '@' character into the text (but no accelerator), then you can simply insert an '@' or a '\t' at the end of the text.
An accelerator specification consists of zero or more modifier tokens followed by a key code token. The tokens are separated by a '+' character.Fires a property change event for the
TEXTproperty if the text actually changes as a consequence.- Parameters:
text- the text, ornullif none- See Also:
-
setToolTipText
Sets the tool tip text for this action.Fires a property change event for the
TOOL_TIP_TEXTproperty if the tool tip text actually changes as a consequence.- Parameters:
toolTipText- the tool tip text, ornullif none- See Also:
-