Java tutorial
/* * 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 com.trender.user.component; import com.trender.user.AddEditStudyView; import com.trender.user.ProfilePageView; import com.trender.user.UserPageView; import com.vaadin.navigator.Navigator; import com.vaadin.server.FontAwesome; import com.vaadin.ui.Button; import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; import com.vaadin.ui.Label; import com.vaadin.ui.MenuBar; import com.vaadin.ui.UI; import com.vaadin.ui.Window; /** * * @author Vladimir */ public class Header extends CssLayout { private Button singInOrSingOutButton, singUpButton; private Label nameCompany, userNameLable; private MenuBar menuBar; private Navigator navigator; private Window window; public Header() { super(); } public Component intitIngexPageComponent() { init(); singInOrSingOutButton = new Button(); singInOrSingOutButton.setIcon(FontAwesome.USER); singInOrSingOutButton.setCaption(""); singInOrSingOutButton.setStyleName("v-button-header-login"); singUpButton = new Button(); singUpButton.setCaption("???"); singUpButton.addStyleName("v-button-header-reg"); singUpButton.addStyleName("v-button-primary"); addComponent(singInOrSingOutButton); addComponent(singUpButton); addComponent(menuBar); singInOrSingOutButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { initWindowModal(400, "", true); } }); singUpButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { initWindowModal(500, "??", false); } }); return this; } public Component intitUserPageComponent(String name) { init(); userNameLable = new Label(); userNameLable.setWidth(400, Unit.PIXELS); userNameLable.setValue(" " + name); userNameLable.addStyleName("v-label-header-user-name"); userNameLable.addStyleName("v-label"); singInOrSingOutButton = new Button(); singInOrSingOutButton.setCaption(""); singInOrSingOutButton.addStyleName("v-button-header-sing-out"); singInOrSingOutButton.addStyleName("v-button-primary"); MenuBar.Command command = new MenuBar.Command() { @Override public void menuSelected(MenuBar.MenuItem selectedItem) { Header.this.menuSelected(selectedItem.getId()); } }; menuBar.addItem(" ??", command); menuBar.addItem(" ??", command); menuBar.addItem("", command); addComponent(userNameLable); addComponent(singInOrSingOutButton); addComponent(menuBar); return this; } private void init() { setSizeFull(); addStyleName("v-background"); setHeight(70, Unit.PIXELS); nameCompany = new Label(); nameCompany.setValue("Trender"); nameCompany.addStyleName("v-label"); nameCompany.addStyleName("v-label-align-center"); nameCompany.addStyleName("v-logo"); nameCompany.setWidth(150, Unit.PIXELS); menuBar = new MenuBar(); menuBar.setSizeFull(); menuBar.setWidth(100.6F, Unit.PERCENTAGE); menuBar.setHeight(35, Unit.PIXELS); menuBar.addStyleName("v-menubar"); menuBar.addStyleName("v-menu"); addComponentAsFirst(nameCompany); } private void menuSelected(int id) { navigator = getUI().getNavigator(); System.out.println(id); switch (id) { case 2: System.out.println(": " + UserPageView.USER_PAGE_VIEW_NAME); navigator.navigateTo(UserPageView.USER_PAGE_VIEW_NAME); break; case 3: System.out.println(": " + AddEditStudyView.ADD_EDIT_STUDY_VIEW_NAME); navigator.navigateTo(AddEditStudyView.ADD_EDIT_STUDY_VIEW_NAME); break; case 4: System.out.println(": " + ProfilePageView.PROFILE_PAGE_VIEW_NAME); navigator.navigateTo(ProfilePageView.PROFILE_PAGE_VIEW_NAME); break; } } private void initWindowModal(int size, String name, boolean flag) { window = new Window(name); window.setWidth(size, Unit.PIXELS); window.setResizable(false); if (flag) { window.setContent(new UserForm().loginForm()); } else { window.setContent(new UserForm().regForm()); } window.setModal(true); window.center(); UI.getCurrent().addWindow(window); } }