Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.eclipse.jface.action
Class MenuManager  view MenuManager download MenuManager.java

java.lang.Object
  extended byorg.eclipse.jface.action.ContributionManager
      extended byorg.eclipse.jface.action.MenuManager
All Implemented Interfaces:
IContributionItem, IContributionManager, IMenuManager

public class MenuManager
extends ContributionManager
implements 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 Summary
private  java.lang.String id
          The menu id.
private  org.eclipse.jface.util.ListenerList listeners
          List of registered menu listeners (element type: IMenuListener).
private  org.eclipse.swt.widgets.Menu menu
          The menu control; null before creation and after disposal.
private  org.eclipse.swt.widgets.MenuItem menuItem
          The menu item widget; null before creation and after disposal.
private  java.lang.String menuText
          The text for a sub-menu.
private  IContributionManagerOverrides overrides
          The overrides for items of this manager
private  IContributionManager parent
          The parent contribution manager.
private  boolean removeAllWhenShown
          Indicates whether removeAll should be called just before the menu is displayed.
private  boolean visible
          Indicates this item is visible in its manager; true by default.
 
Fields inherited from class org.eclipse.jface.action.ContributionManager
 
Constructor Summary
MenuManager()
          Creates a menu manager.
MenuManager(java.lang.String text)
          Creates a menu manager with the given text.
MenuManager(java.lang.String text, java.lang.String id)
          Creates a menu manager with the given text and id.
 
Method Summary
 void addMenuListener(IMenuListener listener)
          Adds a menu listener to this menu.
 org.eclipse.swt.widgets.Menu createContextMenu(org.eclipse.swt.widgets.Control parent)
          Creates and returns an SWT context menu control for this menu, and installs all registered contributions.
 org.eclipse.swt.widgets.Menu createMenuBar(org.eclipse.swt.widgets.Decorations parent)
          Creates and returns an SWT menu bar control for this menu, for use in the given Decorations, and installs all registered contributions.
 org.eclipse.swt.widgets.Menu createMenuBar(org.eclipse.swt.widgets.Shell parent)
          Deprecated. use createMenuBar(Decorations) instead.
 void dispose()
          Disposes of this menu manager and frees all allocated SWT resources.
 void fill(org.eclipse.swt.widgets.Composite parent)
          Fills the given composite control with controls representing this contribution item.
 void fill(org.eclipse.swt.widgets.CoolBar parent, int index)
          Fills the given cool bar with controls representing this contribution item.
 void fill(org.eclipse.swt.widgets.Menu parent, int index)
          Fills the given menu with controls representing this contribution item.
 void fill(org.eclipse.swt.widgets.ToolBar parent, int index)
          Fills the given tool bar with controls representing this contribution item.
 IMenuManager findMenuUsingPath(java.lang.String path)
          Finds the manager for the menu at the given path.
 IContributionItem findUsingPath(java.lang.String path)
          Finds the contribution item at the given path.
private  void fireAboutToShow(IMenuManager manager)
          Notifies any menu listeners that a menu is about to show.
 java.lang.String getId()
          Returns the menu id.
 org.eclipse.swt.widgets.Menu getMenu()
          Returns the SWT menu control for this menu manager.
 java.lang.String getMenuText()
          Returns the text shown in the menu.
 IContributionManagerOverrides getOverrides()
          Returns the overrides for the items of this manager.
 IContributionManager getParent()
          Returns the parent contribution manager of this manger.
 boolean getRemoveAllWhenShown()
          Returns whether all items should be removed when the menu is first shown, but before notifying menu listeners.
private  void handleAboutToShow()
          Notifies all listeners that this menu is about to appear.
private  void initializeMenu()
          Initializes the menu control.
 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.
