Search in sources :

Example 1 with MenuItem

use of com.vaadin.flow.component.contextmenu.MenuItem 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 MenuItem

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

the class ContextMenuView method addBasicContextMenu.

private void addBasicContextMenu() {
    ContextMenu contextMenu = new ContextMenu();
    Component target = createTargetComponent();
    contextMenu.setTarget(target);
    Label message = new Label("-");
    contextMenu.addItem("First menu item", e -> message.setText("Clicked on the first item"));
    contextMenu.addItem("Second menu item", e -> message.setText("Clicked on the second item"));
    // The created MenuItem component can be saved for later use
    MenuItem item = contextMenu.addItem("Disabled menu item", e -> message.setText("This cannot happen"));
    item.setEnabled(false);
    addCard("Basic ContextMenu", target, message);
    target.setId("basic-context-menu-target");
    contextMenu.setId("basic-context-menu");
}
Also used : Label(com.vaadin.flow.component.html.Label) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) Component(com.vaadin.flow.component.Component)

Example 3 with MenuItem

use of com.vaadin.flow.component.contextmenu.MenuItem in project furms by unity-idm.

the class NotificationBarComponent method loadData.

private void loadData() {
    contextMenu.removeAll();
    Set<NotificationBarElement> allCurrentUserNotification = notificationService.findAllCurrentUserNotification();
    Iterator<NotificationBarElement> iterator = allCurrentUserNotification.iterator();
    while (iterator.hasNext()) {
        NotificationBarElement barElement = iterator.next();
        MenuItem menuItem = contextMenu.addItem(createLabel(barElement.text), y -> {
            roleTranslator.refreshAuthzRolesAndGetRolesToUserViewContexts().get(barElement.viewMode).stream().filter(context -> barElement.resourceId.filter(resourceId -> resourceId.equals(context.id)).isPresent()).findAny().ifPresent(FurmsViewUserContext::setAsCurrent);
            barElement.redirect.ifPresent(redirect -> barElement.parameter.ifPresentOrElse(parameter -> UI.getCurrent().navigate(redirect, parameter), () -> UI.getCurrent().navigate(redirect)));
        });
        menuItem.setId("context-menu-item-size");
        if (iterator.hasNext())
            contextMenu.add(new Hr());
    }
    setNumber(allCurrentUserNotification.size());
}
Also used : Component(com.vaadin.flow.component.Component) CssImport(com.vaadin.flow.component.dependency.CssImport) Registration(com.vaadin.flow.shared.Registration) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) VaadinListener(io.imunity.furms.ui.VaadinListener) VaadinBroadcaster(io.imunity.furms.ui.VaadinBroadcaster) ContextMenu(com.vaadin.flow.component.contextmenu.ContextMenu) UINotificationService(io.imunity.furms.ui.notifications.UINotificationService) FurmsViewUserContext(io.imunity.furms.ui.user_context.FurmsViewUserContext) UserAlarmListChangedEvent(io.imunity.furms.domain.notification.UserAlarmListChangedEvent) UI(com.vaadin.flow.component.UI) AttachEvent(com.vaadin.flow.component.AttachEvent) UserInvitationsListChangedEvent(io.imunity.furms.domain.notification.UserInvitationsListChangedEvent) RoleTranslator(io.imunity.furms.ui.user_context.RoleTranslator) NotificationBarElement(io.imunity.furms.ui.notifications.NotificationBarElement) FurmsEvent(io.imunity.furms.domain.FurmsEvent) Iterator(java.util.Iterator) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) BELL(com.vaadin.flow.component.icon.VaadinIcon.BELL) Set(java.util.Set) Hr(com.vaadin.flow.component.html.Hr) FURMSUser(io.imunity.furms.domain.users.FURMSUser) FenixUserId(io.imunity.furms.domain.users.FenixUserId) Button(com.vaadin.flow.component.button.Button) UserPoliciesListChangedEvent(io.imunity.furms.domain.notification.UserPoliciesListChangedEvent) DetachEvent(com.vaadin.flow.component.DetachEvent) UserApplicationsListChangedEvent(io.imunity.furms.domain.notification.UserApplicationsListChangedEvent) JsModule(com.vaadin.flow.component.dependency.JsModule) Span(com.vaadin.flow.component.html.Span) FurmsViewUserContext(io.imunity.furms.ui.user_context.FurmsViewUserContext) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) Hr(com.vaadin.flow.component.html.Hr) NotificationBarElement(io.imunity.furms.ui.notifications.NotificationBarElement)

