com.vaadin.ui
Class MenuBar

java.lang.Object
  extended by com.vaadin.terminal.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.MenuBar
All Implemented Interfaces:
MethodEventSource, Connector, ClientConnector, RpcTarget, Sizeable, Vaadin6Component, VariableOwner, Component, Serializable, EventListener

public class MenuBar
extends AbstractComponent
implements Vaadin6Component

A class representing a horizontal menu bar. The menu can contain MenuItem objects, which in turn can contain more MenuBars. These sub-level MenuBars are represented as vertical menu.

See Also:
Serialized Form

Nested Class Summary
static interface MenuBar.Command
          This interface contains the layer for menu commands of the MenuBar class.
 class MenuBar.MenuItem
          A composite class for menu items and sub-menus.
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.VariableOwner
VariableOwner.ErrorEvent
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.Sizeable
Sizeable.Unit
 
Field Summary
 
Fields inherited from interface com.vaadin.terminal.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
MenuBar()
          Constructs an empty, horizontal menu
 
Method Summary
 MenuBar.MenuItem addItem(String caption, MenuBar.Command command)
          Add a new item to the menu bar.
 MenuBar.MenuItem addItem(String caption, Resource icon, MenuBar.Command command)
          Add a new item to the menu bar.
 MenuBar.MenuItem addItemBefore(String caption, Resource icon, MenuBar.Command command, MenuBar.MenuItem itemToAddBefore)
          Add an item before some item.
 void changeVariables(Object source, Map<String,Object> variables)
          Deserialize changes received from client.
 List<MenuBar.MenuItem> getItems()
          Returns a list with all the MenuItem objects in the menu bar
 MenuBar.MenuItem getMoreMenuItem()
          Get the MenuItem used as the collapse menu item.
 int getSize()
          Returns the size of the menu.
 boolean isAutoOpen()
          Detects whether the menubar is in a mode where top level menus are automatically opened when the mouse cursor is moved over the menu.
 boolean isHtmlContentAllowed()
          Checks whether item captions are interpreted as html or plain text.
 void paintContent(PaintTarget target)
          Paint (serialise) the component for the client.
 void removeItem(MenuBar.MenuItem item)
          Remove first occurrence the specified item from the main menu
 void removeItems()
          Empty the menu bar
 void setAutoOpen(boolean autoOpenTopLevelMenu)
          Using this method menubar can be put into a special mode where top level menus opens without clicking on the menu, but automatically when mouse cursor is moved over the menu.
 void setHtmlContentAllowed(boolean htmlContentAllowed)
          Sets whether html is allowed in the item captions.
 void setMoreMenuItem(MenuBar.MenuItem item)
          Set the item that is used when collapsing the top level menu.
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addListener, addListener, addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, fireEvent, focus, getActionManager, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getErrorMessage, getHeight, getHeightUnits, getIcon, getListeners, getLocale, getParent, getRoot, getState, getStyle, getStyleName, getWidth, getWidthUnits, handleError, hasListeners, isConnectorEnabled, isEnabled, isImmediate, isReadOnly, isVisible, removeListener, removeListener, removeListener, removeListener, removeListener, removeShortcutListener, removeStyleName, requestRepaint, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setHeight, setIcon, setImmediate, setLocale, setParent, setReadOnly, setSizeFull, setSizeUndefined, setStyle, setStyleName, setVisible, setWidth, setWidth, updateState
 
Methods inherited from class com.vaadin.terminal.AbstractClientConnector
addExtension, addMethodInvocationToQueue, createState, getAllChildrenIterable, getConnectorId, getExtensions, getRpcManager, getRpcProxy, getStateType, registerRpc, registerRpc, removeExtension, requestRepaintAll, retrievePendingRpcCalls
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.terminal.VariableOwner
isEnabled, isImmediate
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, getApplication, getCaption, getDebugId, getIcon, getLocale, getParent, getRoot, getState, getStyleName, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setDebugId, setEnabled, setIcon, setReadOnly, setStyleName, setVisible, updateState
 
Methods inherited from interface com.vaadin.terminal.gwt.server.ClientConnector
detach, getExtensions, getStateType, isConnectorEnabled, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setParent
 
Methods inherited from interface com.vaadin.terminal.gwt.client.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.terminal.gwt.server.RpcTarget
getRpcManager
 
Methods inherited from interface com.vaadin.terminal.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setSizeFull, setSizeUndefined, setWidth, setWidth
 

Constructor Detail

MenuBar

public MenuBar()
Constructs an empty, horizontal menu

Method Detail

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException
Paint (serialise) the component for the client.

Specified by:
paintContent in interface Vaadin6Component
Parameters:
target - the target UIDL stream where the component should paint itself to.
Throws:
PaintException - if the paint operation failed.

changeVariables

public void changeVariables(Object source,
                            Map<String,Object> variables)
Deserialize changes received from client.

Specified by:
changeVariables in interface VariableOwner
Parameters:
source - the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.
variables - the Mapping from variable names to new variable values.

addItem

public MenuBar.MenuItem addItem(String caption,
                                MenuBar.Command command)
Add a new item to the menu bar. 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
Throws:
IllegalArgumentException

addItem

public MenuBar.MenuItem addItem(String caption,
                                Resource icon,
                                MenuBar.Command command)
Add a new item to the menu bar. 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:
IllegalArgumentException

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
Throws:
IllegalArgumentException

getItems

public List<MenuBar.MenuItem> getItems()
Returns a list with all the MenuItem objects in the menu bar

Returns:
a list containing the MenuItem objects in the menu bar

removeItem

public void removeItem(MenuBar.MenuItem item)
Remove first occurrence the specified item from the main menu

Parameters:
item - The item to be removed

removeItems

public void removeItems()
Empty the menu bar


getSize

public int getSize()
Returns the size of the menu.

Returns:
The size of the menu

setMoreMenuItem

public void setMoreMenuItem(MenuBar.MenuItem item)
Set the item that is used when collapsing the top level menu. All "overflowing" items will be added below this. The item command will be ignored. If set to null, the default item with a downwards arrow is used. The item command (if specified) is ignored.

Parameters:
item -

getMoreMenuItem

public MenuBar.MenuItem getMoreMenuItem()
Get the MenuItem used as the collapse menu item.

Returns:

setAutoOpen

public void setAutoOpen(boolean autoOpenTopLevelMenu)
Using this method menubar can be put into a special mode where top level menus opens without clicking on the menu, but automatically when mouse cursor is moved over the menu. In this mode the menu also closes itself if the mouse is moved out of the opened menu.

Note, that on touch devices the menu still opens on a click event.

Parameters:
autoOpenTopLevelMenu - true if menus should be opened without click, the default is false

isAutoOpen

public boolean isAutoOpen()
Detects whether the menubar is in a mode where top level menus are automatically opened when the mouse cursor is moved over the menu. Normally root menu opens only by clicking on the menu. Submenus always open automatically.

Returns:
true if the root menus open without click, the default is false

setHtmlContentAllowed

public void setHtmlContentAllowed(boolean htmlContentAllowed)
Sets whether html is allowed in the item captions. If set to true, the captions are passed to the browser as html and the developer is responsible for ensuring no harmful html is used. If set to false, the content is passed to the browser as plain text.

Parameters:
htmlContentAllowed - true if the captions are used as html, false if used as plain text

isHtmlContentAllowed

public boolean isHtmlContentAllowed()
Checks whether item captions are interpreted as html or plain text.

Returns:
true if the captions are used as html, false if used as plain text
See Also:
setHtmlContentAllowed(boolean)


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