Example usage for com.vaadin.ui MenuBar getSize

List of usage examples for com.vaadin.ui MenuBar getSize

Introduction

In this page you can find the example usage for com.vaadin.ui MenuBar getSize.

Prototype

public int getSize() 

Source Link

Document

Returns the size of the menu.

Usage

From source file:com.expressui.core.view.menu.MainMenuBar.java

License:Open Source License

/**
 * Refreshes the menu bar, useful when security permissions change, for example when user logs in and
 * is no longer anonymous.//from www  . ja v a 2 s .  c om
 */
public void refresh() {
    removeAllComponents();
    MenuBar leftMenuBar = leftMenuBarRoot.createMenuBar();
    addComponent(leftMenuBar);

    MenuBar rightMenuBar = rightMenuBarRoot.createMenuBar();
    addComponent(rightMenuBar);
    setComponentAlignment(rightMenuBar, Alignment.MIDDLE_RIGHT);

    if (leftMenuBar.getSize() == 0 && rightMenuBar.getSize() == 0) {
        if (getCurrentUser().getRoles().isEmpty()) {
            getMainApplication().showError(
                    "Menu bar contains no viewable items because current user is not assigned any roles.");
        } else {
            getMainApplication()
                    .showError("Menu bar contains no viewable items, either because none have been coded"
                            + " or assigned roles do not allow any to be viewed.");
        }
    }

    addPopupCodeIfEnabled();
}

From source file:nz.co.senanque.perspectiveslibrary.MenuCloner.java

License:Apache License

public static void merge(MenuBar target, MenuBar source, List<MenuBar.MenuItem> added) {
    if (source != null) {
        List<MenuBar.MenuItem> targetItems = target.getItems();
        for (MenuBar.MenuItem sourceItem : source.getItems()) {
            MenuBar.MenuItem targetItem = findItem(sourceItem.getText(), targetItems);
            if (targetItem == null) {
                try {
                    int sizeOfTarget = target.getSize();
                    if (sizeOfTarget > 0) {
                        targetItem = target.addItemBefore(sourceItem.getText(), null, sourceItem.getCommand(),
                                target.getItems().get(sizeOfTarget - 1));
                    }//from   ww  w  .j  a  va 2 s.  co  m
                } catch (Exception e) {
                }
                if (targetItem == null) {
                    targetItem = target.addItem(sourceItem.getText(), sourceItem.getCommand());
                }
                fixMenuItem(targetItem, sourceItem);
                added.add(targetItem);
            }
            merge(targetItem, sourceItem, added);
        }
    }
}