Example usage for com.vaadin.ui MenuBar setId

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

Introduction

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

Prototype

@Override
    public void setId(String id) 

Source Link

Usage

From source file:org.azrul.langkuik.Langkuik.java

public void initLangkuik(final EntityManagerFactory emf, final UI ui,
        final RelationManagerFactory relationManagerFactory, List<Class<?>> customTypeInterfaces) {

    List<Class<?>> rootClasses = new ArrayList<>();
    for (ManagedType<?> entity : emf.getMetamodel().getManagedTypes()) {
        Class<?> clazz = entity.getJavaType();
        if (clazz.getAnnotation(WebEntity.class).isRoot() == true) {
            rootClasses.add(clazz);//from  ww w.jav a  2s  .  c o m
        }
    }

    //Manage custom type
    if (customTypeInterfaces == null) {
        customTypeInterfaces = new ArrayList<>();
    }
    //add system level custom type
    customTypeInterfaces.add(AttachmentCustomType.class);
    //create DAOs for custom types
    final List<DataAccessObject<?>> customTypeDaos = new ArrayList<>();
    for (Class<?> clazz : customTypeInterfaces) {
        customTypeDaos.add(new HibernateGenericDAO(emf, clazz));
    }

    //Setup page
    VerticalLayout main = new VerticalLayout();
    VerticalLayout content = new VerticalLayout();
    final Navigator navigator = new Navigator(ui, content);
    final HorizontalLayout breadcrumb = new HorizontalLayout();

    MenuBar menubar = new MenuBar();
    menubar.setId("MENUBAR");
    main.addComponent(menubar);
    main.addComponent(breadcrumb);
    main.addComponent(content);

    final Deque<History> history = new ArrayDeque<>();
    final Configuration config = Configuration.getInstance();

    history.push(new History("START", "Start"));
    StartView startView = new StartView(history, breadcrumb);
    navigator.addView("START", startView);
    MenuBar.MenuItem create = menubar.addItem("Create", null);
    MenuBar.MenuItem view = menubar.addItem("View", null);

    final PageParameter pageParameter = new PageParameter(customTypeDaos, emf, relationManagerFactory, history,
            config, breadcrumb);

    for (final Class rootClass : rootClasses) {
        final WebEntity myObject = (WebEntity) rootClass.getAnnotation(WebEntity.class);
        final DataAccessObject<?> dao = new HibernateGenericDAO<>(emf, rootClass);
        create.addItem("New " + myObject.name(), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                Object object = dao.createNew(true);
                BeanView<Object, ?> createNewView = new BeanView<>(object, null, null, pageParameter);
                String targetView = "CREATE_NEW_APPLICATION_" + UUID.randomUUID().toString();
                navigator.addView(targetView, (View) createNewView);
                history.clear();
                history.push(new History("START", "Start"));
                History his = new History(targetView, "Create new " + myObject.name());
                history.push(his);
                navigator.navigateTo(targetView);
            }
        });
        view.addItem("View " + myObject.name(), new MenuBar.Command() {
            @Override
            public void menuSelected(MenuBar.MenuItem selectedItem) {
                PlainTableView<?> seeApplicationView = new PlainTableView<>(rootClass, pageParameter);
                String targetView = "VIEW_APPLICATION_" + UUID.randomUUID().toString();
                navigator.addView(targetView, (View) seeApplicationView);
                history.clear();
                history.push(new History("START", "Start"));
                History his = new History(targetView, "View " + myObject.name());
                history.push(his);
                navigator.navigateTo(targetView);
            }
        });
    }

    menubar.addItem("Logout", null).addItem("Logout", new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            ConfirmDialog.show(ui, "Please Confirm:", "Are you really sure you want to log out?", "I am",
                    "Not quite", new ConfirmDialog.Listener() {
                        @Override
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                HttpServletRequest req = (HttpServletRequest) VaadinService.getCurrentRequest();
                                HttpServletResponse resp = (HttpServletResponse) VaadinService
                                        .getCurrentResponse();
                                Authentication auth = SecurityContextHolder.getContext().getAuthentication();
                                SecurityContextLogoutHandler ctxLogOut = new SecurityContextLogoutHandler();
                                ctxLogOut.logout(req, resp, auth);
                            }
                        }
                    });

        }
    });
    navigator.navigateTo("START");
    ui.setContent(main);
}

From source file:rs.co.micro.bwNet.navigationMenu.java

public navigationMenu() {

    //Main Panel/*from   w ww.j a v a  2s.  com*/
    setResponsive(true);
    setSpacing(true);
    setMargin(false);

    HorizontalLayout topMenu = new HorizontalLayout();
    topMenu.setSizeFull();

    //Logout Dugme
    MenuBar logout = new MenuBar();
    logout.setId("logoutDugme");
    logout.setSizeFull();
    logout.setResponsive(true);
    logout.setDescription("Izadjite iz programa");

    MenuBar.MenuItem logoutDugme = logout.addItem("Logout", FontAwesome.SIGN_OUT, new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            getUI().getSession().close();
            navigator.addView("login", new login());
            navigator.navigateTo("login");
        }
    });

    //Navigacioni meni
    MenuBar navMeni = new MenuBar();
    navMeni.setId("navMeni");
    navMeni.setSizeFull();
    navMeni.setResponsive(true);

    // A top-level menu item that opens a submenu
    MenuBar.MenuItem uvidi = navMeni.addItem("Uvidi", null, null);
    //Nesto poput click listenera
    MenuBar.Command mycommand = new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {
            Notification.show("radi");
        }
    };

    //        karticaPartnera.addItem("Tea",
    //                FontAwesome.DROPBOX, mycommand);
    //        karticaPartnera.addItem("Coffee",
    //                FontAwesome.COFFEE, mycommand);
    // Another top-level item
    MenuBar.MenuItem snacks = navMeni.addItem("Snacks", null, null);
    snacks.addItem("Weisswurst", null, mycommand);
    snacks.addItem("Bratwurst", null, mycommand);
    snacks.addItem("Currywurst", null, mycommand);
    snacks.addItem("Test1", null, mycommand);
    snacks.addItem("test2", null, mycommand);

    // Yet another top-level item
    MenuBar.MenuItem servs = navMeni.addItem("Services", null, null);
    servs.addItem("Car Service", null, mycommand);

    topMenu.addComponents(navMeni, logout);
    addComponents(topMenu);

    // Kreira Kartica Partnera submeni i pokazuje Karticu 
    MenuBar.MenuItem karticaPartnera;
    karticaPartnera = uvidi.addItem("Kartica Partnera", null, new MenuBar.Command() {
        @Override
        public void menuSelected(MenuBar.MenuItem selectedItem) {

            try {
                navigator.addView("BWKarticaPartnera", new BWkarticaPartnera());

            } catch (SQLException ex) {
                System.out.println("Greska (BWnFinex klasa)" + SQLException.class);
            }
            navigator.navigateTo("BWKarticaPartnera");
        }
    });

    System.out.println("ubacen meni");
}