Search in sources :

Example 6 with SubMenu

use of com.vaadin.flow.component.contextmenu.SubMenu in project docs by vaadin.

the class MenuBarOverflow method addItems.

private void addItems(MenuBar menuBar) {
    menuBar.addItem("View");
    menuBar.addItem("Edit");
    MenuItem share = menuBar.addItem("Share");
    SubMenu shareSubMenu = share.getSubMenu();
    MenuItem onSocialMedia = shareSubMenu.addItem("On social media");
    SubMenu socialMediaSubMenu = onSocialMedia.getSubMenu();
    socialMediaSubMenu.addItem("Facebook");
    socialMediaSubMenu.addItem("Twitter");
    socialMediaSubMenu.addItem("Instagram");
    shareSubMenu.addItem("By email");
    shareSubMenu.addItem("Get Link");
    MenuItem move = menuBar.addItem("Move");
    SubMenu moveSubMenu = move.getSubMenu();
    moveSubMenu.addItem("To folder");
    moveSubMenu.addItem("To trash");
    menuBar.addItem("Duplicate");
}
Also used : MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu)

Example 7 with SubMenu

use of com.vaadin.flow.component.contextmenu.SubMenu in project flow-components by vaadin.

the class ContextMenuView method addContextMenuWithComponentsInSubMenu.

private void addContextMenuWithComponentsInSubMenu() {
    Component target = createTargetComponent();
    ContextMenu contextMenu = new ContextMenu(target);
    Label message = new Label("-");
    contextMenu.addItem(new H5("First menu item"), event -> message.setText("Clicked on the first item"));
    MenuItem subMenuItem = contextMenu.addItem("SubMenu Item");
    SubMenu subMenu = subMenuItem.getSubMenu();
    Checkbox checkbox = new Checkbox("Checkbox");
    subMenu.addItem(checkbox, event -> message.setText("Clicked on checkbox with value: " + checkbox.getValue()));
    subMenu.addItem("TextItem", event -> message.setText("Clicked on text item"));
    // Components can also be added to the submenu overlay
    // without creating menu items with add()
    subMenu.addComponentAtIndex(1, new Hr());
    subMenu.add(new Label("This is not a menu item"));
    addCard("ContextMenu With Components in Sub Menu", target, message);
    target.setId("context-menu-with-submenu-components-target");
    contextMenu.setId("context-menu-with-submenu-components");
    message.setId("context-menu-with-submenu-components-message");
}
Also used : Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu) Hr(com.vaadin.flow.component.html.Hr) Component(com.vaadin.flow.component.Component) H5(com.vaadin.flow.component.html.H5)

Aggregations

SubMenu (com.vaadin.flow.component.contextmenu.SubMenu)7 MenuItem (com.vaadin.flow.component.contextmenu.MenuItem)5 Label (com.vaadin.flow.component.html.Label)3 MenuBar (com.vaadin.flow.component.menubar.MenuBar)3 Component (com.vaadin.flow.component.Component)2 ContextMenu (com.vaadin.flow.component.contextmenu.ContextMenu)2 Test (org.junit.jupiter.api.Test)2 ComponentEvent (com.vaadin.flow.component.ComponentEvent)1 ComponentEventListener (com.vaadin.flow.component.ComponentEventListener)1 Text (com.vaadin.flow.component.Text)1 Unit (com.vaadin.flow.component.Unit)1 Button (com.vaadin.flow.component.button.Button)1 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1 H5 (com.vaadin.flow.component.html.H5)1 Hr (com.vaadin.flow.component.html.Hr)1 Notification (com.vaadin.flow.component.notification.Notification)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 VaadinService (com.vaadin.flow.server.VaadinService)1 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)1