public interface IAction
run
method is invoked to do the real work.
Actions support a predefined set of properties (and possibly others as well). Clients of an action may register property change listeners so that they get notified whenever the value of a property changes.
Clients should subclass the abstract base class Action
to define
concrete actions rather than implementing IAction
from scratch.
This interface exists only to define the API for actions. It is not intended to be implemented by clients.
Action
Modifier and Type | Field and Description |
---|---|
static int |
AS_CHECK_BOX
Action style constant (value
2 ) indicating action is
a check box (or a toggle button). |
static int |
AS_DROP_DOWN_MENU
Action style constant (value
4 ) indicating action is
a drop down menu. |
static int |
AS_PUSH_BUTTON
Action style constant (value
1 ) indicating action is
a simple push button. |
static int |
AS_RADIO_BUTTON
Action style constant (value
8 ) indicating action is
a radio button. |
static int |
AS_UNSPECIFIED
Action style constant (value
0 ) indicating action style
is not specified yet. |
static String |
CHECKED
Property name of an action's checked status (value
"checked" ). |
static String |
DESCRIPTION
Property name of an action's description (value
"description" ). |
static String |
ENABLED
Property name of an action's enabled state
(value
"enabled" ). |
static String |
HANDLED
Property name of an action's handler.
|
static String |
IMAGE
Property name of an action's image (value
"image" ). |
static String |
RESULT
Property name of an action's success/fail result
(value
"result" ). |
static String |
TEXT
Property name of an action's text (value
"text" ). |
static String |
TOOL_TIP_TEXT
Property name of an action's tooltip text (value
"toolTipText" ). |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(IPropertyChangeListener listener)
Adds a property change listener to this action.
|
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 |
removePropertyChangeListener(IPropertyChangeListener listener)
Removes the given listener from this action.
|
void |
run()
Runs this action.
|
void |
runWithEvent(Event event)
Runs this action, passing the triggering SWT event.
|
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 text)
Sets the tool tip text for this action.
|
static final int AS_UNSPECIFIED
0
) indicating action style
is not specified yet. By default, the action will assume a push button
style. If setChecked
is called, then the style will change
to a check box, or if setMenuCreator
is called, then the
style will change to a drop down menu.static final int AS_PUSH_BUTTON
1
) indicating action is
a simple push button.static final int AS_CHECK_BOX
2
) indicating action is
a check box (or a toggle button).
Note: The action is also run when a check box gets
deselected. Use isChecked()
to determine the selection state.
static final int AS_DROP_DOWN_MENU
4
) indicating action is
a drop down menu.static final int AS_RADIO_BUTTON
8
) indicating action is
a radio button.
Note: When a radio button gets selected, the action for
the unselected radio button will also be run. Use isChecked()
to
determine the selection state.
static final String TEXT
"text"
).static final String ENABLED
"enabled"
).static final String IMAGE
"image"
).static final String TOOL_TIP_TEXT
"toolTipText"
).static final String DESCRIPTION
"description"
).
Typically the description is shown as a (longer) help text in the status line.static final String CHECKED
"checked"
). Applicable when the style is
AS_CHECK_BOX
or AS_RADIO_BUTTON
.static final String RESULT
"result"
). The values are
Boolean.TRUE
if running the action succeeded and
Boolean.FALSE
if running the action failed or did not
complete.
Not all actions report whether they succeed or fail. This property is provided for use by actions that may be invoked by clients that can take advantage of this information when present (for example, actions used in cheat sheets). Clients should always assume that running the action succeeded in the absence of notification to the contrary.
static final String HANDLED
void addPropertyChangeListener(IPropertyChangeListener listener)
listener
- a property change listenerint getAccelerator()
MenuItem.getAccelerator
.MenuItem.getAccelerator()
String getActionDefinitionId()
null
if noneString getDescription()
getToolTipText()
.null
ImageDescriptor getDisabledImageDescriptor()
This method is associated with the IMAGE
property;
property change events are reported when its value changes.
null
if this action has no imageIMAGE
HelpListener getHelpListener()
ImageDescriptor getHoverImageDescriptor()
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 imageIMAGE
String getId()
null
if it has
none.null
if noneImageDescriptor getImageDescriptor()
This method is associated with the IMAGE
property;
property change events are reported when its value changes.
null
if this action has no imageIMAGE
IMenuCreator getMenuCreator()
null
if noneint getStyle()
AS_PUSH_BUTTON
, AS_CHECK_BOX
,
AS_RADIO_BUTTON
and AS_DROP_DOWN_MENU
.String getText()
This method is associated with the TEXT
property;
property change events are reported when its value changes.
null
if noneTEXT
String getToolTipText()
This method is associated with the TOOL_TIP_TEXT
property;
property change events are reported when its value changes.
null
if noneTOOL_TIP_TEXT
boolean isChecked()
AS_CHECK_BOX
or AS_RADIO_BUTTON
.
This method is associated with the CHECKED
property;
property change events are reported when its value changes.
CHECKED
boolean isEnabled()
This method is associated with the ENABLED
property;
property change events are reported when its value changes.
true
if enabled, and
false
if disabledENABLED
boolean isHandled()
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.void removePropertyChangeListener(IPropertyChangeListener listener)
listener
- a property change listenervoid run()
Action
does nothing.void runWithEvent(Event event)
ActionContributionItem
calls this method
instead of run()
.
The default implementation of this method in Action
simply calls run()
for backwards compatibility.event
- the SWT event which triggered this action being runHow radio buttons are handled
,
How check boxes are handled
void setActionDefinitionId(String id)
id
- the action definition idvoid setChecked(boolean checked)
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 statusCHECKED
void setDescription(String text)
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 descriptionDESCRIPTION
void setDisabledImageDescriptor(ImageDescriptor newImage)
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 imageIMAGE
void setEnabled(boolean enabled)
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 disableENABLED
void setHelpListener(HelpListener listener)
listener
- a help listener for this actionvoid setHoverImageDescriptor(ImageDescriptor newImage)
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 imageIMAGE
void setId(String id)
id
- the action idActionContributionItem
,
IContributionItem.getId()
void setImageDescriptor(ImageDescriptor newImage)
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 imageIMAGE
void setMenuCreator(IMenuCreator creator)
AS_DROP_DOWN_MENU
.creator
- the menu creator, or null
if nonevoid setText(String text)
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 noneTEXT
,
Action.findModifier(java.lang.String)
,
Action.findKeyCode(java.lang.String)
void setToolTipText(String text)
Fires a property change event for the TOOL_TIP_TEXT
property
if the tool tip text actually changes as a consequence.
text
- the tool tip text, or null
if noneTOOL_TIP_TEXT
void setAccelerator(int keycode)
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.
Copyright (c) 2000, 2018 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.