com.vaadin.ui
Class MenuBar.MenuItem

java.lang.Object
  extended by com.vaadin.ui.MenuBar.MenuItem
All Implemented Interfaces:
Serializable
Enclosing class:
MenuBar

public class MenuBar.MenuItem
extends Object
implements Serializable

A composite class for menu items and sub-menus. You can set commands to be fired on user click by implementing the MenuBar.Command interface. You can also add multiple MenuItems to a MenuItem and create a sub-menu.

See Also:
Serialized Form

Constructor Summary
MenuBar.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.
 
Method Summary
 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.
 String getDescription()
           Gets the items's description.
 Resource getIcon()
          Gets the objects icon.
 int getId()
          Get the unique identifier for this item.
 MenuBar.MenuItem getParent()
          For the containing item.
 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)
          Sets the items's description.
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuBar.MenuItem

public MenuBar.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. Icon and command can be null, but a caption must be given.

Parameters:
text - The text associated with the command
command - The command to be fired
Throws:
IllegalArgumentException
Method Detail

hasChildren

public boolean hasChildren()
Checks if the item has children (if it is a sub-menu).

Returns:
True if this item has children

addSeparator

public MenuBar.MenuItem 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.

Since:
6.2.0

addSeparatorBefore

public MenuBar.MenuItem addSeparatorBefore(MenuBar.MenuItem itemToAddBefore)

addItem

public MenuBar.MenuItem addItem(String caption,
                                MenuBar.Command command)
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 item
command - the command for the menu item

addItem

public MenuBar.MenuItem addItem(String caption,
                                Resource icon,
                                MenuBar.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 item
icon - the icon for the menu item
command - the command for the menu item
Throws:
IllegalStateException - If the item is checkable and thus cannot have children.

addItemBefore

public MenuBar.MenuItem addItemBefore(String caption,
                                      Resource icon,
                                      MenuBar.Command command,
                                      MenuBar.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 item
icon - the icon for the menu item
command - the command for the menu item
itemToAddBefore - the item that will be after the new item
Throws:
IllegalStateException - If the item is checkable and thus cannot have children.

getCommand

public MenuBar.Command getCommand()
For the associated command.

Returns:
The associated command, or null if there is none

getIcon

public Resource getIcon()
Gets the objects icon.

Returns:
The icon of the item, null if the item doesn't have an icon

getParent

public MenuBar.MenuItem getParent()
For the containing item. This will return null if the item is in the top-level menu bar.

Returns:
The containing MenuBar.MenuItem , or null if there is none

getChildren

public List<MenuBar.MenuItem> 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

public String 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

public void setCommand(MenuBar.Command command)
Set the command for this item. Set null to remove.

Parameters:
command - The MenuCommand of this item

setIcon

public void setIcon(Resource icon)
Sets the icon. Set null to remove.

Parameters:
icon - The icon for this item

setText

public void setText(String text)
Set the text of this object.

Parameters:
text - Text for this object

removeChild

public void removeChild(MenuBar.MenuItem item)
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

protected void setParent(MenuBar.MenuItem parent)
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

public void setStyleName(String styleName)

getStyleName

public String getStyleName()

setDescription

public void setDescription(String description)
Sets the items's description. See getDescription() for more information on what the description is. This method will trigger a RepaintRequestEvent.

Parameters:
description - the new description string for the component.

getDescription

public String 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 by isChecked()) is indicated in the UI.

An item is not checkable by default.

Returns:
true if the item is checkable, false otherwise
Since:
6.6.2

setCheckable

public void setCheckable(boolean checkable)
                  throws IllegalStateException
Sets the checkable state of the item. If an item is checkable its checked state (as returned by isChecked()) 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
Since:
6.6.2

isChecked

public boolean isChecked()
Gets the checked state of the item (checked or unchecked). Only used if the item is checkable (as indicated by 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".

Returns:
true if the item is checked, false otherwise
Since:
6.6.2

setChecked

public void setChecked(boolean checked)
Sets the checked state of the item. Only used if the item is checkable (indicated by 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".

Since:
6.6.2


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.