Java Code Examples for com.vaadin.ui.MenuBar#MenuItem

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: WebAppMenu.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void addChildItem(MenuItem menuItem) {
    MenuBar.MenuItem childItem = ((MenuItemImpl) menuItem).getDelegateItem();
    if (childItem.getText() == null) {
        throw new IllegalArgumentException("Caption cannot be null");
    }

    MenuBar.MenuItem delegateItem = this.getDelegateItem();

    childItem.setParent(delegateItem);

    delegateItem.getChildren().add(childItem);
    menu.registerMenuItem(menuItem);

    menu.getComponent().markAsDirty();
}
 
Example 2
Source File: WebAppMenu.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void addChildItem(MenuItem menuItem, int index) {
    MenuBar.MenuItem childItem = ((MenuItemImpl) menuItem).getDelegateItem();
    if (childItem.getText() == null) {
        throw new IllegalArgumentException("Caption cannot be null");
    }

    MenuBar.MenuItem delegateItem = this.getDelegateItem();

    childItem.setParent(delegateItem);

    delegateItem.getChildren().add(index, childItem);
    menu.registerMenuItem(menuItem);

    menu.getComponent().markAsDirty();
}
 
Example 3
Source File: WebUserActionsButton.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void initUserMenuButton(boolean authenticated) {
    MenuBar.MenuItem userMenuButton = component.addItem("");
    userMenuButton.setDescription(messages.getMainMessage("userActionsBtnDescription"));
    userMenuButton.setIcon(getIconResource(CubaIcon.USER));
    userMenuButton.setVisible(authenticated);

    if (security.isScreenPermitted("settings")) {
        userMenuButton.addItem(messages.getMainMessage("settings"),
                getIconResource(CubaIcon.GEAR), item -> openSettings());
    }

    userMenuButton.addItem(messages.getMainMessage("logoutBtnDescription"),
            getIconResource(CubaIcon.SIGN_OUT), item -> logout());
}
 
Example 4
Source File: WebAppMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public MenuItem createMenuItem(String id, String caption,
                               @Nullable String icon, @Nullable Consumer<MenuItem> command) {
    checkNotNullArgument(id);
    checkItemIdDuplicate(id);

    MenuItemImpl menuItem = new MenuItemImpl(this, id);

    Resource iconResource = null;
    if (icon != null) {
        iconResource = AppBeans.get(IconResolver.class).getIconResource(icon);
    }

    MenuBar.MenuItem delegateItem = component.createMenuItem(caption, iconResource, null);
    if (command != null) {
        @SuppressWarnings("UnnecessaryLocalVariable")
        Consumer<MenuItem> nonnullCommand = command;

        delegateItem.setCommand(selectedItem ->
                nonnullCommand.accept(menuItem));
    }
    menuItem.setDelegateItem(delegateItem);

    menuItem.setCaption(caption);
    menuItem.setIcon(icon);
    menuItem.setCommand(command);

    return menuItem;
}
 
Example 5
Source File: WebAppMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void assignCubaIds(MenuItem menuItem, String id) {
    AppUI ui = (AppUI) component.getUI();
    if (ui == null || !ui.isTestMode()) {
        return;
    }

    MenuBar.MenuItem delegateItem = ((MenuItemImpl) menuItem).getDelegateItem();
    component.setCubaId(delegateItem, id);
}
 
Example 6
Source File: WebAppMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public MenuItem createSeparator() {
    MenuItemImpl menuItem = new MenuItemImpl(this, null);
    menuItem.setSeparator(true);

    MenuBar.MenuItem separator = component.createSeparator();
    menuItem.setDelegateItem(separator);

    return menuItem;
}
 
Example 7
Source File: WebAppMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void removeChildItem(MenuItem menuItem) {
    MenuBar.MenuItem childItem = ((MenuItemImpl) menuItem).getDelegateItem();

    getDelegateItem().getChildren().remove(childItem);
    menu.unregisterItem(menuItem);
}
 
Example 8
Source File: WebAppMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void menuSelected(@SuppressWarnings("unused") MenuBar.MenuItem event) {
    CubaUI ui = (CubaUI) menu.getComponent().getUI();
    if (ui.isAccessibleForUser(menu.getComponent())) {
        this.command.accept(this);
    } else {
        LoggerFactory.getLogger(WebAppMenu.class)
                .debug("Ignore click because menu is inaccessible for user");
    }
}
 
Example 9
Source File: WebUserActionsButton.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void initLoginButton(boolean authenticated) {
    MenuBar.MenuItem loginButton = component.addItem("", item -> login());
    loginButton.setDescription(messages.getMainMessage("loginBtnDescription"));
    loginButton.setIcon(getIconResource(CubaIcon.SIGN_IN));
    loginButton.setVisible(!authenticated);
}
 
Example 10
Source File: WebAppMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void removeMenuItem(int index) {
    MenuBar.MenuItem delegateItem = component.getMenuItems().get(index);
    component.removeMenuItem(delegateItem);
    unregisterItem(viewModelMap.get(delegateItem));
}
 
Example 11
Source File: WebAppMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public MenuBar.MenuItem getDelegateItem() {
    return delegateItem;
}
 
Example 12
Source File: WebAppMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void setDelegateItem(MenuBar.MenuItem delegateItem) {
    this.delegateItem = delegateItem;
}
 
Example 13
Source File: CubaMenuBar.java    From cuba with Apache License 2.0 4 votes vote down vote up
public MenuItem createSeparator() {
    MenuBar.MenuItem menuItem = createMenuItem("", null, null);
    setMenuItemSeparator(menuItem, true);
    return menuItem;
}