private  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 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 first shown, 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(java.lang.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.
private  void updateMenuItem()
          Updates the menu item for this sub menu.
 
Methods inherited from class org.eclipse.jface.action.ContributionManager
add, add, allowItem, appendToGroup, appendToGroup, dumpStatistics, find, getItems, hasDynamicItems, indexOf, indexOf, insert, insertAfter, insertAfter, insertBefore, insertBefore, internalSetItems, isDirty, isEmpty, itemAdded, itemRemoved, markDirty, prependToGroup, prependToGroup, remove, remove, removeAll, replaceItem, setDirty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.action.IContributionManager
add, add, appendToGroup, appendToGroup, find, getItems, insertAfter, insertAfter, insertBefore, insertBefore, isDirty, isEmpty, markDirty, prependToGroup, prependToGroup, remove, remove, removeAll
 
Methods inherited from interface org.eclipse.jface.action.IContributionItem
isDirty
 

Field Detail

id

private java.lang.String id
The menu id.


listeners

private org.eclipse.jface.util.ListenerList listeners
List of registered menu listeners (element type: IMenuListener).


menu

private org.eclipse.swt.widgets.Menu menu
The menu control; null before creation and after disposal.


menuItem

private org.eclipse.swt.widgets.MenuItem menuItem
The menu item widget; null before creation and after disposal. This field is used when this menu manager is a sub-menu.


menuText

private java.lang.String menuText
The text for a sub-menu.


overrides

private IContributionManagerOverrides overrides
The overrides for items of this manager


parent

private IContributionManager parent
The parent contribution manager.


removeAllWhenShown

private boolean removeAllWhenShown
Indicates whether removeAll should be called just before the menu is displayed.


visible

private boolean visible
Indicates this item is visible in its manager; true by default.

Constructor Detail

MenuManager

public MenuManager()
Creates a menu manager. The text and id are null. Typically used for creating a context menu, where it doesn't need to be referred to by id.


MenuManager

public MenuManager(java.lang.String text)
Creates a menu manager with the given text. The id of the menu is null. Typically used for creating a sub-menu, where it doesn't need to be referred to by id.


MenuManager

public MenuManager(java.lang.String text,
                   java.lang.String id)
Creates 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.

Method Detail

addMenuListener

public void addMenuListener(IMenuListener listener)
Description copied from interface: IMenuManager
Adds a menu listener to this menu. Has no effect if an identical listener is already registered.

Specified by:
addMenuListener in interface IMenuManager

createContextMenu

public org.eclipse.swt.widgets.Menu createContextMenu(org.eclipse.swt.widgets.Control parent)
Creates 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.


createMenuBar

public org.eclipse.swt.widgets.Menu createMenuBar(org.eclipse.swt.widgets.Decorations parent)
Creates and returns an SWT menu bar control for this menu, for use in the given Decorations, and installs all registered contributions. Does not create a new control if one already exists.

Since:
2.1

createMenuBar

public org.eclipse.swt.widgets.Menu createMenuBar(org.eclipse.swt.widgets.Shell parent)
Deprecated. use createMenuBar(Decorations) instead.

Creates and returns an SWT menu bar control for this menu, for use in the given Shell, and installs all registered contributions. Does not create a new control if one already exists. This implementation simply calls the createMenuBar(Decorations) method


dispose

public void dispose()
Disposes of this menu manager and frees all allocated SWT resources. Notifies all contribution items of the dispose. Note that this method does not clean up references between this menu manager and its associated contribution items. Use removeAll for that purpose.

Specified by:
dispose in interface IContributionItem

fill

public void fill(org.eclipse.swt.widgets.Composite parent)
Description copied from interface: IContributionItem
Fills the given composite control with controls representing this contribution item. Used by StatusLineManager.

Specified by:
fill in interface IContributionItem

fill

public void fill(org.eclipse.swt.widgets.CoolBar parent,
                 int index)
Description copied from interface: IContributionItem
Fills the given cool bar with controls representing this contribution item. Used by CoolBarManager.

Specified by:
fill in interface IContributionItem

fill

public void fill(org.eclipse.swt.widgets.Menu parent,
                 int index)
Description copied from interface: IContributionItem
Fills the given menu with controls representing this contribution item. Used by MenuManager.

Specified by:
fill in interface IContributionItem

fill

public void fill(org.eclipse.swt.widgets.ToolBar parent,
                 int index)
Description copied from interface: IContributionItem
Fills the given tool bar with controls representing this contribution item. Used by ToolBarManager.

Specified by:
fill in interface IContributionItem

findMenuUsingPath

public IMenuManager findMenuUsingPath(java.lang.String path)
Description copied from interface: IMenuManager
Finds 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 an IMenuManager if possible.

Specified by:
findMenuUsingPath in interface IMenuManager

findUsingPath

public IContributionItem findUsingPath(java.lang.String path)
Description copied from interface: IMenuManager
Finds 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:
findUsingPath in interface IMenuManager

fireAboutToShow

private void fireAboutToShow(IMenuManager manager)
Notifies any menu listeners that a menu is about to show. Only listeners registered at the time this method is called are notified.


getId

public java.lang.String getId()
Returns 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:
getId in interface IContributionItem

getMenu

public org.eclipse.swt.widgets.Menu getMenu()
Returns the SWT menu control for this menu manager.


getMenuText

public java.lang.String getMenuText()
Returns the text shown in the menu.


getOverrides

public IContributionManagerOverrides getOverrides()
Description copied from interface: IContributionManager
Returns the overrides for the items of this manager.

Specified by:
getOverrides in interface IContributionManager
Overrides:
getOverrides in class ContributionManager

getParent

public IContributionManager getParent()
Returns the parent contribution manager of this manger.

Since:
2.0

getRemoveAllWhenShown

public boolean getRemoveAllWhenShown()
Description copied from interface: IMenuManager
Returns whether all items should be removed when the menu is first shown, but before notifying menu listeners. The default is false.

Specified by:
getRemoveAllWhenShown in interface IMenuManager

handleAboutToShow

private void handleAboutToShow()
Notifies all listeners that this menu is about to appear.


initializeMenu

private void initializeMenu()
Initializes the menu control.


isDynamic

public boolean isDynamic()
Description copied from interface: IContributionItem
Returns whether this contribution item is dynamic. A dynamic contribution item contributes items conditionally, dependent on some internal state.

Specified by:
isDynamic in interface IContributionItem

isEnabled

public 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:
isEnabled in interface IMenuManager

isGroupMarker

public boolean isGroupMarker()
Description copied from interface: IContributionItem
Returns whether this contribution item is a group marker. This information is used when adding items to a group.

Specified by:
isGroupMarker in interface IContributionItem

isSeparator

public boolean isSeparator()
Description copied from interface: IContributionItem
Returns whether this contribution item is a separator. This information is used to enable hiding of unnecessary separators.

Specified by:
isSeparator in interface IContributionItem

isSubstituteFor

public boolean isSubstituteFor(IContributionItem item)
Deprecated. this method is no longer a part of the IContributionItem API.


isVisible

public boolean isVisible()
Description copied from interface: IContributionItem
Returns whether this contribution item is visibile within its manager.

Specified by:
isVisible in interface IContributionItem

menuExist

private boolean menuExist()
Returns whether the menu control is created and not disposed.


removeMenuListener

public void removeMenuListener(IMenuListener listener)
Description copied from interface: IMenuManager
Removes the given menu listener from this menu. Has no effect if an identical listener is not registered.

Specified by:
removeMenuListener in interface IMenuManager

saveWidgetState

public void saveWidgetState()
Description copied from interface: IContributionItem
Saves 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:
saveWidgetState in interface IContributionItem

setOverrides

public void setOverrides(IContributionManagerOverrides newOverrides)
Sets the overrides for this contribution manager

Overrides:
setOverrides in class ContributionManager
Since:
2.0

setParent

public void setParent(IContributionManager manager)
Description copied from interface: IContributionItem
Sets the parent manager of this item

Specified by:
setParent in interface IContributionItem

setRemoveAllWhenShown

public void setRemoveAllWhenShown(boolean removeAll)
Description copied from interface: IMenuManager
Sets whether all items should be removed when the menu is first shown, but before notifying menu listeners.

Specified by:
setRemoveAllWhenShown in interface IMenuManager

setVisible

public void setVisible(boolean visible)
Description copied from interface: IContributionItem
Sets whether this contribution item is visibile within its manager.

Specified by:
setVisible in interface IContributionItem

update

public void update()
Description copied from interface: IContributionItem
Updates 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:
update in interface IContributionItem

update

public void update(boolean force)
The MenuManager implementation of this IContributionManager updates this menu, but not any of its submenus.

Specified by:
update in interface IContributionManager

update

protected 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.


update

public void update(java.lang.String property)
Description copied from interface: IContributionItem
Updates any SWT controls cached by this contribution item with changes for the the given property.

Specified by:
update in interface IContributionItem

updateAll

public void updateAll(boolean force)
Description copied from interface: IMenuManager
Incrementally builds the menu from the contribution items, and does so recursively for all submenus.

Specified by:
updateAll in interface IMenuManager

updateMenuItem

private void updateMenuItem()
Updates the menu item for this sub menu. The menu item is disabled if this sub menu is empty. Does nothing if this menu is not a submenu.