public class

MenuItem

extends UIObject
implements HasSafeHtml HasEnabled HasHTML
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.MenuItem

Class Overview

An entry in a MenuBar. Menu items can either fire a Command when they are clicked, or open a cascading sub-menu. Each menu item is assigned a unique DOM id in order to support ARIA. See Accessibility for more information.

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
MenuItem(SafeHtml html)
Constructs a new menu item that fires a command when it is selected.
MenuItem(SafeHtml html, Command cmd)
Constructs a new menu item that fires a command when it is selected.
MenuItem(SafeHtml html, MenuBar subMenu)
Constructs a new menu item that cascades to a sub-menu when it is selected.
MenuItem(String text, boolean asHTML, Command cmd)
Constructs a new menu item that fires a command when it is selected.
MenuItem(String text, boolean asHTML, MenuBar subMenu)
Constructs a new menu item that cascades to a sub-menu when it is selected.
MenuItem(String text, Command cmd)
Constructs a new menu item that fires a command when it is selected.
MenuItem(String text, MenuBar subMenu)
Constructs a new menu item that cascades to a sub-menu when it is selected.
Public Methods
Command getCommand()
Gets the command associated with this item.
String getHTML()
Gets this object's contents as HTML.
MenuBar getParentMenu()
Gets the menu that contains this item.
MenuBar getSubMenu()
Gets the sub-menu associated with this item.
String getText()
Gets this object's text.
boolean isEnabled()
Returns true if the widget is enabled, false if not.
void setCommand(Command cmd)
Sets the command associated with this item.
void setEnabled(boolean enabled)
Sets whether this widget is enabled.
void setHTML(SafeHtml html)
Sets this object's contents via known-safe HTML.
void setHTML(String html)
Sets this object's contents via HTML.
void setSubMenu(MenuBar subMenu)
Sets the sub-menu associated with this item.
void setText(String text)
Sets this object's text.
Protected Methods
void onEnsureDebugId(String baseID)
Also sets the Debug IDs of MenuItems in the submenu of this MenuItem if a submenu exists.
void setSelectionStyle(boolean selected)
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.safehtml.client.HasSafeHtml
From interface com.google.gwt.user.client.ui.HasEnabled
From interface com.google.gwt.user.client.ui.HasHTML
From interface com.google.gwt.user.client.ui.HasText

Public Constructors

public MenuItem (SafeHtml html)

Constructs a new menu item that fires a command when it is selected.

Parameters
html the item's html text

public MenuItem (SafeHtml html, Command cmd)

Constructs a new menu item that fires a command when it is selected.

Parameters
html the item's text
cmd the command to be fired when it is selected

public MenuItem (SafeHtml html, MenuBar subMenu)

Constructs a new menu item that cascades to a sub-menu when it is selected.

Parameters
html the item's text
subMenu the sub-menu to be displayed when it is selected

public MenuItem (String text, boolean asHTML, Command cmd)

Constructs a new menu item that fires a command when it is selected.

Parameters
text the item's text
asHTML true to treat the specified text as html
cmd the command to be fired when it is selected

public MenuItem (String text, boolean asHTML, MenuBar subMenu)

Constructs a new menu item that cascades to a sub-menu when it is selected.

Parameters
text the item's text
asHTML true to treat the specified text as html
subMenu the sub-menu to be displayed when it is selected

public MenuItem (String text, Command cmd)

Constructs a new menu item that fires a command when it is selected.

Parameters
text the item's text
cmd the command to be fired when it is selected

public MenuItem (String text, MenuBar subMenu)

Constructs a new menu item that cascades to a sub-menu when it is selected.

Parameters
text the item's text
subMenu the sub-menu to be displayed when it is selected

Public Methods

public Command getCommand ()

Gets the command associated with this item.

Returns
  • this item's command, or null if none exists

public String getHTML ()

Gets this object's contents as HTML.

Returns
  • the object's HTML

public MenuBar getParentMenu ()

Gets the menu that contains this item.

Returns
  • the parent menu, or null if none exists.

public MenuBar getSubMenu ()

Gets the sub-menu associated with this item.

Returns
  • this item's sub-menu, or null if none exists

public String getText ()

Gets this object's text.

Returns
  • the object's text

public boolean isEnabled ()

Returns true if the widget is enabled, false if not.

public void setCommand (Command cmd)

Sets the command associated with this item.

Parameters
cmd the command to be associated with this item

public void setEnabled (boolean enabled)

Sets whether this widget is enabled.

Parameters
enabled true to enable the widget, false to disable it

public void setHTML (SafeHtml html)

Sets this object's contents via known-safe HTML.

The object will behave exactly the same as when a widget's setHTML(String) method is invoked; however the SafeHtml passed to this method observes the contract that it can be used in an HTML context without causing unsafe script execution. Thus, unlike setHTML(String), using this method cannot result in Cross-Site Scripting security vulnerabilities.

Parameters
html the object's new HTML, represented as a SafeHtml object

public void setHTML (String html)

Sets this object's contents via HTML. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using setText(String) whenever possible.

Parameters
html the object's new HTML

public void setSubMenu (MenuBar subMenu)

Sets the sub-menu associated with this item.

Parameters
subMenu this item's new sub-menu

public void setText (String text)

Sets this object's text.

Parameters
text the object's new text

Protected Methods

protected void onEnsureDebugId (String baseID)

Also sets the Debug IDs of MenuItems in the submenu of this MenuItem if a submenu exists.

Parameters
baseID the base ID used by the main element

protected void setSelectionStyle (boolean selected)