com.itmill.toolkit.ui
Class MenuBar.MenuItem

java.lang.Object
  extended by com.itmill.toolkit.ui.MenuBar.MenuItem
Enclosing class:
MenuBar

public class MenuBar.MenuItem
extends Object

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.


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.
 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.
 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 getText()
          Gets the objects text
 boolean hasChildren()
          Checks if the item has children (if it is a sub-menu).
 void removeChild(MenuBar.MenuItem item)
          Remove the first occurrence of the item.
 void removeChildren()
          Empty the list of children items.
 void setCommand(MenuBar.Command command)
          Set the command for this item.
 void setIcon(Resource icon)
          Sets the icon.
protected  void setParent(MenuBar.MenuItem parent)
          Set the parent of this item.
 void setText(String text)
          Set the text of this object.
 
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

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)
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

addItemBefore

public MenuBar.MenuItem addItemBefore(String caption,
                                      Resource icon,
                                      MenuBar.Command command,
                                      MenuBar.MenuItem itemToAddBefore)
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

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


Copyright © 2000-2009 IT Mill Ltd. All Rights Reserved.