Package org.eclipse.jface.action
Class ActionContributionItem
java.lang.Object
org.eclipse.jface.action.ContributionItem
org.eclipse.jface.action.ActionContributionItem
- All Implemented Interfaces:
IContributionItem
- Direct Known Subclasses:
PluginActionContributionItem
A contribution item which delegates to an action.
This class may be instantiated; it is not intended to be subclassed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intMode bit: Show text on tool items or buttons, even if an image is present. -
Constructor Summary
ConstructorsConstructorDescriptionActionContributionItem(IAction action) Creates a new contribution item from the given action. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()The default implementation of thisIContributionItemmethod does nothing.booleanCompares this action contribution item with another object.voidTheActionContributionItemimplementation of thisIContributionItemmethod creates an SWTButtonfor the action using the action's style.voidTheActionContributionItemimplementation of thisIContributionItemmethod creates an SWTMenuItemfor the action using the action's style.voidTheActionContributionItemimplementation of this ,IContributionItemmethod creates an SWTToolItemfor the action using the action's style.Returns the action associated with this contribution item.intgetMode()Returns the presentation mode, which is the bitwise-or of theMODE_*constants.static booleanReturns whether color icons should be used in toolbars.Return the widget associated with this contribution item.inthashCode()booleanThe action item implementation of thisIContributionItemmethod returnstruefor menu items andfalsefor everything else.booleanThe default implementation of thisIContributionItemmethod returnstrue.protected booleanReturnstrueif this item is allowed to enable,falseotherwise.booleanTheActionContributionItemimplementation of thisContributionItemmethod extends the super implementation by also checking whether the command corresponding to this action is active.voidsetMode(int mode) Sets the presentation mode, which is the bitwise-or of theMODE_*constants.static voidsetUseColorIconsInToolbars(boolean useColorIcons) Sets whether color icons should be used in toolbars.protected StringshortenText(String textValue, ToolItem item) Shorten the given texttso 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 ("...").final voidupdate()The action item implementation of thisIContributionItemmethod callsupdate(null).voidSynchronizes 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
-
Field Details
-
MODE_FORCE_TEXT
public static int MODE_FORCE_TEXTMode 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 Details
-
ActionContributionItem
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 Details
-
getUseColorIconsInToolbars
public static boolean getUseColorIconsInToolbars()Returns whether color icons should be used in toolbars.- Returns:
trueif color icons should be used in toolbars,falseotherwise
-
setUseColorIconsInToolbars
public static void setUseColorIconsInToolbars(boolean useColorIcons) Sets whether color icons should be used in toolbars.- Parameters:
useColorIcons-trueif color icons should be used in toolbars,falseotherwise
-
equals
Compares this action contribution item with another object. Two action contribution items are equal if they refer to the identical Action. -
fill
TheActionContributionItemimplementation of thisIContributionItemmethod creates an SWTButtonfor 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:
fillin interfaceIContributionItem- Overrides:
fillin classContributionItem- Parameters:
parent- the parent control
-
fill
TheActionContributionItemimplementation of thisIContributionItemmethod creates an SWTMenuItemfor 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:
fillin interfaceIContributionItem- Overrides:
fillin classContributionItem- Parameters:
parent- the parent menuindex- the index where the controls are inserted, or-1to insert at the end
-
fill
TheActionContributionItemimplementation of this ,IContributionItemmethod creates an SWTToolItemfor 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:
fillin interfaceIContributionItem- Overrides:
fillin classContributionItem- Parameters:
parent- the parent tool barindex- the index where the controls are inserted, or-1to insert at the end
-
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 theMODE_*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() -
isDynamic
public boolean isDynamic()The action item implementation of thisIContributionItemmethod returnstruefor menu items andfalsefor everything else.- Specified by:
isDynamicin interfaceIContributionItem- Overrides:
isDynamicin classContributionItem- Returns:
trueif this item is dynamic, andfalsefor normal items
-
isEnabled
public boolean isEnabled()Description copied from class:ContributionItemThe default implementation of thisIContributionItemmethod returnstrue. Subclasses may override.- Specified by:
isEnabledin interfaceIContributionItem- Overrides:
isEnabledin classContributionItem- Returns:
trueif this item is enabled
-
isEnabledAllowed
protected boolean isEnabledAllowed()Returnstrueif this item is allowed to enable,falseotherwise.- Returns:
- if this item is allowed to be enabled
- Since:
- 2.0
-
isVisible
public boolean isVisible()TheActionContributionItemimplementation of thisContributionItemmethod extends the super implementation by also checking whether the command corresponding to this action is active.- Specified by:
isVisiblein interfaceIContributionItem- Overrides:
isVisiblein classContributionItem- Returns:
trueif this item is visible, andfalseotherwise
-
setMode
public void setMode(int mode) Sets the presentation mode, which is the bitwise-or of theMODE_*constants.- Parameters:
mode- the presentation mode settings- Since:
- 3.0
-
update
public final void update()The action item implementation of thisIContributionItemmethod callsupdate(null).- Specified by:
updatein interfaceIContributionItem- Overrides:
updatein classContributionItem
-
update
Synchronizes the UI with the given property.- Specified by:
updatein interfaceIContributionItem- Overrides:
updatein classContributionItem- Parameters:
propertyName- the name of the property, ornullmeaning all applicable properties
-
shortenText
Shorten the given texttso 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 shortenitem- the tool item the text belongs to- Returns:
- the shortened string
-
dispose
public void dispose()Description copied from class:ContributionItemThe default implementation of thisIContributionItemmethod does nothing. Subclasses may override.- Specified by:
disposein interfaceIContributionItem- Overrides:
disposein classContributionItem
-
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
nulldepending on the lifecycle. - Since:
- 3.4
-