Search in sources :

Example 1 with SubMenu

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

the class ContextMenuView method addContextMenuWithSubMenus.

private void addContextMenuWithSubMenus() {
    ContextMenu contextMenu = new ContextMenu();
    Component target = createTargetComponent();
    contextMenu.setTarget(target);
    Label message = new Label("-");
    contextMenu.addItem("First menu item", event -> message.setText("Clicked on the first item"));
    MenuItem parent = contextMenu.addItem("Parent item");
    SubMenu subMenu = parent.getSubMenu();
    subMenu.addItem("Second menu item", event -> message.setText("Clicked on the second item"));
    subMenu = subMenu.addItem("Parent item").getSubMenu();
    subMenu.addItem("Third menu item", event -> message.setText("Clicked on the third item"));
    addCard("Hierarchical Menu", target, message);
    target.setId("hierarchical-menu-target");
    message.setId("hierarchical-menu-message");
}
Also used : 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) Component(com.vaadin.flow.component.Component)

Example 2 with SubMenu

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

the class ApplicationMenuItemDefinitionTest method testCreateItem_SubMenu_SubMenu.

@Test
void testCreateItem_SubMenu_SubMenu() {
    ApplicationMenuItemDefinition itemDefinition = new ApplicationMenuItemDefinition("name", "id", Arrays.asList(new ApplicationMenuItemDefinition("sub", "sub-id", Handler.NOP_HANDLER)));
    MenuBar menuBar = new MenuBar();
    SubMenu subMenu = menuBar.addItem("item").getSubMenu();
    itemDefinition.createItem(subMenu);
    assertThat(subMenu.getItems()).hasSize(1);
    assertThat(subMenu.getItems().get(0).getText()).isEqualTo("name");
    assertThat(subMenu.getItems().get(0).getSubMenu().getItems()).hasSize(1);
    assertThat(subMenu.getItems().get(0).getSubMenu().getItems().get(0).getText()).isEqualTo("sub");
}
Also used : MenuBar(com.vaadin.flow.component.menubar.MenuBar) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu) Test(org.junit.jupiter.api.Test)

Example 3 with SubMenu

use of com.vaadin.flow.component.contextmenu.SubMenu in project ArchCNL by Mari-Wie.

the class MainView method createHeader.

