Package org.eclipse.jface.action
Class MenuManager
java.lang.Object
org.eclipse.jface.action.ContributionManager
org.eclipse.jface.action.MenuManager
- All Implemented Interfaces:
- IContributionItem,- IContributionManager,- IMenuManager
A menu manager is a contribution manager which realizes itself and its items
 in a menu control; either as a menu bar, a sub-menu, or a context menu.
 
This class may be instantiated; it may also be subclassed.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe key under which theMenuManageris added to the data properties of theMenucreated by the manager.protected booleanIndicates this item is visible in its manager;trueby default.
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a menu manager.MenuManager(String text) Creates a menu manager with the given text.MenuManager(String text, String id) Creates a menu manager with the given text and id.MenuManager(String text, ImageDescriptor image, String id) Creates a menu manager with the given text, image, and id.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddMenuListener(IMenuListener listener) Adds a menu listener to this menu.createContextMenu(Control parent) Creates and returns an SWT context menu control for this menu, and installs all registered contributions.createMenuBar(Decorations parent) Creates and returns an SWT menu bar control for this menu, for use in the givenDecorations, and installs all registered contributions.createMenuBar(Shell parent) Deprecated.voiddispose()Disposes of this menu manager and frees all allocated SWT resources.protected voiddoItemFill(IContributionItem ci, int index) Call anIContributionItem's fill method with the implementation's widget.voidFills the given composite control with controls representing this contribution item.voidFills the given cool bar with controls representing this contribution item.voidFills the given menu with controls representing this contribution item.voidFills the given tool bar with controls representing this contribution item.findMenuUsingPath(String path) Finds the manager for the menu at the given path.findUsingPath(String path) Finds the contribution item at the given path.getId()Returns the menu id.Returns the image for this menu as an image descriptor.getMenu()Returns the SWT menu control for this menu manager.protected ItemgetMenuItem(int index) Get an item from the implementation's widget.protected intGet the menu item count for the implementation's widget.protected Item[]Get all the items from the implementation's widget.Returns the text shown in the menu, potentially with a shortcut appended.TheContributionManagerimplementation of this method declared onIContributionManagerreturns the current overrides.Returns the parent contribution manager of this manger.booleanReturns whether all items should be removed when the menu is about to show, but before notifying menu listeners.booleanReturns whether this contribution item is dynamic.booleanReturns whether this menu should be enabled or not.booleanReturns whether this contribution item is a group marker.booleanReturns whether this contribution item is a separator.booleanDeprecated.this method is no longer a part of theIContributionItemAPI.booleanReturns whether this contribution item is visibile within its manager.voidTheMenuManagerimplementation of thisContributionManagermethod also propagates the dirty flag up the parent chain.protected booleanReturns whether the menu control is created and not disposed.voidremoveMenuListener(IMenuListener listener) Removes the given menu listener from this menu.voidSaves any state information of the control(s) owned by this contribution item.voidsetActionDefinitionId(String definitionId) Sets the action definition id of this action.voidsetImageDescriptor(ImageDescriptor imageDescriptor) voidsetMenuText(String menuText) voidsetOverrides(IContributionManagerOverrides newOverrides) Sets the overrides for this contribution managervoidsetParent(IContributionManager manager) Sets the parent manager of this itemvoidsetRemoveAllWhenShown(boolean removeAll) Sets whether all items should be removed when the menu is about to show, but before notifying menu listeners.voidsetVisible(boolean visible) Sets whether this contribution item is visibile within its manager.toString()voidupdate()Updates any SWT controls cached by this contribution item with any changes which have been made to this contribution item since the last update.voidupdate(boolean force) TheMenuManagerimplementation of thisIContributionManagerupdates this menu, but not any of its submenus.protected voidupdate(boolean force, boolean recursive) Incrementally builds the menu from the contribution items.voidUpdates any SWT controls cached by this contribution item with changes for the the given property.voidupdateAll(boolean force) Incrementally builds the menu from the contribution items, and does so recursively for all submenus.Methods inherited from class org.eclipse.jface.action.ContributionManageradd, add, allowItem, appendToGroup, appendToGroup, dumpStatistics, find, getItems, getSize, hasDynamicItems, indexOf, indexOf, insert, insertAfter, insertAfter, insertBefore, insertBefore, internalSetItems, isDirty, isEmpty, itemAdded, itemRemoved, prependToGroup, prependToGroup, remove, remove, removeAll, replaceItem, setDirtyMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jface.action.IContributionItemisDirtyMethods inherited from interface org.eclipse.jface.action.IContributionManageradd, add, appendToGroup, appendToGroup, find, getItems, insertAfter, insertAfter, insertBefore, insertBefore, isDirty, isEmpty, prependToGroup, prependToGroup, remove, remove, removeAll
- 
Field Details- 
MANAGER_KEYThe key under which theMenuManageris added to the data properties of theMenucreated by the manager.- Since:
- 3.12
- See Also:
 
