Package com.google.gwt.user.client.ui
Class MenuItem
java.lang.Object
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.MenuItem
- All Implemented Interfaces:
HasSafeHtml
,HasEnabled
,HasHTML
,HasText
,HasVisibility
An entry in a
MenuBar
. Menu items can either fire a
Scheduler.ScheduledCommand
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, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
-
Constructor Summary
ConstructorDescriptionConstructs a new menu item that fires a command when it is selected.MenuItem
(SafeHtml html, Scheduler.ScheduledCommand cmd) Constructs a new menu item that fires a command when it is selected.Constructs a new menu item that cascades to a sub-menu when it is selected.MenuItem
(String text, boolean asHTML, Scheduler.ScheduledCommand cmd) Constructs a new menu item that fires a command when it is selected.Constructs a new menu item that cascades to a sub-menu when it is selected.MenuItem
(String text, Scheduler.ScheduledCommand cmd) Constructs a new menu item that fires a command when it is selected.Constructs a new menu item that cascades to a sub-menu when it is selected. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.getHTML()
Gets this object's contents as HTML.Gets the menu that contains this item.Gets the scheduled command associated with this item.Gets the sub-menu associated with this item.getText()
Gets this object's text.boolean
Returns true if the widget is enabled, false if not.protected void
onEnsureDebugId
(String baseID) Also sets the Debug IDs of MenuItems in the submenu of thisMenuItem
if a submenu exists.void
setCommand
(Command cmd) Deprecated.usesetScheduledCommand(ScheduledCommand)
insteadvoid
setEnabled
(boolean enabled) Sets whether this widget is enabled.void
Sets this object's contents via known-safe HTML.void
Sets this object's contents via HTML.(package private) void
setParentMenu
(MenuBar parentMenu) void
Sets the scheduled command associated with this item.protected void
setSelectionStyle
(boolean selected) void
setSubMenu
(MenuBar subMenu) Sets the sub-menu associated with this item.void
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, replaceElement, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, sinkEvents, toString, unsinkEvents
-
Constructor Details
-
MenuItem
Constructs a new menu item that fires a command when it is selected.- Parameters:
text
- the item's textasHTML
-true
to treat the specified text as htmlcmd
- the command to be fired when it is selected
-
MenuItem
Constructs a new menu item that cascades to a sub-menu when it is selected.- Parameters:
text
- the item's textasHTML
-true
to treat the specified text as htmlsubMenu
- the sub-menu to be displayed when it is selected
-
MenuItem
Constructs a new menu item that fires a command when it is selected.- Parameters:
text
- the item's textcmd
- the command to be fired when it is selected
-
MenuItem
Constructs a new menu item that cascades to a sub-menu when it is selected.- Parameters:
text
- the item's textsubMenu
- the sub-menu to be displayed when it is selected
-
MenuItem
MenuItem(String text, boolean asHTML)
-
Method Details
-
getCommand
Deprecated.usegetScheduledCommand()
insteadGets the command associated with this item. If a scheduled command is associated with this item a command that can be used to execute the scheduled command will be returned.- Returns:
- the command
-
getHTML
Description copied from interface:HasHTML
Gets this object's contents as HTML. -
getParentMenu
Gets the menu that contains this item.- Returns:
- the parent menu, or
null
if none exists.
-
getScheduledCommand
Gets the scheduled command associated with this item.- Returns:
- this item's scheduled command, or
null
if none exists
-
getSubMenu
Gets the sub-menu associated with this item.- Returns:
- this item's sub-menu, or
null
if none exists
-
getText
Description copied from interface:HasText
Gets this object's text. -
isEnabled
public boolean isEnabled()Description copied from interface:HasEnabled
Returns true if the widget is enabled, false if not.- Specified by:
isEnabled
in interfaceHasEnabled
-
setCommand
Deprecated.usesetScheduledCommand(ScheduledCommand)
insteadSets the command associated with this item.- Parameters:
cmd
- the command to be associated with this item
-
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:HasEnabled
Sets whether this widget is enabled.- Specified by:
setEnabled
in interfaceHasEnabled
- Parameters:
enabled
-true
to enable the widget,false
to disable it
-
setHTML
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 usingHasText.setText(String)
whenever possible. -
setScheduledCommand
Sets the scheduled command associated with this item.- Parameters:
cmd
- the scheduled command to be associated with this item
-
setSubMenu
Sets the sub-menu associated with this item.- Parameters:
subMenu
- this item's new sub-menu
-
setText
Description copied from interface:HasText
Sets this object's text. -
onEnsureDebugId
Also sets the Debug IDs of MenuItems in the submenu of thisMenuItem
if a submenu exists.- Overrides:
onEnsureDebugId
in classUIObject
- Parameters:
baseID
- the base ID used by the main element- See Also:
-
setSelectionStyle
protected void setSelectionStyle(boolean selected) -
setParentMenu
-
getScheduledCommand()
instead