Java tutorial
/* * Copyright 2012 Lexaden.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.freebox.engeneering.application.web.layout; import static com.freebox.engeneering.application.web.login.Constants.FREEBOX_MENU; import com.freebox.engeneering.application.view.state.StateConstants; import com.freebox.engeneering.application.web.common.AbstractController; import com.lexaden.webflow.StateEvent; import com.lexaden.webflow.annotation.OnEnterState; import com.lexaden.webflow.annotation.OnEvent; import com.lexaden.webflow.annotation.OnExitState; import com.lexaden.webflow.core.model.TransitionTarget; import com.vaadin.server.ThemeResource; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.ui.Button; import com.vaadin.ui.CssLayout; import com.vaadin.ui.Image; import com.vaadin.ui.Label; import com.vaadin.ui.MenuBar; import com.vaadin.ui.NativeButton; import com.vaadin.ui.Notification; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.MenuBar.Command; import com.vaadin.ui.MenuBar.MenuItem; /** * This class is responsible for UI components collaborations on left side bar part of the screen. * * @author Aliaksei Papou */ @SuppressWarnings("serial") public class LeftSideBarController extends AbstractController<VerticalLayout> { private CssLayout sideBarHeader = new CssLayout(); private CssLayout menu = new CssLayout(); private VerticalLayout sideBarFooter = new VerticalLayout(); /** * Initializes view when system enters 'initView' action state. * * @param event - state event. */ public void initView(@SuppressWarnings("rawtypes") StateEvent event) { final VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addStyleName("sidebar"); verticalLayout.setWidth("100%"); verticalLayout.setHeight("100%"); setView(verticalLayout); } /** * This method is called every time system enters any profile state * * @param stateEvent -state event. */ @OnEnterState(StateConstants.PROFILE) public void buildLeftSideBarView(@SuppressWarnings("rawtypes") StateEvent stateEvent) { clearView(stateEvent); final TransitionTarget targetState = stateEvent.getTargetState(); stateEvent.getContext().getParent().set(StateConstants.PROFILE, targetState); } private void createHeaderSideBar() { VerticalLayout verticalLayout = super.getView(); sideBarHeader.addStyleName("branding"); Label logo = new Label("<span>Freebox Dashboard</span> Manager", ContentMode.HTML); logo.setSizeUndefined(); sideBarHeader.addComponent(logo); verticalLayout.addComponent(sideBarHeader); } private void createFooterSideBar() { VerticalLayout verticalLayout = super.getView(); sideBarFooter.setSizeUndefined(); sideBarFooter.addStyleName("user"); Image profilePic = new Image(null, new ThemeResource("img/profile-pic.png")); profilePic.setWidth("34px"); sideBarFooter.addComponent(profilePic); Label userName = new Label("MOHELLEBI ATAF"); userName.setSizeUndefined(); sideBarFooter.addComponent(userName); Command cmd = new Command() { @Override public void menuSelected(MenuItem selectedItem) { Notification.show("Not implemented in this demo"); } }; MenuBar settings = new MenuBar(); MenuItem settingsMenu = settings.addItem("", null); settingsMenu.setStyleName("icon-cog"); settingsMenu.addItem("Settings", cmd); settingsMenu.addItem("Preferences", cmd); settingsMenu.addSeparator(); settingsMenu.addItem("My Account", cmd); sideBarFooter.addComponent(settings); Button exit = new NativeButton("Exit"); exit.addStyleName("icon-cancel"); exit.setDescription("Sign Out"); sideBarFooter.addComponent(exit); exit.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { } }); verticalLayout.addComponent(sideBarFooter); } private void createMenuSideBar() { menu.addStyleName("no-vertical-drag-hints"); menu.addStyleName("no-horizontal-drag-hints"); menu.addStyleName("menu"); menu.setHeight("100%"); Button freeboxState; Button freeboxDownloads; Button freeboxContacts; Button freeboxCalls; freeboxState = new NativeButton("Etat Freebox");//Etat de la freebox freeboxState.addStyleName("icon-dashboard"); freeboxState.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent clickEvent) { getEventProcessor().fireEvent("register"); } }); menu.addComponent(freeboxState); freeboxDownloads = new NativeButton("Dashbord");//Tlchargement freeboxDownloads.addStyleName("icon-sales"); freeboxDownloads.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent clickEvent) { eventProcessor.fireEvent("dashboard", ""); } }); menu.addComponent(freeboxDownloads); freeboxContacts = new NativeButton("Contacts"); freeboxContacts.addStyleName("icon-transactions"); freeboxContacts.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent clickEvent) { getEventProcessor().fireEvent("register"); } }); menu.addComponent(freeboxContacts); freeboxCalls = new NativeButton("Journal"); freeboxCalls.addStyleName("icon-reports"); freeboxCalls.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent clickEvent) { getEventProcessor().fireEvent("register"); } }); menu.addComponent(freeboxCalls); freeboxState = new NativeButton("Explorateur"); freeboxState.addStyleName("icon-schedule"); freeboxState.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent clickEvent) { getEventProcessor().fireEvent("explorer"); } }); menu.addComponent(freeboxState); freeboxState = new NativeButton("Etat"); freeboxState.addStyleName("icon-dashboard"); freeboxState.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent clickEvent) { getEventProcessor().fireEvent("register"); } }); menu.addComponent(freeboxState); freeboxState = new NativeButton("Etat"); freeboxState.addStyleName("icon-dashboard"); freeboxState.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent clickEvent) { getEventProcessor().fireEvent("register"); } }); menu.addComponent(freeboxState); freeboxState = new NativeButton("Etat"); freeboxState.addStyleName("icon-dashboard"); freeboxState.addClickListener(new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent clickEvent) { getEventProcessor().fireEvent("register"); } }); VerticalLayout verticalLayout = super.getView(); verticalLayout.addComponent(menu); verticalLayout.setExpandRatio(menu, 1); } /** * Initializes personal info view screen. * * @param event the event from web flow executor. */ @OnEvent(FREEBOX_MENU) public void updateFreeboxMenu(@SuppressWarnings("rawtypes") StateEvent event) { clearView(event); if (event != null) { createHeaderSideBar(); createMenuSideBar(); createFooterSideBar(); } } @OnExitState @Override public void clearView(@SuppressWarnings("rawtypes") StateEvent stateEvent) { VerticalLayout content = super.getView(); if (content != null) { content.removeAllComponents(); } } }