- 
visibleprotected boolean visibleIndicates this item is visible in its manager;trueby default.- Since:
- 3.3
 
 
- 
- 
Constructor Details- 
MenuManagerpublic MenuManager()Creates a menu manager. The text and id arenull. Typically used for creating a context menu, where it doesn't need to be referred to by id.
- 
MenuManagerCreates a menu manager with the given text. The id of the menu isnull. Typically used for creating a sub-menu, where it doesn't need to be referred to by id.- Parameters:
- text- the text for the menu, or- nullif none
 
- 
MenuManagerCreates a menu manager with the given text and id. Typically used for creating a sub-menu, where it needs to be referred to by id.- Parameters:
- text- the text for the menu, or- nullif none
- id- the menu id, or- nullif it is to have no id
 
- 
MenuManagerCreates a menu manager with the given text, image, and id. Typically used for creating a sub-menu, where it needs to be referred to by id.- Parameters:
- text- the text for the menu, or- nullif none
- image- the image for the menu, or- nullif none
- id- the menu id, or- nullif it is to have no id
- Since:
- 3.4
 
 
- 
- 
Method Details- 
addMenuListenerDescription copied from interface:IMenuManagerAdds a menu listener to this menu. Has no effect if an identical listener is already registered.- Specified by:
- addMenuListenerin interface- IMenuManager
- Parameters:
- listener- a menu listener
 
- 
createContextMenuCreates and returns an SWT context menu control for this menu, and installs all registered contributions. Does not create a new control if one already exists.Note that the menu is not expected to be dynamic. - Parameters:
- parent- the parent control
- Returns:
- the menu control
 
- 
createMenuBarCreates and returns an SWT menu bar control for this menu, for use in the givenDecorations, and installs all registered contributions. Does not create a new control if one already exists.- Parameters:
- parent- the parent decorations
- Returns:
- the menu control
- Since:
- 2.1
 
- 
createMenuBarDeprecated.usecreateMenuBar(Decorations)instead.Creates and returns an SWT menu bar control for this menu, for use in the givenShell, and installs all registered contributions. Does not create a new control if one already exists. This implementation simply calls thecreateMenuBar(Decorations)method- Parameters:
- parent- the parent decorations
- Returns:
- the menu control
 
- 
disposepublic void dispose()Disposes of this menu manager and frees all allocated SWT resources. Notifies all contribution items of the dispose.- Specified by:
- disposein interface- IContributionItem
 
- 
fillDescription copied from interface:IContributionItemFills the given composite control with controls representing this contribution item. Used byStatusLineManager.- Specified by:
- fillin interface- IContributionItem
- Parameters:
- parent- the parent control
 
- 
fillDescription copied from interface:IContributionItemFills the given cool bar with controls representing this contribution item. Used byCoolBarManager.- Specified by:
- fillin interface- IContributionItem
- Parameters:
- parent- the parent cool bar
- index- the index where the controls are inserted, or- -1to insert at the end
 
- 
fillDescription copied from interface:IContributionItemFills the given menu with controls representing this contribution item. Used byMenuManager.- Specified by:
- fillin interface- IContributionItem
- Parameters:
- parent- the parent menu
- index- the index where the controls are inserted, or- -1to insert at the end
 
- 
fillDescription copied from interface:IContributionItemFills the given tool bar with controls representing this contribution item. Used byToolBarManager.- Specified by:
- fillin interface- IContributionItem
- Parameters:
- parent- the parent tool bar
- index- the index where the controls are inserted, or- -1to insert at the end
 
