public class MenuManager extends ContributionManager implements IMenuManager
This class may be instantiated; it may also be subclassed.
Modifier and Type | Field and Description |
---|---|
protected boolean |
visible
Indicates this item is visible in its manager;
true
by default. |
Constructor and Description |
---|
MenuManager()
Creates a menu manager.
|
MenuManager(String text)
Creates a menu manager with the given text.
|
MenuManager(String text,
ImageDescriptor image,
String id)
Creates a menu manager with the given text, image, and id.
|
MenuManager(String text,
String id)
Creates a menu manager with the given text and id.
|
Modifier and Type | Method and Description |
---|---|
void |
addMenuListener(IMenuListener listener)
Adds a menu listener to this menu.
|
Menu |
createContextMenu(Control parent)
Creates and returns an SWT context menu control for this menu,
and installs all registered contributions.
|
Menu |
createMenuBar(Decorations parent)
Creates and returns an SWT menu bar control for this menu,
for use in the given
Decorations , and installs all registered
contributions. |
Menu |
createMenuBar(Shell parent)
Deprecated.
use
createMenuBar(Decorations) instead. |
void |
dispose()
Disposes of this menu manager and frees all allocated SWT resources.
|
protected void |
doItemFill(IContributionItem ci,
int index)
Call an
IContributionItem 's fill method with the
implementation's widget. |
void |
fill(Composite parent)
Fills the given composite control with controls representing this
contribution item.
|
void |
fill(CoolBar parent,
int index)
Fills the given cool bar with controls representing this contribution item.
|
void |
fill(Menu parent,
int index)
Fills the given menu with controls representing this contribution item.
|
void |
fill(ToolBar parent,
int index)
Fills the given tool bar with controls representing this contribution item.
|
IMenuManager |
findMenuUsingPath(String path)
Finds the manager for the menu at the given path.
|
IContributionItem |
findUsingPath(String path)
Finds the contribution item at the given path.
|
String |
getId()
Returns the menu id.
|
ImageDescriptor |
getImageDescriptor()
Returns the image for this menu as an image descriptor.
|
Menu |
getMenu()
Returns the SWT menu control for this menu manager.
|
protected Item |
getMenuItem(int index)
Get an item from the implementation's widget.
|
protected int |
getMenuItemCount()
Get the menu item count for the implementation's widget.
|
protected Item[] |
getMenuItems()
Get all the items from the implementation's widget.
|
String |
getMenuText()
Returns the text shown in the menu, potentially with a shortcut
appended.
|
IContributionManagerOverrides |
getOverrides()
The
ContributionManager implementation of this method
declared on IContributionManager returns the current
overrides. |
IContributionManager |
getParent()
Returns the parent contribution manager of this manger.
|
boolean |
getRemoveAllWhenShown()
Returns whether all items should be removed when the menu is about to
show, but before notifying menu listeners.
|
boolean |
isDynamic()
Returns whether this contribution item is dynamic.
|
boolean |
isEnabled()
Returns whether this menu should be enabled or not.
|
boolean |
isGroupMarker()
Returns whether this contribution item is a group marker.
|
boolean |
isSeparator()
Returns whether this contribution item is a separator.
|
boolean |
isSubstituteFor(IContributionItem item)
Deprecated.
this method is no longer a part of the
IContributionItem API. |
boolean |
isVisible()
Returns whether this contribution item is visibile within its manager.
|
void |
markDirty()
The
MenuManager implementation of this ContributionManager method
also propagates the dirty flag up the parent chain. |
protected boolean |
menuExist()
Returns whether the menu control is created
and not disposed.
|
void |
removeMenuListener(IMenuListener listener)
Removes the given menu listener from this menu.
|
void |
saveWidgetState()
Saves any state information of the control(s) owned by this contribution item.
|
void |
setActionDefinitionId(String definitionId)
Sets the action definition id of this action.
|
void |
setImageDescriptor(ImageDescriptor imageDescriptor) |
void |
setMenuText(String menuText) |
void |
setOverrides(IContributionManagerOverrides newOverrides)
Sets the overrides for this contribution manager
|
void |
setParent(IContributionManager manager)
Sets the parent manager of this item
|
void |
setRemoveAllWhenShown(boolean removeAll)
Sets whether all items should be removed when the menu is about to show,
but before notifying menu listeners.
|
void |
setVisible(boolean visible)
Sets whether this contribution item is visibile within its manager.
|
void |
update()
Updates any SWT controls cached by this contribution item with any
changes which have been made to this contribution item since the last update.
|
void |
update(boolean force)
The
MenuManager implementation of this IContributionManager
updates this menu, but not any of its submenus. |
protected void |
update(boolean force,
boolean recursive)
Incrementally builds the menu from the contribution items.
|
void |
update(String property)
Updates any SWT controls cached by this contribution item with changes
for the the given property.
|
void |
updateAll(boolean force)
Incrementally builds the menu from the contribution items, and
does so recursively for all submenus.
|
add, 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, setDirty
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
add, add, appendToGroup, appendToGroup, find, getItems, insertAfter, insertAfter, insertBefore, insertBefore, isDirty, isEmpty, prependToGroup, prependToGroup, remove, remove, removeAll
isDirty
protected boolean visible
true
by default.public MenuManager()
null
.
Typically used for creating a context menu, where it doesn't need to be referred to by id.public MenuManager(String text)
null
.
Typically used for creating a sub-menu, where it doesn't need to be referred to by id.text
- the text for the menu, or null
if nonepublic MenuManager(String text, String id)
text
- the text for the menu, or null
if noneid
- the menu id, or null
if it is to have no idpublic MenuManager(String text, ImageDescriptor image, String id)
text
- the text for the menu, or null
if noneimage
- the image for the menu, or null
if noneid
- the menu id, or null
if it is to have no idpublic void addMenuListener(IMenuListener listener)
IMenuManager
addMenuListener
in interface IMenuManager
listener
- a menu listenerpublic Menu createContextMenu(Control parent)
Note that the menu is not expected to be dynamic.
parent
- the parent controlpublic Menu createMenuBar(Decorations parent)
Decorations
, and installs all registered
contributions. Does not create a new control if one already exists.parent
- the parent decorations@Deprecated public Menu createMenuBar(Shell parent)
createMenuBar(Decorations)
instead.Shell
, and installs all registered contributions. Does not
create a new control if one already exists. This implementation simply calls
the createMenuBar(Decorations)
methodparent
- the parent decorationspublic void dispose()
ContributionManager.removeAll()
for that
purpose, but note that will not dispose the items.dispose
in interface IContributionItem
public void fill(Composite parent)
IContributionItem
StatusLineManager
.fill
in interface IContributionItem
parent
- the parent controlpublic void fill(CoolBar parent, int index)
IContributionItem
CoolBarManager
.fill
in interface IContributionItem
parent
- the parent cool barindex
- the index where the controls are inserted,
or -1
to insert at the endpublic void fill(Menu parent, int index)
IContributionItem
MenuManager
.fill
in interface IContributionItem
parent
- the parent menuindex
- the index where the controls are inserted,
or -1
to insert at the endpublic void fill(ToolBar parent, int index)
IContributionItem
ToolBarManager
.fill
in interface IContributionItem
parent
- the parent tool barindex
- the index where the controls are inserted,
or -1
to insert at the endpublic IMenuManager findMenuUsingPath(String path)
IMenuManager
'/'
.
Convenience for findUsingPath(path)
which
extracts an IMenuManager
if possible.
findMenuUsingPath
in interface IMenuManager
path
- the path stringnull
if there is no such contribution item or if the item does
not have an associated menu managerpublic IContributionItem findUsingPath(String path)
IMenuManager
'/'
.findUsingPath
in interface IMenuManager
path
- the path stringnull
if there is no
such contribution itempublic String getId()
getId
in interface IContributionItem
public Menu getMenu()
public String getMenuText()
public ImageDescriptor getImageDescriptor()
null
if this menu has no imagepublic IContributionManagerOverrides getOverrides()
ContributionManager
ContributionManager
implementation of this method
declared on IContributionManager
returns the current
overrides. If there is no overrides it lazily creates one which overrides
no item state.getOverrides
in interface IContributionManager
getOverrides
in class ContributionManager
public IContributionManager getParent()
public boolean getRemoveAllWhenShown()
IMenuManager
false
.getRemoveAllWhenShown
in interface IMenuManager
true
if all items should be removed when shown,
false
if notpublic boolean isDynamic()
IContributionItem
isDynamic
in interface IContributionItem
true
if this item is dynamic, and
false
for normal itemspublic boolean isEnabled()
The default implementation of this framework method
returns true
. Subclasses may reimplement.
isEnabled
in interface IContributionItem
isEnabled
in interface IMenuManager
true
if enabled, and
false
if disabledpublic boolean isGroupMarker()
IContributionItem
isGroupMarker
in interface IContributionItem
true
if this item is a group marker, and
false
for normal itemsGroupMarker
,
IContributionManager.appendToGroup(String, IContributionItem)
,
IContributionManager.prependToGroup(String, IContributionItem)
public boolean isSeparator()
IContributionItem
isSeparator
in interface IContributionItem
true
if this item is a separator, and
false
for normal itemsSeparator
@Deprecated public boolean isSubstituteFor(IContributionItem item)
IContributionItem
API.item
- the contribution itemtrue
if give item is a substitution for ourselvespublic boolean isVisible()
IContributionItem
isVisible
in interface IContributionItem
true
if this item is visible, and
false
otherwisepublic void markDirty()
MenuManager
implementation of this ContributionManager
method
also propagates the dirty flag up the parent chain.markDirty
in interface IContributionManager
markDirty
in class ContributionManager
protected boolean menuExist()
true
if the control is created
and not disposed, false
otherwisepublic void removeMenuListener(IMenuListener listener)
IMenuManager
removeMenuListener
in interface IMenuManager
listener
- the menu listenerpublic void saveWidgetState()
IContributionItem
saveWidgetState
in interface IContributionItem
public void setOverrides(IContributionManagerOverrides newOverrides)
setOverrides
in class ContributionManager
newOverrides
- the overrides for the items of this managerpublic void setParent(IContributionManager manager)
IContributionItem
setParent
in interface IContributionItem
manager
- the parent contribution managerpublic void setRemoveAllWhenShown(boolean removeAll)
IMenuManager
setRemoveAllWhenShown
in interface IMenuManager
removeAll
- true
if all items should be removed when shown,
false
if notpublic void setVisible(boolean visible)
IContributionItem
setVisible
in interface IContributionItem
visible
- true
if this item should be visible, and
false
otherwisepublic void setActionDefinitionId(String definitionId)
definitionId
- the command definition idpublic void update()
IContributionItem
update
in interface IContributionItem
public void update(boolean force)
MenuManager
implementation of this IContributionManager
updates this menu, but not any of its submenus.update
in interface IContributionManager
force
- true
means update even if not dirty,
and false
for normal incremental updatingupdateAll(boolean)
protected Item[] getMenuItems()
protected Item getMenuItem(int index)
index
- of the itemprotected int getMenuItemCount()
protected void doItemFill(IContributionItem ci, int index)
IContributionItem
's fill method with the
implementation's widget. The default is to use the Menu
widget.fill(Menu menu, int index)
ci
- An IContributionItem
whose fill()
method should be called.index
- The position the fill()
method should start
inserting at.protected void update(boolean force, boolean recursive)
force
- true
means update even if not dirty,
and false
for normal incremental updatingrecursive
- true
means recursively update
all submenus, and false
means just this menupublic void update(String property)
IContributionItem
update
in interface IContributionItem
property
- the id of the changed propertypublic void updateAll(boolean force)
IMenuManager
updateAll
in interface IMenuManager
force
- true
means update even if not dirty,
and false
for normal incremental updatingpublic void setMenuText(String menuText)
menuText
- The text (label) of the menu.public void setImageDescriptor(ImageDescriptor imageDescriptor)
imageDescriptor
- The image descriptor to set.
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.