public class MenuBar.MenuItem extends Object implements Serializable, EventTrigger
MenuBar.Command
interface. You can also add
multiple MenuItems to a MenuItem and create a sub-menu.Constructor and Description |
---|
MenuItem(String caption,
Resource icon,
MenuBar.Command command)
Constructs a new menu item that can optionally have an icon and a
command associated with it.
|
Modifier and Type | Method and Description |
---|---|
MenuBar.MenuItem |
addItem(String caption)
Add a new menu item inside this menu item, creating a sub-menu.
|
MenuBar.MenuItem |
addItem(String caption,
MenuBar.Command command)
Add a new item inside this item, thus creating a sub-menu.
|
MenuBar.MenuItem |
addItem(String caption,
Resource icon,
MenuBar.Command command)
Add a new item inside this item, thus creating a sub-menu.
|
MenuBar.MenuItem |
addItemBefore(String caption,
Resource icon,
MenuBar.Command command,
MenuBar.MenuItem itemToAddBefore)
Add an item before some item.
|
MenuBar.MenuItem |
addSeparator()
Adds a separator to this menu.
|
MenuBar.MenuItem |
addSeparatorBefore(MenuBar.MenuItem itemToAddBefore) |
List<MenuBar.MenuItem> |
getChildren()
This will return the children of this item or null if there are none.
|
MenuBar.Command |
getCommand()
For the associated command.
|
AbstractClientConnector |
getConnector()
Gets the connector who will be used to offer the file download.
|
String |
getDescription()
Gets the item's description.
|
ContentMode |
getDescriptionContentMode()
Gets the content mode of the description of the menu item.
|
Resource |
getIcon()
Gets the objects icon.
|
int |
getId()
Get the unique identifier for this item.
|
MenuBar |
getMenuBar()
Gets the menu bar this item is part of.
|
MenuBar.MenuItem |
getParent()
For the containing item.
|
String |
getPartInformation()
Gets a free form string which identifies which part of the connector that
should trigger the download.
|
int |
getSize()
Returns the number of children.
|
String |
getStyleName() |
String |
getText()
Gets the objects text.
|
boolean |
hasChildren()
Checks if the item has children (if it is a sub-menu).
|
boolean |
isCheckable()
Gets the checkable state of the item - whether the item has checked
and unchecked states.
|
boolean |
isChecked()
Gets the checked state of the item (checked or unchecked).
|
boolean |
isEnabled() |
boolean |
isSeparator() |
boolean |
isVisible() |
void |
removeChild(MenuBar.MenuItem item)
Remove the first occurrence of the item.
|
void |
removeChildren()
Empty the list of children items.
|
void |
setCheckable(boolean checkable)
Sets the checkable state of the item.
|
void |
setChecked(boolean checked)
Sets the checked state of the item.
|
void |
setCommand(MenuBar.Command command)
Set the command for this item.
|
void |
setDescription(String description)
Analogous method to
AbstractComponent.setDescription(String) . |
void |
setDescription(String description,
ContentMode mode)
Analogous method to
AbstractComponent.setDescription(String, ContentMode) . |
void |
setEnabled(boolean enabled) |
void |
setIcon(Resource icon)
Sets the icon.
|
protected void |
setParent(MenuBar.MenuItem parent)
Set the parent of this item.
|
void |
setStyleName(String styleName) |
void |
setText(String text)
Set the text of this object.
|
void |
setVisible(boolean visible) |
public MenuItem(String caption, Resource icon, MenuBar.Command command)
caption
- The text associated with the commandcommand
- The command to be firedIllegalArgumentException
public boolean hasChildren()
public MenuBar.MenuItem addSeparator()
public MenuBar.MenuItem addSeparatorBefore(MenuBar.MenuItem itemToAddBefore)
public MenuBar.MenuItem addItem(String caption)
Clicking on the new item has no effect. Use
MenuBar.addItem(String, Command)
or #setCommand(Command)
to
assign an action to the menu item.
caption
- the text for the menu itempublic MenuBar.MenuItem addItem(String caption, MenuBar.Command command)
caption
- the text for the menu itemcommand
- the command for the menu itempublic MenuBar.MenuItem addItem(String caption, Resource icon, MenuBar.Command command) throws IllegalStateException
caption
- the text for the menu itemicon
- the icon for the menu itemcommand
- the command for the menu itemIllegalStateException
- If the item is checkable and thus cannot have children.public MenuBar.MenuItem addItemBefore(String caption, Resource icon, MenuBar.Command command, MenuBar.MenuItem itemToAddBefore) throws IllegalStateException
caption
- the text for the menu itemicon
- the icon for the menu itemcommand
- the command for the menu itemitemToAddBefore
- the item that will be after the new itemIllegalStateException
- If the item is checkable and thus cannot have children.public MenuBar.Command getCommand()
public Resource getIcon()
public MenuBar.MenuItem getParent()
MenuBar.MenuItem
, or
null if there is nonepublic List<MenuBar.MenuItem> getChildren()
public String getText()
public int getSize()
public int getId()
public void setCommand(MenuBar.Command command)
command
- The MenuCommand of this itempublic void setIcon(Resource icon)
icon
- The icon for this itempublic void setText(String text)
text
- Text for this objectpublic void removeChild(MenuBar.MenuItem item)
item
- The item to be removedpublic void removeChildren()
protected void setParent(MenuBar.MenuItem parent)
parent
- The parent itempublic void setEnabled(boolean enabled)
public boolean isEnabled()
public void setVisible(boolean visible)
public boolean isVisible()
public boolean isSeparator()
public void setStyleName(String styleName)
public String getStyleName()
public void setDescription(String description)
AbstractComponent.setDescription(String)
.
Sets the item's description. See getDescription()
for more
information on what the description is.description
- the new description string for the component.public void setDescription(String description, ContentMode mode)
AbstractComponent.setDescription(String, ContentMode)
. Sets
the item's description using given content mode. See
getDescription()
for more information on what the
description is.
If the content mode
is ContentMode.HTML the
description is displayed as HTML in tooltips or directly in certain
components so care should be taken to avoid creating the possibility
for HTML injection and possibly XSS vulnerabilities.
description
- the new description string for the component.mode
- the content mode for the descriptionContentMode
public String getDescription()
Gets the item's description. The description can be used to briefly describe the state of the item to the user. The description string may contain certain XML tags:
Tag | Description | Example |
<b> | bold | bold text |
<i> | italic | italic text |
<u> | underlined | underlined text |
<br> | linebreak | N/A |
<ul> <li>item1 <li>item1 </ul> |
item list |
|
These tags may be nested.
String
public ContentMode getDescriptionContentMode()
If no content mode was explicitly set using the
setDescription(String, ContentMode)
method, the content mode
will be ContentMode.PREFORMATTED
ContentMode
of the description of this menu itemContentMode
public boolean isCheckable()
isChecked()
) is indicated in the UI.
An item is not checkable by default.
public void setCheckable(boolean checkable) throws IllegalStateException
isChecked()
) is indicated in
the UI.
An item is not checkable by default.
Items with sub items cannot be checkable.
checkable
- true if the item should be checkable, false otherwiseIllegalStateException
- If the item has childrenpublic boolean isChecked()
isCheckable()
).
The checked state is indicated in the UI with the item, if the item
is checkable.
An item is not checked by default.
The CSS style corresponding to the checked state is "-checked".
public void setChecked(boolean checked)
isCheckable()
). The checked state is
indicated in the UI with the item, if the item is checkable.
An item is not checked by default.
The CSS style corresponding to the checked state is "-checked".
public MenuBar getMenuBar()
public AbstractClientConnector getConnector()
EventTrigger
getConnector
in interface EventTrigger
public String getPartInformation()
EventTrigger
For example, MenuBar
passes the id of a menu item through this
method so that the client side can listen to events for that particular
item only.
getPartInformation
in interface EventTrigger
Copyright © 2019 Vaadin Ltd. All rights reserved.