com.vaadin.ui.MenuBar.MenuItem Java Examples

The following examples show how to use com.vaadin.ui.MenuBar.MenuItem. 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: AbstractMenuItemFactoryImpl.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Inits the application menu bar.
 *
 * @param menuBar
 *            the menu bar
 */
protected final void initApplicationMenuBar(final MenuBar menuBar) {
	menuBar.removeItems();
	menuBar.setWidth(MENU_BAR_WIDTH);
	menuBar.setStyleName(HEADER_STYLE_NAME);
	final MenuItem mainViewItem = menuBar.addItem(APPLICATION, VaadinIcons.SERVER, null);

	mainViewItem.addItem(START_TEXT, VaadinIcons.STAR, COMMAND_MAINVIEW_OVERVIEW);

	final MenuItem mainItem = mainViewItem.addItem(MAIN, VaadinIcons.STAR, null);

	mainItem.addItem(PAGE_VISIT_HISTORY_TEXT, VaadinIcons.LINE_CHART, COMMAND_MAINVIEW_PAGEVISITHISTORY);


	if (UserContextUtil.allowRoleInSecurityContext(ROLE_ADMIN) || UserContextUtil.allowRoleInSecurityContext(ROLE_USER)) {
		mainViewItem.addItem(USERHOME, VaadinIcons.USER,COMMAND_USERHOME);
		createAdminMenu(mainViewItem);
		mainViewItem.addItem(LOGOUT, VaadinIcons.SIGN_OUT, COMMAND_LOGOUT);
	} else {
		mainViewItem.addItem(LOGIN, VaadinIcons.SIGN_IN, COMMAND_LOGIN);
		mainViewItem.addItem(REGISTER, VaadinIcons.FILE_ADD, COMMAND_REGISTER);
	}

}
 
Example #3
Source File: ContextMenu.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * @param parentComponent
 *            The component to whose lifecycle the context menu is tied to.
 * @param setAsMenuForParentComponent
 *            Determines if this menu will be shown for the parent
 *            component.
 */
public ContextMenu(AbstractComponent parentComponent,
        boolean setAsMenuForParentComponent) {
    extend(parentComponent);

    registerRpc(new ContextMenuServerRpc() {
        @Override
        public void itemClicked(int itemId) {
            MenuItem clickedItem = itemById.get(itemId);
            if (clickedItem != null) {
                if (clickedItem.isCheckable())
                    clickedItem.setChecked(!clickedItem.isChecked());

                if (clickedItem.getCommand() != null)
                    clickedItem.getCommand().menuSelected(clickedItem);
            }
        }
    });

    if (setAsMenuForParentComponent) {
        setAsContextMenuOf(parentComponent);
    }
}
 
Example #4
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 #5
Source File: ContextMenu.java    From context-menu with Apache License 2.0 6 votes vote down vote up
/**
 * @param parentComponent
 *            The component to whose lifecycle the context menu is tied to.
 * @param setAsMenuForParentComponent
 *            Determines if this menu will be shown for the parent
 *            component.
 */
public ContextMenu(AbstractComponent parentComponent,
        boolean setAsMenuForParentComponent) {
    extend(parentComponent);

    registerRpc(new ContextMenuServerRpc() {
        @Override
        public void itemClicked(int itemId) {
            MenuItem clickedItem = itemById.get(itemId);
            if (clickedItem != null) {
                if (clickedItem.isCheckable())
                    clickedItem.setChecked(!clickedItem.isChecked());

                if (clickedItem.getCommand() != null)
                    clickedItem.getCommand().menuSelected(clickedItem);
            }
        }
    });

    if (setAsMenuForParentComponent) {
        setAsContextMenuOf(parentComponent);
    }
}
 
Example #6
Source File: WebAbstractDataGrid.java    From cuba with Apache License 2.0 5 votes vote down vote up
public ActionMenuItemWrapper(MenuItem menuItem, boolean showIconsForPopupMenuActions) {
    this.menuItem = menuItem;
    this.showIconsForPopupMenuActions = showIconsForPopupMenuActions;

    this.menuItem.setCommand((MenuBar.Command) selectedItem -> {
        if (action != null) {
            performAction(action);
        }
    });
}
 
