GWT 2.0.3

com.google.gwt.user.client.ui
Class MenuItem

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.MenuItem
All Implemented Interfaces:
HasHTML, HasText

public class MenuItem
extends UIObject
implements HasHTML

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.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
MenuItem(java.lang.String text, boolean asHTML, Command cmd)
          Constructs a new menu item that fires a command when it is selected.
MenuItem(java.lang.String text, boolean asHTML, MenuBar subMenu)
          Constructs a new menu item that cascades to a sub-menu when it is selected.
MenuItem(java.lang.String text, Command cmd)
          Constructs a new menu item that fires a command when it is selected.
MenuItem(java.lang.String text, MenuBar subMenu)
          Constructs a new menu item that cascades to a sub-menu when it is selected.
 
Method Summary
 Command getCommand()
          Gets the command associated with this item.
 java.lang.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.
 java.lang.String getText()
          Gets this object's text.
protected  void onEnsureDebugId(java.lang.String baseID)
          Also sets the Debug IDs of MenuItems in the submenu of this MenuItem if a submenu exists.
 void setCommand(Command cmd)
          Sets the command associated with this item.
 void setHTML(java.lang.String html)
          Sets this object's contents via HTML.
protected  void setSelectionStyle(boolean selected)
           
 void setSubMenu(MenuBar subMenu)
          Sets the sub-menu associated with this item.
 void setText(java.lang.String text)
          Sets this object's text.
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MenuItem

public MenuItem(java.lang.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

MenuItem

public MenuItem(java.lang.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

MenuItem

public MenuItem(java.lang.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

MenuItem

public MenuItem(java.lang.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
Method Detail

getCommand

public Command getCommand()
Gets the command associated with this item.

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

getHTML

public java.lang.String getHTML()
Description copied from interface: HasHTML
Gets this object's contents as HTML.

Specified by:
getHTML in interface HasHTML
Returns:
the object's HTML

getParentMenu

public MenuBar getParentMenu()
Gets the menu that contains this item.

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

getSubMenu

public MenuBar getSubMenu()
Gets the sub-menu associated with this item.

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

getText

public java.lang.String getText()
Description copied from interface: HasText
Gets this object's text.

Specified by:
getText in interface HasText
Returns:
the object's text

setCommand

public void setCommand(Command cmd)
Sets the command associated with this item.

Parameters:
cmd - the command to be associated with this item

setHTML

public void setHTML(java.lang.String html)
Description copied from interface: HasHTML
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 HasText.setText(String) whenever possible.

Specified by:
setHTML in interface HasHTML
Parameters:
html - the object's new HTML

setSubMenu

public void setSubMenu(MenuBar subMenu)
Sets the sub-menu associated with this item.

Parameters:
subMenu - this item's new sub-menu

setText

public void setText(java.lang.String text)
Description copied from interface: HasText
Sets this object's text.

Specified by:
setText in interface HasText
Parameters:
text - the object's new text

onEnsureDebugId

protected void onEnsureDebugId(java.lang.String baseID)
Also sets the Debug IDs of MenuItems in the submenu of this MenuItem if a submenu exists.

Overrides:
onEnsureDebugId in class UIObject
Parameters:
baseID - the base ID used by the main element
See Also:
UIObject.onEnsureDebugId(String)

setSelectionStyle

protected void setSelectionStyle(boolean selected)

GWT 2.0.3