4.5.2.1.1. AppMenu
AppMenu
component provides means of customizing the main menu in the main window layout and managing menu items dynamically.
CUBA Studio provides the screen template for main window based on the standard mainWindow
screen provided by the platform. This template extends the AppMainWindow
class and provides direct access to the AppMenu
instance:
public class ExtAppMainWindow extends AppMainWindow {
@Override
public void init(Map<String, Object> params) {
super.init(params);
AppMenu.MenuItem item = mainMenu.createMenuItem("shop", "Shop");
AppMenu.MenuItem subItem = mainMenu.createMenuItem("customer", "Customers", null, menuItem -> {
showNotification("Customers menu item clicked", NotificationType.HUMANIZED);
});
item.addChildItem(subItem);
mainMenu.addMenuItem(item, 0);
}
}
Methods of the AppMenu
interface:
-
addMenuItem()
- adds menu item to the end of root items list or to specified position in the root items list.
-
createMenuItem()
- the factory method that creates new menu item. Does not add item to the menu.id
must be unique for whole menu.
-
createSeparator()
- creates menu separator. -
getMenuItem()/getMenuItemNN()
- returns the item from the menu tree by itsid
. -
getMenuItems()
- returns the list of root menu items. -
hasMenuItems()
- returnstrue
if the menu has items.
Methods of the MenuItem
interface:
-
addChildItem() / removeChildItem()
- adds/removes the menu item to the end or to the specified position of children list. -
getCaption()
- returns the String caption of the menu item. -
getChildren()
- returns the list of child items.
-
setCommand()
- sets item command, or the action to be performed on this menu item click. -
setDescription()
- sets the String description of the menu item, displayed as a popup tip. -
setIcon()
- sets the item’s icon. -
getId()
- returns the menu item id. -
getMenu()
- returns the menu item owner. -
setStylename()
- sets one or more user-defined style names of the component, replacing any previous user-defined styles. Multiple styles can be specified as a space-separated list of style names. The style names must be valid CSS class names. -
hasChildren()
- returnstrue
if the menu item has child items. -
isSeparator()
- returnstrue
if the item is a separator. -
setVisible()
- manages visibility of the menu item.
- API