Example #7
Source File: ContextMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
private List<ContextMenuItemState> convertItemsToState(List<MenuItem> items,
                                                       Map<Integer, MenuItem> itemRegistry) {
    if (items == null || items.size() == 0) {
        return null;
    }

    List<ContextMenuItemState> stateItems = new ArrayList<>(items.size());

    for (MenuItem item : items) {
        ContextMenuItemState menuItemState = new ContextMenuItemState();

        if (!item.isVisible()) {
            continue;
        }

        menuItemState.id = item.getId();
        menuItemState.text = item.getText();
        menuItemState.checkable = item.isCheckable();
        menuItemState.command = item.getCommand() != null;
        menuItemState.checked = item.isChecked();
        menuItemState.description = item.getDescription();
        menuItemState.descriptionContentMode = item
                .getDescriptionContentMode();
        menuItemState.enabled = item.isEnabled();
        menuItemState.separator = item.isSeparator();
        menuItemState.icon = ResourceReference.create(item.getIcon(), this,
                "");
        menuItemState.styleName = item.getStyleName();

        menuItemState.childItems = convertItemsToState(item.getChildren(),
                itemRegistry);

        stateItems.add(menuItemState);
        itemRegistry.put(item.getId(), item);
    }

    return stateItems;
}
 
Example #8
Source File: DocumentMenuItemFactoryImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public void createDocumentsMenuBar(final MenuBar menuBar) {
	initApplicationMenuBar(menuBar);

	applicationMenuItemFactory.addRankingMenu(menuBar);
	final MenuItem documentsItem = menuBar.addItem(DOCUMENTS, VaadinIcons.FILE, null);
	documentsItem.addItem("List all",VaadinIcons.GROUP, COMMAND_DOCUMENTS);
	documentsItem.addItem("Search Documents",VaadinIcons.GROUP, COMMAND_SEARCH_DOCUMENT);

}
 
Example #9
Source File: PartyRankingMenuItemFactoryImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public void createPartyRankingTopics(final MenuItem partynMenuItem) {

	partynMenuItem.addItem(OVERVIEW_TEXT, VaadinIcons.GROUP,
			COMMAND_OVERVIEW);

	final MenuItem listByTopic = partynMenuItem.addItem(RANKING_LIST_BY_TOPIC_TEXT, VaadinIcons.GROUP, null);

	final MenuItem listItem = listByTopic.addItem(TOTAL_MEMBERS,VaadinIcons.GROUP,
			COMMAND_DATAGRID);
	listItem.setDescription(PARTY_BY_TOTAL_MEMBERS_BASED_ON_ROLES_IN_DEPARTMENTS_COMMITTEES_AND_PARLIAMENT);

	final MenuItem chartByTopic = partynMenuItem.addItem(CHART_BY_TOPIC_TEXT, VaadinIcons.GROUP, null);


	chartByTopic.addItem(CURRENT_PARTIES_ACTIVE_IN_MINISTRIES_HEAD_COUNT_TEXT,VaadinIcons.GROUP,
			COMMAND_CHARTS_CURRENT_GOVERNMENT_PARTIES);

	chartByTopic.addItem(CURRENT_PARTIES_ACTIVE_IN_COMMITTEES_HEAD_COUNT,VaadinIcons.GROUP,
			COMMAND_CHARTS_CURRENT_COMMITTEES);

	chartByTopic.addItem(CURRENT_PARTIES_ACTIVE_IN_PARLIAMENT_HEAD_COUNT,VaadinIcons.GROUP,
			COMMAND_CHARTS_CURRENT_PARTIES);
	chartByTopic.addItem(ALL_PARTIES_TOTAL_DAYS_SERVED_IN_PARLIAMENT,VaadinIcons.GROUP,
			COMMAND_CHARTS_ALL_PARTIES);

	partynMenuItem.addItem(PAGE_VISIT_HISTORY_TEXT, VaadinIcons.GROUP,
			COMMAND_PAGEVISITHISTORY);
}
 
Example #10
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public MenuItem addSeparatorBefore(MenuItem itemToAddBefore) {
    return rootItem.addSeparatorBefore(itemToAddBefore);
}
 
Example #11
Source File: CommitteeRankingMenuItemFactoryImpl.java    From cia with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the committee ranking topics.
 *
 * @param committeeMenuItem
 *            the committee menu item
 */
