Class FMenuBar.MenuItem

java.lang.Object
com.vaadin.featurepack.ui.FMenuBar.MenuItem
All Implemented Interfaces:
Serializable
Enclosing class:
FMenuBar

public class FMenuBar.MenuItem extends Object implements Serializable
See Also:
  • Constructor Details

    • MenuItem

      public MenuItem(String caption, Resource icon, FMenuBar.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:
      caption - The text associated with the command
      command - 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

      public FMenuBar.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.
    • addSeparatorBefore

      public FMenuBar.MenuItem addSeparatorBefore(FMenuBar.MenuItem itemToAddBefore)
    • addItem

      public FMenuBar.MenuItem addItem(String caption, FMenuBar.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 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 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 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 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 FMenuBar.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 FMenuBar.MenuItem 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

      public List<FMenuBar.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(FMenuBar.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(FMenuBar.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(FMenuBar.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.
      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
    • 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
    • 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
    • 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".