Example 4 with MenuItem

use of com.vaadin.flow.component.contextmenu.MenuItem in project furms by unity-idm.

the class ProjectAllocationComponent method createContextMenu.

private Component createContextMenu(ProjectAllocationGridModel model) {
    GridActionMenu contextMenu = new GridActionMenu();
    if (hasTerminalStatus(model)) {
        contextMenu.addItem(new MenuButton(getTranslation("view.community-admin.project-allocation.menu.edit"), EDIT), event -> UI.getCurrent().navigate(ProjectAllocationFormView.class, model.id));
    }
    Dialog confirmDialog = createConfirmDialog(model.id, model.name);
    final MenuItem deleteItem = contextMenu.addItem(new MenuButton(getTranslation("view.community-admin.project-allocation.menu.delete"), TRASH), event -> confirmDialog.open());
    deleteItem.setEnabled(projectInTerminalState && !projectExpired);
    getRefreshMenuItem(contextMenu);
    getContent().add(contextMenu);
    return contextMenu.getTarget();
}
Also used : GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) Dialog(com.vaadin.flow.component.dialog.Dialog) MenuButton(io.imunity.furms.ui.components.MenuButton) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem)

Example 5 with MenuItem

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

the class ApplicationHeaderTest method testAddThemeVariantToggles_MultipleItems.

@Test
void testAddThemeVariantToggles_MultipleItems() {
    ApplicationHeader header = new ApplicationHeader(new TestApplicationInfo(), Sequence.empty());
    header.init();
    MenuBar rightComponent = (MenuBar) ((HorizontalLayout) header.getContent().getComponentAt(1)).getComponentAt(0);
    MenuItem helpMenuItem = rightComponent.getItems().get(0);
    header.addThemeVariantToggles(helpMenuItem, LINKKI_CARD, LINKKI_COMPACT);
    assertThat(helpMenuItem.getSubMenu().getItems()).anyMatch(mi -> mi.getText().equals("Themes"));
    assertThat(helpMenuItem.getSubMenu().getItems().get(1).getText()).isEqualTo(NlsText.getString("ApplicationHeader.Theme"));
    assertThat(helpMenuItem.getSubMenu().getItems().get(1).getSubMenu().getItems().stream().map(MenuItem::getText)).contains("Card Theme", "Compact Theme");
}
Also used : MenuBar(com.vaadin.flow.component.menubar.MenuBar) MenuItem(com.vaadin.flow.component.contextmenu.MenuItem) Test(org.junit.jupiter.api.Test)

Aggregations

MenuItem (com.vaadin.flow.component.contextmenu.MenuItem)27 MenuBar (com.vaadin.flow.component.menubar.MenuBar)9 Test (org.junit.jupiter.api.Test)8 ContextMenu (com.vaadin.flow.component.contextmenu.ContextMenu)6 Label (com.vaadin.flow.component.html.Label)6 Component (com.vaadin.flow.component.Component)5 SubMenu (com.vaadin.flow.component.contextmenu.SubMenu)5 Text (com.vaadin.flow.component.Text)2 Button (com.vaadin.flow.component.button.Button)2 Hr (com.vaadin.flow.component.html.Hr)2 Span (com.vaadin.flow.component.html.Span)2 Icon (com.vaadin.flow.component.icon.Icon)2 VaadinIcon (com.vaadin.flow.component.icon.VaadinIcon)2 Registration (com.vaadin.flow.shared.Registration)2 Test (org.junit.Test)2 AttachEvent (com.vaadin.flow.component.AttachEvent)1 ComponentEvent (com.vaadin.flow.component.ComponentEvent)1 ComponentEventListener (com.vaadin.flow.component.ComponentEventListener)1 DetachEvent (com.vaadin.flow.component.DetachEvent)1 UI (com.vaadin.flow.component.UI)1