Package com.vaadin.featurepack.ui
Class FMenuBar.MenuItem
java.lang.Object
com.vaadin.featurepack.ui.FMenuBar.MenuItem
- All Implemented Interfaces:
Serializable
- Enclosing class:
FMenuBar
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMenuItem(String caption, Resource icon, FMenuBar.Command command) Constructs a new menu item that can optionally have an icon and a command associated with it. -
Method Summary
Modifier and TypeMethodDescriptionaddItem(String caption, Resource icon, FMenuBar.Command command) Add a new item inside this item, thus creating a sub-menu.addItem(String caption, FMenuBar.Command command) Add a new item inside this item, thus creating a sub-menu.addItemBefore(String caption, Resource icon, FMenuBar.Command command, FMenuBar.MenuItem itemToAddBefore) Add an item before some item.Adds a separator to this menu.addSeparatorBefore(FMenuBar.MenuItem itemToAddBefore) This will return the children of this item or null if there are none.For the associated command.Gets the items's description.getIcon()Gets the objects icon.intgetId()Get the unique identifier for this item.For the containing item.intgetSize()Returns the number of children.getText()Gets the objects textbooleanChecks if the item has children (if it is a sub-menu).booleanGets the checkable state of the item - whether the item has checked and unchecked states.booleanGets the checked state of the item (checked or unchecked).booleanbooleanbooleanvoidremoveChild(FMenuBar.MenuItem item) Remove the first occurrence of the item.voidEmpty the list of children items.voidsetCheckable(boolean checkable) Sets the checkable state of the item.voidsetChecked(boolean checked) Sets the checked state of the item.voidsetCommand(FMenuBar.Command command) Set the command for this item.voidsetDescription(String description) Sets the items's description.voidsetEnabled(boolean enabled) voidSets the icon.protected voidsetParent(FMenuBar.MenuItem parent) Set the parent of this item.voidsetStyleName(String styleName) voidSet the text of this object.voidsetVisible(boolean visible)
-
Constructor Details
-
MenuItem
Constructs a new menu item that can optionally have an icon and a command associated with it. Icon and command can be null, but a caption must be given.- Parameters:
caption- The text associated with the commandcommand- The command to be fired- Throws:
IllegalArgumentException
-
-
Method Details
-
hasChildren
public boolean hasChildren()Checks if the item has children (if it is a sub-menu).- Returns:
- True if this item has children
-
addSeparator
Adds a separator to this menu. A separator is a way to visually group items in a menu, to make it easier for users to find what they are looking for in the menu. -
addSeparatorBefore
-
addItem
Add a new item inside this item, thus creating a sub-menu. Command can be null, but a caption must be given.- Parameters:
caption- the text for the menu itemcommand- the command for the menu item
-
addItem
public FMenuBar.MenuItem addItem(String caption, Resource icon, FMenuBar.Command command) throws IllegalStateException Add a new item inside this item, thus creating a sub-menu. Icon and command can be null, but a caption must be given.- Parameters:
caption- the text for the menu itemicon- the icon for the menu itemcommand- the command for the menu item- Throws:
IllegalStateException- If the item is checkable and thus cannot have children.
-
addItemBefore
public FMenuBar.MenuItem addItemBefore(String caption, Resource icon, FMenuBar.Command command, FMenuBar.MenuItem itemToAddBefore) throws IllegalStateException Add an item before some item. If the given item does not exist the item is added at the end of the menu. Icon and command can be null, but a caption must be given.- Parameters:
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 item- Throws:
IllegalStateException- If the item is checkable and thus cannot have children.
-
getCommand
For the associated command.- Returns:
- The associated command, or null if there is none
-
getIcon
Gets the objects icon.- Returns:
- The icon of the item, null if the item doesn't have an icon
-
getParent
For the containing item. This will return null if the item is in the top-level menu bar.- Returns:
- The containing
FMenuBar.MenuItem, or null if there is none
-
getChildren
This will return the children of this item or null if there are none.- Returns:
- List of children items, or null if there are none
-
getText
Gets the objects text- Returns:
- The text
-
getSize
public int getSize()Returns the number of children.- Returns:
- The number of child items
-
getId
public int getId()Get the unique identifier for this item.- Returns:
- The id of this item
-
setCommand
Set the command for this item. Set null to remove.- Parameters:
command- The MenuCommand of this item
-
setIcon
Sets the icon. Set null to remove.- Parameters:
icon- The icon for this item
-
setText
Set the text of this object.- Parameters:
text- Text for this object
-
removeChild
Remove the first occurrence of the item.- Parameters:
item- The item to be removed
-
removeChildren
public void removeChildren()Empty the list of children items. -
setParent
Set the parent of this item. This is called by the addItem method.- Parameters:
parent- The parent item
-
setEnabled
public void setEnabled(boolean enabled) -
isEnabled
public boolean isEnabled() -
setVisible
public void setVisible(boolean visible) -
isVisible
public boolean isVisible() -
isSeparator
public boolean isSeparator() -
setStyleName
-
getStyleName
-
setDescription
Sets the items's description. SeegetDescription()for more information on what the description is.- Parameters:
description- the new description string for the component.
-
getDescription
Gets the items'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 - item1
- item2
These tags may be nested.
- Returns:
- item's description
String
-
isCheckable
public boolean isCheckable()Gets the checkable state of the item - whether the item has checked and unchecked states. If an item is checkable its checked state (as returned byisChecked()) is indicated in the UI.An item is not checkable by default.
- Returns:
- true if the item is checkable, false otherwise
-
setCheckable
Sets the checkable state of the item. If an item is checkable its checked state (as returned byisChecked()) is indicated in the UI.An item is not checkable by default.
Items with sub items cannot be checkable.
- Parameters:
checkable- true if the item should be checkable, false otherwise- Throws:
IllegalStateException- If the item has children
-
isChecked
public boolean isChecked()Gets the checked state of the item (checked or unchecked). Only used if the item is checkable (as indicated byisCheckable()). 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".
- Returns:
- true if the item is checked, false otherwise
-
setChecked
public void setChecked(boolean checked) Sets the checked state of the item. Only used if the item is checkable (indicated byisCheckable()). 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".
-