Example usage for com.vaadin.ui MenuBar.MenuItem setEnabled

List of usage examples for com.vaadin.ui MenuBar.MenuItem setEnabled

Introduction

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

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:org.jpos.qi.Header.java

License:Open Source License

private void decorate(MenuBar.MenuItem mi, Element e) {
    String style = e.getAttributeValue("style");
    if (style != null)
        mi.setStyleName(e.getAttributeValue("style"));
    String iconName = e.getAttributeValue("icon");
    if (iconName != null) {
        try {/*from   w  ww .  ja va  2  s. co  m*/
            mi.setIcon(VaadinIcons.valueOf(iconName));
        } catch (IllegalArgumentException ex) {
            mi.setIcon(VaadinIcons.EXCLAMATION);
            mi.setEnabled(false);
        }
    }
}

From source file:org.opennms.features.topology.app.internal.menu.MenuBuilder.java

License:Open Source License

private static MenuBar.MenuItem addItem(ItemAddBehaviour<MenuBar.MenuItem> behaviour, MenuItem eachChildElement,
        List<VertexRef> targets, OperationContext operationContext, List<Runnable> hooks) {
    boolean visibility = eachChildElement.isVisible(targets, operationContext);
    if (visibility) { // only add item if it is actually visible
        final MenuBar.MenuItem childMenuItem = behaviour.addItem();
        final boolean enabled = eachChildElement.isEnabled(targets, operationContext);
        final boolean checkable = eachChildElement.isCheckable();
        childMenuItem.setEnabled(enabled);
        childMenuItem.setCheckable(checkable);
        if (checkable) {
            boolean checked = eachChildElement.isChecked(targets, operationContext);
            childMenuItem.setChecked(checked);
        }//from  w w  w . jav  a  2 s .com

        // Add click behaviour if leaf element
        if (!eachChildElement.getChildren().isEmpty() && eachChildElement.getCommand() != null) {
            LOG.warn("The MenuItem {} is not a leaf but defines a command. The command is ignored.",
                    removeLabelProperties(eachChildElement.getLabel()));
        } else {
            if (eachChildElement.getCommand() != null) {
                childMenuItem.setCommand((MenuBar.Command) selectedItem -> {
                    eachChildElement.getCommand().execute(targets, operationContext);
                    hooks.forEach(hook -> hook.run());
                });
            }
        }
        return childMenuItem;
    }
    return null;
}

From source file:org.vaadin.addons.sitekit.viewlet.anonymous.MenuNavigationViewlet.java

License:Apache License

private void processChildPage(final NavigationVersion navigationVersion, final MenuBar.MenuItem parentItem,
        final String pageName) {
    final ViewVersion pageVersion = getSite().getCurrentViewVersion(pageName);
    if (pageVersion == null) {
        throw new SiteException("Unknown page: " + pageName);
    }//from w  ww  .  java2  s.co m
    if (pageVersion.getViewerRoles().length > 0) {
        boolean roleMatch = false;
        for (final String role : pageVersion.getViewerRoles()) {
            if (getSite().getSecurityProvider().getRoles().contains(role)) {
                roleMatch = true;
                break;
            }
        }
        if (!roleMatch) {
            return;
        }
    }

    final String localizedPageName = pageVersion.isDynamic() ? pageName
            : getSite().localize("page-link-" + pageName);
    final Resource iconResource = pageVersion.isDynamic()
            ? navigationVersion.hasChildPages(pageName) ? getSite().getIcon("page-icon-folder")
                    : getSite().getIcon("page-icon-page")
            : getSite().getIcon("page-icon-" + pageName);

    final MenuBar.MenuItem menuItem = parentItem.addItem(localizedPageName, iconResource,
            navigationVersion.hasChildPages(pageName) ? null : new MenuBar.Command() {
                @Override
                public void menuSelected(MenuBar.MenuItem selectedItem) {
                    UI.getCurrent().getNavigator().navigateTo(pageName);
                }
            });
    menuItem.setStyleName("navigation-" + pageName);
    menuItem.setEnabled(true);

    if (navigationVersion.hasChildPages(pageName)) {
        for (final String childPage : navigationVersion.getChildPages(pageName)) {
            processChildPage(navigationVersion, menuItem, childPage);
        }
    }
}

From source file:ru.codeinside.gses.webui.manager.ManagerWorkplace.java

License:Mozilla Public License

private void chooseTab(MenuBar.MenuItem selectedItem, MenuBar menu, Component componentToShow,
        Component... componentToHides) {
    List<MenuBar.MenuItem> items = menu.getItems();
    for (MenuBar.MenuItem i : items) {
        i.setEnabled(true);
    }// w  w w .  ja v a  2  s  .  c  o  m
    selectedItem.setEnabled(false);
    for (Component componentToHide : componentToHides) {
        if (components.contains(componentToHide)) {
            removeComponent(componentToHide);
        }
    }
    addComponent(componentToShow);
    setExpandRatio(componentToShow, 0.99f);
}

From source file:ru.codeinside.gses.webui.supervisor.TaskManager.java

License:Mozilla Public License

private void addBlock(final String title, final BlockProducer blockProducer) {
    final MenuBar.MenuItem item = menu.addItem(title, new BlockSelector(blockProducer));
    if (currentBlock == null) {
        item.setEnabled(false);
        createBlock(blockProducer);/*from w  ww  .jav a 2s  .com*/
    }
}