@Override
public void createCommitteeRankingTopics(final MenuItem committeeMenuItem) {
	committeeMenuItem.addItem(OVERVIEW_TEXT, VaadinIcons.GROUP, COMMAND_OVERVIEW);

	final MenuItem listByTopic = committeeMenuItem.addItem(RANKING_LIST_BY_TOPIC_TEXT, VaadinIcons.GROUP, null);

	final MenuItem listItem = listByTopic.addItem(POLITICAL_WORK_SUMMARY_TEXT,VaadinIcons.GROUP, COMMAND_DATAGRID);
	listItem.setDescription(CURRENT_AND_PAST_MEMBER_AND_SUMMARY_OF_POLTICIAL_DAYS);

	final MenuItem chartByTopic = committeeMenuItem.addItem(CHART_BY_TOPIC_TEXT, VaadinIcons.GROUP, null);


	chartByTopic.addItem(CURRENT_COMMITTEES_CURRENT_MEMBERS_TEXT,VaadinIcons.GROUP, COMMAND_CURRENT_COMMITTEES_BY_HEADCOUNT);
	chartByTopic.addItem(CURRENT_PARTIES_ACTIVE_IN_COMMITTEES_CURRENT_ASSIGNMENTS,VaadinIcons.GROUP, COMMAND_COMMITTEES_BY_PARTY);
	chartByTopic.addItem(CURRENT_PARTIES_ACTIVE_IN_COMMITTEES_TOTAL_DAYS_SERVED_IN_COMMITTEES,VaadinIcons.GROUP, COMMAND_CURRENT_COMMITTEES_BY_PARTY_DAYS_SERVED);

	chartByTopic.addItem(ALL_COMMITTEES_TOTAL_MEMBERS,VaadinIcons.GROUP, COMMAND_ALL_COMMITTEES_BY_HEADCOUNT);

	committeeMenuItem.addItem(PAGE_VISIT_HISTORY_TEXT, VaadinIcons.GROUP, COMMAND_PAGEVISIT_HISTORY);

}
 
Example #12
Source File: UserHomeMenuItemFactoryImpl.java    From cia with Apache License 2.0 4 votes vote down vote up
@Override
public void createUserHomeMenuBar(final MenuBar menuBar, final String pageId) {
	initApplicationMenuBar(menuBar);

	applicationMenuItemFactory.addRankingMenu(menuBar);
	final MenuItem accountItem = menuBar.addItem("Useraccount", VaadinIcons.USER,null);


	accountItem.addItem(OVERVIEW_TEXT, VaadinIcons.USER,
			new PageModeMenuCommand(UserViews.USERHOME_VIEW_NAME, PageMode.OVERVIEW, pageId));

	accountItem.addItem(SECURITY_SETTING_TEXT, VaadinIcons.USER,
			new PageModeMenuCommand(UserViews.USERHOME_VIEW_NAME, UserHomePageMode.SECURITY_SETTINGS.toString(), pageId));

	accountItem.addItem(USER_VISITS, VaadinIcons.USER,
			new PageModeMenuCommand(UserViews.USERHOME_VIEW_NAME, UserHomePageMode.USER_VISITS.toString(), pageId));

	accountItem.addItem(USER_EVENTS, VaadinIcons.USER,
			new PageModeMenuCommand(UserViews.USERHOME_VIEW_NAME, UserHomePageMode.USER_EVENTS.toString(), pageId));


}
 
Example #13
Source File: PoliticianRankingMenuItemFactoryImpl.java    From cia with Apache License 2.0 4 votes vote down vote up
@Override
public void createPoliticianRankingTopics(final MenuItem politicianMenuItem) {
	politicianMenuItem.addItem(OVERVIEW_TEXT, VaadinIcons.BUG, COMMAND_OVERVIEW);

	final MenuItem listByTopic = politicianMenuItem.addItem(RANKING_LIST_BY_TOPIC_TEXT, VaadinIcons.BUG, null);

	final MenuItem listItem = listByTopic.addItem(POLITICAL_EXPERIENCE_SUMMARY, VaadinIcons.BUG, COMMAND_DATAGRID);
	listItem.setDescription(CURRENT_AND_PAST_ASSIGNMENTS_AND_SUMMARY_EXPERIENCE_IN_DAYS);

	final MenuItem chartByTopic = politicianMenuItem.addItem(CHART_BY_TOPIC_TEXT, VaadinIcons.BUG, null);

	chartByTopic.addItem(ALL_PARTIES, VaadinIcons.GROUP, COMMAND_ALL_PARTIES);

	chartByTopic.addItem(CURRENT_PARTIES, VaadinIcons.GROUP, COMMAND_CURRENT_PARTIES);

	politicianMenuItem.addItem(PAGE_VISIT_HISTORY_TEXT, VaadinIcons.BUG, COMMAND_PAGEVISITHISTORY);

}
 
