org.eclipse.jface.action

## Class ActionContributionItem

- java.lang.Object
- - org.eclipse.jface.action.ContributionItem
  - - org.eclipse.jface.action.ActionContributionItem

All Implemented Interfaces:
  IContributionItem

    public class ActionContributionItem
    extends ContributionItem

A contribution item which delegates to an action.

This class may be instantiated; it is not intended to be subclassed.

Restriction:
  This class is not intended to be subclassed by clients.

### Field Summary

Fields
`static int` `MODE_FORCE_TEXT` Mode bit: Show text on tool items or buttons, even if an image is present.

### Constructor Summary

Constructors
Constructor and Description
`ActionContributionItem(IAction action)` Creates a new contribution item from the given action.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `dispose()` The default implementation of this `IContributionItem` method does nothing.
`boolean` `equals(Object o)` Compares this action contribution item with another object.
`void` `fill(Composite parent)` The `ActionContributionItem` implementation of this `IContributionItem` method creates an SWT `Button` for the action using the action's style.
`void` `fill(Menu parent, int index)` The `ActionContributionItem` implementation of this `IContributionItem` method creates an SWT `MenuItem` for the action using the action's style.
`void` `fill(ToolBar parent, int index)` The `ActionContributionItem` implementation of this , `IContributionItem` method creates an SWT `ToolItem` for the action using the action's style.
`IAction` `getAction()` Returns the action associated with this contribution item.
`int` `getMode()` Returns the presentation mode, which is the bitwise-or of the `MODE_*` constants.
`static boolean` `getUseColorIconsInToolbars()` Returns whether color icons should be used in toolbars.
`Widget` `getWidget()` Return the widget associated with this contribution item.
`int` `hashCode()`
`boolean` `isDynamic()` The action item implementation of this `IContributionItem` method returns `true` for menu items and `false` for everything else.
`boolean` `isEnabled()` The default implementation of this `IContributionItem` method returns `true`.
`protected boolean` `isEnabledAllowed()` Returns `true` if this item is allowed to enable, `false` otherwise.
`boolean` `isVisible()` The `ActionContributionItem` implementation of this `ContributionItem` method extends the super implementation by also checking whether the command corresponding to this action is active.
`void` `setMode(int mode)` Sets the presentation mode, which is the bitwise-or of the `MODE_*` constants.
`static void` `setUseColorIconsInToolbars(boolean useColorIcons)` Sets whether color icons should be used in toolbars.
`protected String` `shortenText(String textValue, ToolItem item)` Shorten the given text `t` so that its length doesn't exceed the width of the given ToolItem.The default implementation replaces characters in the center of the original string with an ellipsis ("...").
`void` `update()` The action item implementation of this `IContributionItem` method calls `update(null)`.
`void` `update(String propertyName)` Synchronizes the UI with the given property.

### Methods inherited from class org.eclipse.jface.action.ContributionItem

`fill, getId, getParent, isDirty, isGroupMarker, isSeparator, saveWidgetState, setId, setParent, setVisible, toString`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### MODE_FORCE_TEXT

    public static int MODE_FORCE_TEXT

Mode bit: Show text on tool items or buttons, even if an image is present. If this mode bit is not set, text is only shown on tool items if there is no image present.

Since:
  3.0

### Constructor Detail

#### ActionContributionItem

    public ActionContributionItem(IAction action)

Creates a new contribution item from the given action. The id of the action is used as the id of the item.

Parameters:
  `action` - the action

### Method Detail

#### getUseColorIconsInToolbars

    public static boolean getUseColorIconsInToolbars()

Returns whether color icons should be used in toolbars.

Returns:
  `true` if color icons should be used in toolbars, `false` otherwise

#### setUseColorIconsInToolbars

    public static void setUseColorIconsInToolbars(boolean useColorIcons)

Sets whether color icons should be used in toolbars.

Parameters:
  `useColorIcons` - `true` if color icons should be used in toolbars, `false` otherwise

#### equals

    public boolean equals(Object o)

Compares this action contribution item with another object. Two action contribution items are equal if they refer to the identical Action.

Overrides:
  `equals` in class `Object`

#### fill

    public void fill(Composite parent)

The `ActionContributionItem` implementation of this `IContributionItem` method creates an SWT `Button` for the action using the action's style. If the action's checked property has been set, the button is created and primed to the value of the checked property.

Specified by:
  `fill` in interface `IContributionItem`
Overrides:
  `fill` in class `ContributionItem`
Parameters:
  `parent` - the parent control