- 
findMenuUsingPathDescription copied from interface:IMenuManagerFinds the manager for the menu at the given path. A path consists of contribution item ids separated by the separator character. The path separator character is'/'.Convenience for findUsingPath(path)which extracts anIMenuManagerif possible.- Specified by:
- findMenuUsingPathin interface- IMenuManager
- Parameters:
- path- the path string
- Returns:
- the menu contribution item, or nullif there is no such contribution item or if the item does not have an associated menu manager
 
- 
findUsingPathDescription copied from interface:IMenuManagerFinds the contribution item at the given path. A path consists of contribution item ids separated by the separator character. The path separator character is'/'.- Specified by:
- findUsingPathin interface- IMenuManager
- Parameters:
- path- the path string
- Returns:
- the contribution item, or nullif there is no such contribution item
 
- 
getIdReturns the menu id. The menu id is used when creating a contribution item for adding this menu as a sub menu of another.- Specified by:
- getIdin interface- IContributionItem
- Returns:
- the menu id
 
- 
getMenuReturns the SWT menu control for this menu manager.- Returns:
- the menu control
 
- 
getMenuTextReturns the text shown in the menu, potentially with a shortcut appended.- Returns:
- the menu text
 
- 
getImageDescriptorReturns the image for this menu as an image descriptor.- Returns:
- the image, or nullif this menu has no image
- Since:
- 3.4
 
- 
getOverridesDescription copied from class:ContributionManagerTheContributionManagerimplementation of this method declared onIContributionManagerreturns the current overrides. If there is no overrides it lazily creates one which overrides no item state.- Specified by:
- getOverridesin interface- IContributionManager
- Overrides:
- getOverridesin class- ContributionManager
- Returns:
- the overrides for the items of this manager
 
- 
getParentReturns the parent contribution manager of this manger.- Returns:
- the parent contribution manager
- Since:
- 2.0
 
- 
getRemoveAllWhenShownpublic boolean getRemoveAllWhenShown()Description copied from interface:IMenuManagerReturns whether all items should be removed when the menu is about to show, but before notifying menu listeners. The default isfalse.- Specified by:
- getRemoveAllWhenShownin interface- IMenuManager
- Returns:
- trueif all items should be removed when shown,- falseif not
 
- 
isDynamicpublic boolean isDynamic()Description copied from interface:IContributionItemReturns whether this contribution item is dynamic. A dynamic contribution item contributes items conditionally, dependent on some internal state.- Specified by:
- isDynamicin interface- IContributionItem
- Returns:
- trueif this item is dynamic, and- falsefor normal items
 
- 
isEnabledpublic boolean isEnabled()Returns whether this menu should be enabled or not. Used to enable the menu item containing this menu when it is realized as a sub-menu.The default implementation of this framework method returns true. Subclasses may reimplement.- Specified by:
- isEnabledin interface- IContributionItem
- Specified by:
- isEnabledin interface- IMenuManager
- Returns:
- trueif enabled, and- falseif disabled
 
- 
isGroupMarkerpublic boolean isGroupMarker()Description copied from interface:IContributionItemReturns whether this contribution item is a group marker. This information is used when adding items to a group.- Specified by:
- isGroupMarkerin interface- IContributionItem
- Returns:
- trueif this item is a group marker, and- falsefor normal items
- See Also:
 
- 
isSeparatorpublic boolean isSeparator()Description copied from interface:IContributionItemReturns whether this contribution item is a separator. This information is used to enable hiding of unnecessary separators.- Specified by:
- isSeparatorin interface- IContributionItem
- Returns:
- trueif this item is a separator, and- falsefor normal items
- See Also:
 
- 
isSubstituteForDeprecated.this method is no longer a part of theIContributionItemAPI.Check if the contribution is item is a subsitute for ourselves- Parameters:
- item- the contribution item
- Returns:
- trueif give item is a substitution for ourselves
 
- 
isVisiblepublic boolean isVisible()Description copied from interface:IContributionItemReturns whether this contribution item is visibile within its manager.- Specified by:
- isVisiblein interface- IContributionItem
- Returns:
- trueif this item is visible, and- falseotherwise
 
- 
markDirtypublic void markDirty()TheMenuManagerimplementation of thisContributionManagermethod also propagates the dirty flag up the parent chain.- Specified by:
- markDirtyin interface- IContributionManager
- Overrides:
- markDirtyin class- ContributionManager
- Since:
- 3.1
 
