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.squadd.views; import com.squadd.UI.HeaderLayout; import com.squadd.UI.MainPageLayout; import com.squadd.UI.MenuLayout; import com.vaadin.event.MouseEvents; import com.vaadin.navigator.Navigator; import com.vaadin.navigator.ViewChangeListener; import com.vaadin.spring.annotation.SpringView; import com.vaadin.spring.annotation.UIScope; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.Layout; import com.vaadin.ui.Panel; import javax.annotation.PostConstruct; import org.springframework.stereotype.Component; /** * * @author SharkNado */ @SpringView(name = MainPageView.name) @UIScope public class MainPageView extends PrimaryView { protected MainPageLayout mainPageLayout; public static final String name = "MainView"; @Override public void enter(ViewChangeListener.ViewChangeEvent event) { super.enter(event); } @PostConstruct protected void init() { if (contact == null || contact.getId() == null) { return; } mainPageLayout = new MainPageLayout(contact, fillContentPanel(null)); addComponents(mainPageLayout); configureActions(); } private void configureActions() { ClickListener logOut = new ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { contact.setAuthorized(false); getUI().getNavigator().navigateTo(LoginView.name); } }; mainPageLayout.getHeader().getLogout().addClickListener(logOut); configurePanelsActions(); } private void configurePanelsActions() { MouseEvents.ClickListener mainPageListener = new MouseEvents.ClickListener() { @Override public void click(MouseEvents.ClickEvent event) { getUI().getNavigator().navigateTo(UserPageView.NAME); } }; mainPageLayout.getMenu().getMainPagePanel().addClickListener(mainPageListener); MouseEvents.ClickListener groupsPageListener = new MouseEvents.ClickListener() { @Override public void click(MouseEvents.ClickEvent event) { getUI().getNavigator().navigateTo(GroupsView.NAME); } }; mainPageLayout.getMenu().getGroupsPanel().addClickListener(groupsPageListener); MouseEvents.ClickListener messagesPageListener = new MouseEvents.ClickListener() { @Override public void click(MouseEvents.ClickEvent event) { getUI().getNavigator().navigateTo(ChatView.NAME); } }; mainPageLayout.getMenu().getMessagesPanel().addClickListener(messagesPageListener); } protected Panel fillContentPanel(Layout layout) { //must be overriden for not allowing empty content panel return new Panel(layout); } }