#### fill

    public void fill(Menu parent,
                     int index)

The `ActionContributionItem` implementation of this `IContributionItem` method creates an SWT `MenuItem` for the action using the action's style. If the action's checked property has been set, a button is created and primed to the value of the checked property. If the action's menu creator property has been set, a cascading submenu is created.

Specified by:
  `fill` in interface `IContributionItem`
Overrides:
  `fill` in class `ContributionItem`
Parameters:
  `parent` - the parent menu
  `index` - the index where the controls are inserted, or `-1` to insert at the end

#### fill

    public void fill(ToolBar parent,
                     int index)

The `ActionContributionItem` implementation of this , `IContributionItem` method creates an SWT `ToolItem` for the action using the action's style. If the action's checked property has been set, a button is created and primed to the value of the checked property. If the action's menu creator property has been set, a drop-down tool item is created.

Specified by:
  `fill` in interface `IContributionItem`
Overrides:
  `fill` in class `ContributionItem`
Parameters:
  `parent` - the parent tool bar
  `index` - the index where the controls are inserted, or `-1` to insert at the end

#### getAction

    public IAction getAction()

Returns the action associated with this contribution item.

Returns:
  the action

#### getMode

    public int getMode()

Returns the presentation mode, which is the bitwise-or of the `MODE_*` constants. The default mode setting is 0, meaning that for menu items, both text and image are shown (if present), but for tool items, the text is shown only if there is no image.

Returns:
  the presentation mode settings
Since:
  3.0

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### isDynamic

    public boolean isDynamic()

The action item implementation of this `IContributionItem` method returns `true` for menu items and `false` for everything else.

Specified by:
  `isDynamic` in interface `IContributionItem`
Overrides:
  `isDynamic` in class `ContributionItem`
Returns:
  `true` if this item is dynamic, and `false` for normal items

#### isEnabled

    public boolean isEnabled()

Description copied from class: `ContributionItem`
The default implementation of this `IContributionItem` method returns `true`. Subclasses may override.

Specified by:
  `isEnabled` in interface `IContributionItem`
Overrides:
  `isEnabled` in class `ContributionItem`
Returns:
  `true` if this item is enabled

#### isEnabledAllowed

    protected boolean isEnabledAllowed()

Returns `true` if this item is allowed to enable, `false` otherwise.

Returns:
  if this item is allowed to be enabled
Since:
  2.0

#### isVisible

    public boolean isVisible()

The `ActionContributionItem` implementation of this `ContributionItem` method extends the super implementation by also checking whether the command corresponding to this action is active.

Specified by:
  `isVisible` in interface `IContributionItem`
Overrides:
  `isVisible` in class `ContributionItem`
Returns:
  `true` if this item is visible, and `false` otherwise

#### setMode

    public void setMode(int mode)

Sets the presentation mode, which is the bitwise-or of the `MODE_*` constants.

Parameters:
  `mode` - the presentation mode settings
Since:
  3.0

#### update

    public final void update()

The action item implementation of this `IContributionItem` method calls `update(null)`.

Specified by:
  `update` in interface `IContributionItem`
Overrides:
  `update` in class `ContributionItem`

#### update

    public void update(String propertyName)

Synchronizes the UI with the given property.

Specified by:
  `update` in interface `IContributionItem`
Overrides:
  `update` in class `ContributionItem`
Parameters:
  `propertyName` - the name of the property, or `null` meaning all applicable properties

#### shortenText

    protected String shortenText(String textValue,
                                 ToolItem item)

Shorten the given text `t` so that its length doesn't exceed the width of the given ToolItem.The default implementation replaces characters in the center of the original string with an ellipsis ("..."). Override if you need a different strategy.

Parameters:
  `textValue` - the text to shorten
  `item` - the tool item the text belongs to
Returns:
  the shortened string

#### dispose

    public void dispose()

Description copied from class: `ContributionItem`
The default implementation of this `IContributionItem` method does nothing. Subclasses may override.

Specified by:
  `dispose` in interface `IContributionItem`
Overrides:
  `dispose` in class `ContributionItem`

#### getWidget

    public Widget getWidget()

Return the widget associated with this contribution item. It should not be cached, as it can be disposed and re-created by its containing ContributionManager, which controls all of the widgets lifecycle methods.

This can be used to set layout data on the widget if appropriate. The actual type of the widget can be any valid control for this ContributionItem's current ContributionManager.

Returns:
  the widget, or `null` depending on the lifecycle.
Since:
  3.4