Example #14
Source File: PageModeMenuCommand.java    From cia with Apache License 2.0 4 votes vote down vote up
@Override
public void menuSelected(final MenuItem selectedItem) {
	UI.getCurrent().getNavigator().navigateTo(page + PAGE_SEPARATOR + pageReference);
}
 
Example #15
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
private List<ContextMenuItemState> convertItemsToState(List<MenuItem> items,
        Map<Integer, MenuItem> itemRegistry) {
    if (items == null || items.size() == 0) {
        return null;
    }

    List<ContextMenuItemState> stateItems = new ArrayList<>(items.size());

    for (MenuItem item : items) {
        ContextMenuItemState menuItemState = new ContextMenuItemState();

        if (!item.isVisible()) {
            continue;
        }

        menuItemState.id = item.getId();
        menuItemState.text = item.getText();
        menuItemState.checkable = item.isCheckable();
        menuItemState.command = item.getCommand() != null;
        menuItemState.checked = item.isChecked();
        menuItemState.description = item.getDescription();
        menuItemState.descriptionContentMode = item
                .getDescriptionContentMode();
        menuItemState.enabled = item.isEnabled();
        menuItemState.separator = item.isSeparator();
        String key= item.getIcon()!= null ?
                String.valueOf(item.getIcon().hashCode())
                : "icon";
        ResourceReference resourceReference = ResourceReference.create(item.getIcon(), this, key);
        if (item.getIcon()!=null && (item.getIcon() instanceof ConnectorResource)) {
            super.getState().resources.put(key,resourceReference);
        }
        menuItemState.icon = resourceReference;
        menuItemState.styleName = item.getStyleName();

        menuItemState.childItems = convertItemsToState(item.getChildren(),
                itemRegistry);

        stateItems.add(menuItemState);
        itemRegistry.put(item.getId(), item);
    }

    return stateItems;
}
 
Example #16
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public MenuItem addSeparator() {
    return rootItem.addSeparator();
}
 
Example #17
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!"));
}
 
Example #18
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public MenuItem addItem(String caption) {
    return rootItem.addItem(caption);
}
 
Example #19
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public MenuItem addItem(String caption, Command command) {
    return rootItem.addItem(caption, command);
}
 
Example #20
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public MenuItem addItem(String caption, Resource icon, Command command) {
    return rootItem.addItem(caption, icon, command);
}
 
Example #21
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public MenuItem addItemBefore(String caption, Resource icon,
                              Command command, MenuItem itemToAddBefore) {
    return rootItem.addItemBefore(caption, icon, command, itemToAddBefore);
}
 
Example #22
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public List<MenuItem> getItems() {
    return rootItem.getChildren();
}
 
Example #23
Source File: ContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public void removeItem(MenuItem item) {
    rootItem.removeChild(item);
}
 
Example #24
Source File: ContextMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public MenuItem addSeparator() {
    return rootItem.addSeparator();
}
 
Example #25
Source File: ContextMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void removeItem(MenuItem item) {
    rootItem.removeChild(item);
}
 
Example #26
Source File: ContextMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public List<MenuItem> getItems() {
    return rootItem.getChildren();
}
 
Example #27
Source File: ContextMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public MenuItem addItemBefore(String caption, Resource icon,
                              Command command, MenuItem itemToAddBefore) {
    return rootItem.addItemBefore(caption, icon, command, itemToAddBefore);
}
 
Example #28
Source File: ContextMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public MenuItem addItem(String caption, Resource icon, Command command) {
    return rootItem.addItem(caption, icon, command);
}
 
Example #29
Source File: ContextMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public MenuItem addItem(String caption, Command command) {
    return rootItem.addItem(caption, command);
}
 
Example #30
Source File: ContextMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public MenuItem addItem(String caption) {
    return rootItem.addItem(caption);
}