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");
}
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");
}
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());
}
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();
}
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");
}
Aggregations