public abstract class Action extends AbstractAction
Subclasses must implement the IAction.run
method to carry out
the action's semantics.
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
Modifier | Constructor and Description |
---|---|
protected |
Action()
Creates a new action with no text and no image.
|
protected |
Action(String text)
Creates a new action with the given text and no image.
|
protected |
Action(String text,
ImageDescriptor image)
Creates a new action with the given text and image.
|
protected |
Action(String text,
int style)
Creates a new action with the given text and style.
|
Modifier and Type | Method and Description |
---|---|
static String |
convertAccelerator(int keyCode)
Converts an accelerator key code to a string representation.
|
static int |
convertAccelerator(String acceleratorText)
Parses the given accelerator text, and converts it to an accelerator key
code.
|
static int |
findKeyCode(String token)
Maps a standard keyboard key name to an SWT key code.
|
static String |
findKeyString(int keyCode)
Maps an SWT key code to a standard keyboard key name.
|
static int |
findModifier(String token)
Maps standard keyboard modifier key names to the corresponding SWT
modifier bit.
|
static String |
findModifierString(int keyCode)
Returns a string representation of an SWT modifier bit (SWT.CTRL,
SWT.ALT, SWT.SHIFT, and SWT.COMMAND).
|
int |
getAccelerator()
Returns the accelerator keycode for this action.
|
String |
getActionDefinitionId()
Returns the action definition id of this action.
|
String |
getDescription()
Returns the action's description if it has one.
|
ImageDescriptor |
getDisabledImageDescriptor()
Returns the disabled image for this action as an image descriptor.
|
HelpListener |
getHelpListener()
Returns a help listener for this action.
|
ImageDescriptor |
getHoverImageDescriptor()
Returns the hover image for this action as an image descriptor.
|
String |
getId()
Returns a unique identifier for this action, or
null if it has
none. |
ImageDescriptor |
getImageDescriptor()
Returns the image for this action as an image descriptor.
|
IMenuCreator |
getMenuCreator()
Returns the menu creator for this action.
|
int |
getStyle()
Return this action's style.
|
String |
getText()
Returns the text for this action.
|
String |
getToolTipText()
Returns the tool tip text for this action.
|
boolean |
isChecked()
Returns the checked status of this action.
|
boolean |
isEnabled()
Returns whether this action is enabled.
|
boolean |
isHandled()
Returns whether this action is handled.
|
void |
notifyResult(boolean success)
Reports the outcome of the running of this action via the
IAction.RESULT property. |
static String |
removeAcceleratorText(String text)
Convenience method for removing any optional accelerator text from the
given string.
|
static String |
removeMnemonics(String text)
Convenience method for removing any mnemonics from the given string.
|
void |
run()
The default implementation of this
IAction method does
nothing. |
void |
runWithEvent(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(String id)
Sets the action definition id of this action.
|
void |
setChecked(boolean checked)
Sets the checked status of this action.
|
void |
setDescription(String text)
Sets this action's description.
|
void |
setDisabledImageDescriptor(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(HelpListener listener)
Sets a help listener for this action.
|
void |
setHoverImageDescriptor(ImageDescriptor newImage)
Sets the hover image for this action, as an image descriptor.
|
void |
setId(String id)
Sets the unique identifier for this action.
|
void |
setImageDescriptor(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(String text)
Sets the text for this action.
|
void |
setToolTipText(String toolTipText)
Sets the tool tip text for this action.
|
addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
protected Action()
Configure the action later using the set methods.
protected Action(String text)
setText
.text
- the string used as the text for the action, or
null
if there is no textsetText(java.lang.String)
protected Action(String text, ImageDescriptor image)
setText
and
setImageDescriptor
.text
- the action's text, or null
if there is no textimage
- the action's image, or null
if there is no
imagesetText(java.lang.String)
,
setImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)
protected Action(String text, int style)
text
- the action's text, or null
if there is no textstyle
- one of AS_PUSH_BUTTON
,
AS_CHECK_BOX
, AS_DROP_DOWN_MENU
,
AS_RADIO_BUTTON
, and
AS_UNSPECIFIED
.public static String convertAccelerator(int keyCode)
keyCode
- the key code to be translatedpublic static int convertAccelerator(String acceleratorText)
acceleratorText
- the accelerator textpublic static int findKeyCode(String token)
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"
token
- the key name-1
if no match was foundSWT
public static String findKeyString(int keyCode)
keyCode
- the key code to be translatedSWT
public static int findModifier(String token)
"CTRL"
, "SHIFT"
,
"ALT"
, and "COMMAND"
. The given modifier
key name is converted to upper case before comparison.token
- the modifier key name0
if no match was foundSWT
public static String findModifierString(int keyCode)
null
if the
key code is not an SWT modifier bit.keyCode
- the SWT modifier bit to be translatednull
if the key code was not an SWT modifier bitSWT
public static String removeAcceleratorText(String text)
'\t'
(or the last '@'
if there is no tab).text
- the textpublic static String removeMnemonics(String text)
removeMnemonics("&Open")
will return
"Open"
.text
- the textpublic int getAccelerator()
IAction
MenuItem.getAccelerator
.MenuItem.getAccelerator()
public String getActionDefinitionId()
IAction
null
if nonepublic String getDescription()
IAction
getToolTipText()
.null
public ImageDescriptor getDisabledImageDescriptor()
IAction
This method is associated with the IMAGE
property;
property change events are reported when its value changes.
null
if this action has no imageIAction.IMAGE
public HelpListener getHelpListener()
IAction
public ImageDescriptor getHoverImageDescriptor()
IAction
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.
null
if this action has no imageIAction.IMAGE
public String getId()
IAction
null
if it has
none.null
if nonepublic ImageDescriptor getImageDescriptor()
IAction
This method is associated with the IMAGE
property;
property change events are reported when its value changes.
null
if this action has no imageIAction.IMAGE
public IMenuCreator getMenuCreator()
IAction
null
if nonepublic int getStyle()
IAction
AS_PUSH_BUTTON
, AS_CHECK_BOX
,
AS_RADIO_BUTTON
and AS_DROP_DOWN_MENU
.public String getText()
IAction
This method is associated with the TEXT
property;
property change events are reported when its value changes.
null
if noneIAction.TEXT
public String getToolTipText()
IAction
This method is associated with the TOOL_TIP_TEXT
property;
property change events are reported when its value changes.
null
if noneIAction.TOOL_TIP_TEXT
public boolean isChecked()
IAction
AS_CHECK_BOX
or AS_RADIO_BUTTON
.
This method is associated with the CHECKED
property;
property change events are reported when its value changes.
IAction.CHECKED
public boolean isEnabled()
IAction
This method is associated with the ENABLED
property;
property change events are reported when its value changes.
true
if enabled, and
false
if disabledIAction.ENABLED
public boolean isHandled()
IAction
true
. 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.true
if all of the action's behaviour is
available; false
otherwise.public final void notifyResult(boolean success)
IAction.RESULT
property.success
- true
if the action succeeded and
false
if the action failed or was not completedIAction.RESULT
public void run()
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.public void runWithEvent(Event event)
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.event
- the SWT event which triggered this action being runHow radio buttons are handled
,
How check boxes are handled
public void setAccelerator(int keycode)
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.
keycode
- the keycode to be accepted.public void setActionDefinitionId(String id)
IAction
id
- the action definition idpublic void setChecked(boolean checked)
IAction
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.
checked
- the new checked statusIAction.CHECKED
public void setDescription(String text)
IAction
Fires a property change event for the DESCRIPTION
property
if the description actually changes as a consequence.
text
- the description, or null
to clear the descriptionIAction.DESCRIPTION
public void setDisabledImageDescriptor(ImageDescriptor newImage)
IAction
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.
newImage
- the image, or null
if this
action should not have an imageIAction.IMAGE
public void setEnabled(boolean enabled)
IAction
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.
enabled
- true
to enable, and
false
to disableIAction.ENABLED
public void setHelpListener(HelpListener listener)
IAction
listener
- a help listener for this actionpublic void setHoverImageDescriptor(ImageDescriptor newImage)
IAction
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.
newImage
- the image, or null
if this
action should not have an imageIAction.IMAGE
public void setId(String id)
IAction
id
- the action idActionContributionItem
,
IContributionItem.getId()
public void setImageDescriptor(ImageDescriptor newImage)
IAction
Fires a property change event for the IMAGE
property 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.
newImage
- the image, or null
if this action should not have
an imageIAction.IMAGE
public void setMenuCreator(IMenuCreator creator)
Note that if this method is called, it overrides the check status.
creator
- the menu creator, or null
if nonepublic void setText(String text)
IAction
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 TEXT
property
if the text actually changes as a consequence.
text
- the text, or null
if noneIAction.TEXT
,
findModifier(java.lang.String)
,
findKeyCode(java.lang.String)
public void setToolTipText(String toolTipText)
Fires a property change event for the TOOL_TIP_TEXT
property if the tool tip text actually changes as a consequence.
toolTipText
- the tool tip text, or null
if noneIAction.TOOL_TIP_TEXT
Copyright (c) 2000, 2018 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.