org.balisunrise.vaadin.components.header.ModuleMenu.java Source code

Java tutorial

Introduction

Here is the source code for org.balisunrise.vaadin.components.header.ModuleMenu.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.balisunrise.vaadin.components.header;

import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.Notification;
import com.vaadin.ui.themes.Reindeer;
import com.vaadin.ui.themes.ValoTheme;

/**
 *
 * @author Glauco
 */
public class ModuleMenu extends CustomComponent {

    private MenuBar menuBar;

    public ModuleMenu() {
        init();
    }

    private void init() {
        setHeight("100%");
        setWidthUndefined();

        menuBar = new MenuBar();
        menuBar.setStyleName("b-module-menu");

        setCompositionRoot(menuBar);

        MenuBar.MenuItem item;
        item = menuBar.addItem("Menu 1", new ItemCommand());
        item.setStyleName("b-module-menu-item");
        item.setDescription("1 Item do menu");

        MenuBar.MenuItem subMenu;
        subMenu = menuBar.addItem("Sub Menus 1", null);
        subMenu.setStyleName("b-module-menu-item");

        item = subMenu.addItem("Menu 2", new ItemCommand());
        item.setStyleName("b-module-menu-item");
        item.setDescription("2 Item do menu");

        item = subMenu.addItem("Menu 3", new ItemCommand());
        item.setStyleName("b-module-menu-item");
        item.setDescription("3 Item do menu");

        subMenu = menuBar.addItem("Sub Menus 2", null);
        subMenu.setStyleName("b-module-menu-item");

        MenuBar.MenuItem subMenu2;
        subMenu2 = subMenu.addItem("Sub Sub Menu 1", null);
        subMenu2.setStyleName("b-module-menu-item");

        item = subMenu2.addItem("Menu 4", new ItemCommand());
        item.setStyleName("b-module-menu-item");
        item.setDescription("4 Item do menu");

        item = subMenu2.addItem("Menu 5", new ItemCommand());
        item.setStyleName("b-module-menu-item");
        item.setDescription("5 Item do menu");

        subMenu2 = subMenu.addItem("Sub Sub Menu 2", null);
        subMenu2.setStyleName("b-module-menu-item");

        item = subMenu2.addItem("Menu 6", new ItemCommand());
        item.setStyleName("b-module-menu-item");
        item.setDescription("6 Item do menu");

        item = subMenu2.addItem("Menu 7", new ItemCommand());
        item.setStyleName("b-module-menu-item");
        item.setDescription("7 Item do menu");
    }

    private class ItemCommand implements MenuBar.Command {

        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            Notification.show(selectedItem.getDescription(), Notification.Type.TRAY_NOTIFICATION);
        }

    }
}