Java Code Examples for com.vaadin.ui.MenuBar.MenuItem#setStyleName()

The following examples show how to use com.vaadin.ui.MenuBar.MenuItem#setStyleName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebLayoutAnalyzerContextMenuProvider.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void initContextMenu(Window window, Component contextMenuTarget) {
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
    if (clientConfig.getLayoutAnalyzerEnabled()) {
        ContextMenu contextMenu = new ContextMenu(contextMenuTarget.unwrap(AbstractComponent.class), true);
        MenuItem menuItem = contextMenu.addItem(messages.getMainMessage("actions.analyzeLayout"), c -> {
            LayoutAnalyzer analyzer = new LayoutAnalyzer();
            List<LayoutTip> tipsList = analyzer.analyze(window);

            if (tipsList.isEmpty()) {
                window.showNotification("No layout problems found", NotificationType.HUMANIZED);
            } else {
                window.openWindow("layoutAnalyzer", OpenType.DIALOG,
                        ParamsMap.of("tipsList", tipsList)
                );
            }
        });
        menuItem.setStyleName("c-cm-item");
    }
}
 
Example 2
Source File: DashboardMenu.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
private Component buildUserMenu(final UiProperties uiProperties) {
    final MenuBar settings = new MenuBar();
    settings.addStyleName("user-menu");
    settings.setHtmlContentAllowed(true);

    final MenuItem settingsItem = settings.addItem("", getImage(uiProperties.isGravatar()), null);

    final String formattedTenant = UserDetailsFormatter.formatCurrentTenant();
    if (!StringUtils.isEmpty(formattedTenant)) {
        settingsItem.setText(formattedTenant);
        UserDetailsFormatter.getCurrentTenant().ifPresent(tenant -> settingsItem.setDescription(i18n
                .getMessage("menu.user.description", tenant, UserDetailsFormatter.getCurrentUser().getUsername())));
    } else {
        settingsItem.setText("...");
    }

    settingsItem.setStyleName("user-menuitem");

    final String logoutUrl = generateLogoutUrl();

    settingsItem.addItem(i18n.getMessage("label.sign.out"),
            selectedItem -> Page.getCurrent().setLocation(logoutUrl));
    return settings;
}
 
Example 3
Source File: ContextMenuUI.java    From context-menu with Apache License 2.0 4 votes vote down vote up
private void fillMenu(ContextMenu menu) {
    final MenuItem item = menu.addItem("Checkable \u00d6",
            e -> Notification.show("checked: " + e.isChecked())
    );
    item.setCheckable(true);
    item.setChecked(true);

    MenuItem item2 = menu.addItem("Disabled",new ClassResource("/images/tiger.jpg"),
            e -> Notification.show("disabled")
    );
    item2.setDescription("Disabled item");
    item2.setEnabled(false);

    MenuItem item3 = menu.addItem("Invisible",
            e -> Notification.show("invisible")
    );
    item3.setVisible(false);

    menu.addSeparator();

    //The path is /resources/images/kitten.jpg
    ClassResource ico = new ClassResource("/images/kitten.jpg");
    MenuItem item4 = menu.addItem("Icon + Description + <b>HTML</b>",ico,
            e -> Notification.show("icon")
    );
    item4.setDescription("Test tooltip");
    but3.addClickListener(e -> item4.setDescription(""));
    MenuItem item5 = menu.addItem("Custom stylename",
            e -> Notification.show("stylename")
    );
    //The path is /webapp/VAADIN/themes/contextmenu/images
    ThemeResource resource = new ThemeResource("images/cat.jpg");
    item5.setIcon(resource);

    item5.setStyleName("teststyle");

    MenuItem item6 = menu.addItem("Submenu");
    item6.addItem("Subitem", VaadinIcons.OPTION, e -> Notification.show("SubItem"));
    item6.addSeparator();
    item6.addItem("Subitem",new ThemeResource("images/cat2.jpg"), e -> Notification.show("SubItem"))
            .setDescription("Test");
    MenuItem openWindowNotification = item6.addItem(
            "Open Window + Notification",
            e -> Notification.show("Open Vaadin.com"));
    new BrowserWindowOpener("https://vaadin.com").extend(openWindowNotification);

    MenuItem openWindowDummy = item6.addItem("Open Google");
    new BrowserWindowOpener("https://google.com").extend(openWindowDummy);

    new BrowserWindowOpener("https://yahoo.com")
            .extend(item6.addItem("SubMenu2").addItem("Yahoo!"));
}