private HorizontalLayout createHeader() {
    final HorizontalLayout headerBox = new HorizontalLayout();
    final Label title = new Label("ArchCNL");
    title.getStyle().set("color", "#76d0f1");
    title.getStyle().set("font-size", "x-large");
    title.getStyle().set("font-weight", "bold");
    final MenuBar menuBar = new MenuBar();
    final MenuItem project = menuBar.addItem("Project");
    final MenuItem edit = menuBar.addItem("Edit");
    final MenuItem rules = menuBar.addItem("Rules");
    menuBar.addItem("View", e -> fireEvent(new ViewOptionRequestedEvent(this, true)));
    menuBar.addItem("Help", e -> fireEvent(new HelpOptionRequestedEvent(this, true)));
    final SubMenu projectSubMenu = project.getSubMenu();
    projectSubMenu.addItem("New Project", e -> fireEvent(new ProjectOptionRequestedEvent(this, true, ProjectOption.NEW)));
    openProjectMenuItem = projectSubMenu.addItem("Open Project", e -> fireEvent(new ProjectOptionRequestedEvent(this, true, ProjectOption.OPEN)));
    saveProjectMenuItem = projectSubMenu.addItem("Save", e -> fireEvent(new ProjectOptionRequestedEvent(this, true, ProjectOption.SAVE)));
    saveProjectMenuItem.setEnabled(false);
    projectSubMenu.addItem("Save As", e -> fireEvent(new ProjectOptionRequestedEvent(this, true, ProjectOption.SAVE_AS)));
    final SubMenu editSubMenu = edit.getSubMenu();
    editSubMenu.addItem("Undo", e -> fireEvent(new EditOptionRequestedEvent(this, true, EditOption.UNDO)));
    editSubMenu.addItem("Redo", e -> fireEvent(new EditOptionRequestedEvent(this, true, EditOption.REDO)));
    final SubMenu rulesSubMenu = rules.getSubMenu();
    rulesSubMenu.addItem("Import from File", e -> fireEvent(new RulesOptionRequestedEvent(this, true, RulesOption.IMPORT_FROM_FILE)));
    rulesSubMenu.addItem("Import Rule Presets", e -> fireEvent(new RulesOptionRequestedEvent(this, true, RulesOption.IMPORT_RULE_PRESETS)));
    headerBox.add(title, menuBar);
    headerBox.setDefaultVerticalComponentAlignment(Alignment.CENTER);
    headerBox.setWidthFull();
    return headerBox;
}
Also used : ComponentEventListener(com.vaadin.flow.component.ComponentEventListener) MenuBar(com.vaadin.flow.component.menubar.MenuBar) RulesOptionRequestedEvent(org.archcnl.ui.events.RulesOptionRequestedEvent) Registration(com.vaadin.flow.shared.Registration) URISyntaxException(java.net.URISyntaxException) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Label(com.vaadin.flow.component.html.Label) ProjectOption(org.archcnl.ui.events.ProjectOptionRequestedEvent.ProjectOption) FooterOption(org.archcnl.ui.events.FooterOptionRequestedEvent.FooterOption) RulesOption(org.archcnl.ui.events.RulesOptionRequestedEvent.RulesOption) EditOptionRequestedEvent(org.archcnl.ui.events.EditOptionRequestedEvent) Unit(com.vaadin.flow.component.Unit) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) URI(java.net.URI) NoSuchElementException(java.util.NoSuchElementException) Notification(com.vaadin.flow.component.notification.Notification) Text(com.vaadin.flow.component.Text) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu) ProjectOptionRequestedEvent(org.archcnl.ui.events.ProjectOptionRequestedEvent) ViewOptionRequestedEvent(org.archcnl.ui.events.ViewOptionRequestedEvent) ComponentEvent(com.vaadin.flow.component.ComponentEvent) EditOption(org.archcnl.ui.events.EditOptionRequestedEvent.EditOption) HelpOptionRequestedEvent(org.archcnl.ui.events.HelpOptionRequestedEvent) Button(com.vaadin.flow.component.button.Button) FooterOptionRequestedEvent(org.archcnl.ui.events.FooterOptionRequestedEvent) VaadinService(com.vaadin.flow.server.VaadinService) ProjectOptionRequestedEvent(org.archcnl.ui.events.ProjectOptionRequestedEvent) Label(com.vaadin.flow.component.html.Label) HelpOptionRequestedEvent(org.archcnl.ui.events.HelpOptionRequestedEvent) MenuBar(com.vaadin.flow.component.menubar.MenuBar) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu) ViewOptionRequestedEvent(org.archcnl.ui.events.ViewOptionRequestedEvent) EditOptionRequestedEvent(org.archcnl.ui.events.EditOptionRequestedEvent) RulesOptionRequestedEvent(org.archcnl.ui.events.RulesOptionRequestedEvent) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 4 with SubMenu

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

the class MenuBarOpenOnHover 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 5 with SubMenu

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

the class ApplicationMenuItemDefinitionTest method testCreateItem_SubMenu_NoSubMenu.

@Test
void testCreateItem_SubMenu_NoSubMenu() {
    ApplicationMenuItemDefinition itemDefinition = new ApplicationMenuItemDefinition("name", "id", Handler.NOP_HANDLER);
    MenuBar menuBar = new MenuBar();
    SubMenu subMenu = menuBar.addItem("item").getSubMenu();
    itemDefinition.createItem(subMenu);
    assertThat(subMenu.getItems()).hasSize(1);
    assertThat(subMenu.getItems().get(0).getText()).isEqualTo("name");
    assertThat(subMenu.getItems().get(0).getId()).hasValue("id");
}
Also used : MenuBar(com.vaadin.flow.component.menubar.MenuBar) SubMenu(com.vaadin.flow.component.contextmenu.SubMenu) Test(org.junit.jupiter.api.Test)

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