- 
removeMenuListenerDescription copied from interface:IMenuManagerRemoves the given menu listener from this menu. Has no effect if an identical listener is not registered.- Specified by:
- removeMenuListenerin interface- IMenuManager
- Parameters:
- listener- the menu listener
 
- 
saveWidgetStatepublic void saveWidgetState()Description copied from interface:IContributionItemSaves any state information of the control(s) owned by this contribution item. The contribution manager calls this method before disposing of the controls.- Specified by:
- saveWidgetStatein interface- IContributionItem
 
- 
setOverridesSets the overrides for this contribution manager- Overrides:
- setOverridesin class- ContributionManager
- Parameters:
- newOverrides- the overrides for the items of this manager
- Since:
- 2.0
 
- 
setParentDescription copied from interface:IContributionItemSets the parent manager of this item- Specified by:
- setParentin interface- IContributionItem
- Parameters:
- manager- the parent contribution manager
 
- 
setRemoveAllWhenShownpublic void setRemoveAllWhenShown(boolean removeAll) Description copied from interface:IMenuManagerSets whether all items should be removed when the menu is about to show, but before notifying menu listeners.- Specified by:
- setRemoveAllWhenShownin interface- IMenuManager
- Parameters:
- removeAll-- trueif all items should be removed when shown,- falseif not
 
- 
setVisiblepublic void setVisible(boolean visible) Description copied from interface:IContributionItemSets whether this contribution item is visibile within its manager.- Specified by:
- setVisiblein interface- IContributionItem
- Parameters:
- visible-- trueif this item should be visible, and- falseotherwise
 
- 
setActionDefinitionIdSets the action definition id of this action. This simply allows the menu item text to include a short cut if available. It can be used to notify a user of a key combination that will open a quick menu.- Parameters:
- definitionId- the command definition id
- Since:
- 3.4
 
- 
updatepublic void update()Description copied from interface:IContributionItemUpdates any SWT controls cached by this contribution item with any changes which have been made to this contribution item since the last update. Called by contribution manager update methods.- Specified by:
- updatein interface- IContributionItem
 
- 
updatepublic void update(boolean force) TheMenuManagerimplementation of thisIContributionManagerupdates this menu, but not any of its submenus.- Specified by:
- updatein interface- IContributionManager
- Parameters:
- force-- truemeans update even if not dirty, and- falsefor normal incremental updating
- See Also:
 
- 
getMenuItemsGet all the items from the implementation's widget.- Returns:
- the menu items
- Since:
- 3.4
 
- 
getMenuItemGet an item from the implementation's widget.- Parameters:
- index- of the item
- Returns:
- the menu item
- Since:
- 3.4
 
- 
getMenuItemCountprotected int getMenuItemCount()Get the menu item count for the implementation's widget.- Returns:
- the number of items
- Since:
- 3.4
 
- 
doItemFillCall anIContributionItem's fill method with the implementation's widget. The default is to use theMenuwidget.
 fill(Menu menu, int index)- Parameters:
- ci- An- IContributionItemwhose- fill()method should be called.
- index- The position the- fill()method should start inserting at.
- Since:
- 3.4
 
- 
updateprotected void update(boolean force, boolean recursive) Incrementally builds the menu from the contribution items. This method leaves out double separators and separators in the first or last position.- Parameters:
- force-- truemeans update even if not dirty, and- falsefor normal incremental updating
- recursive-- truemeans recursively update all submenus, and- falsemeans just this menu
 
- 
updateDescription copied from interface:IContributionItemUpdates any SWT controls cached by this contribution item with changes for the the given property.- Specified by:
- updatein interface- IContributionItem
- Parameters:
- property- the id of the changed property
 
- 
updateAllpublic void updateAll(boolean force) Description copied from interface:IMenuManagerIncrementally builds the menu from the contribution items, and does so recursively for all submenus.- Specified by:
- updateAllin interface- IMenuManager
- Parameters:
- force-- truemeans update even if not dirty, and- falsefor normal incremental updating
 
- 
setMenuText- Parameters:
- menuText- The text (label) of the menu.
- Since:
- 3.10
 
- 
setImageDescriptor- Parameters:
- imageDescriptor- The image descriptor to set.
- Since:
- 3.10
 
- 
toString
 
- 
createMenuBar(Decorations)instead.