Java tutorial
/* * Copyright (C) 2013 SGV * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.gvcc.jgoffice.components; import com.vaadin.server.ThemeResource; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.ui.*; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.MenuBar.MenuItem; import net.gvcc.jgoffice.MainUI; import net.gvcc.jgoffice.commons.Applications; import net.gvcc.jgoffice.searchcomponent.SearchComponent; import net.gvcc.jgoffice.system.factories.SearchBarFactory; import net.gvcc.jgoffice.templates.interfaces.IGlobalConst; import org.vaadin.dialogs.ConfirmDialog; @SuppressWarnings("serial") public class CommandBar extends CustomComponent implements IGlobalConst { /*- VaadinEditorProperties={"grid":"RegularGrid,9","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */ private VerticalLayout mainLayout; private HorizontalLayout navigationBar; private MenuBar menuBar_1; private HorizontalLayout horizontalLayout_2; private Button btnLogout; private HorizontalLayout programList; private Label lblApplicationTitle; private Embedded logoPicture; public SearchComponent searchComponent; /** * The constructor should first build the main layout, set the composition * root and then do any custom initialization. * <p/> * The constructor will not be automatically regenerated by the visual * editor. */ public CommandBar() { buildMainLayout(); setCompositionRoot(mainLayout); programList.setMargin(new MarginInfo(false, true, false, false)); btnLogout.setStyleName(LINK_BUTTONSTYLE); btnLogout.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { // Close the VaadinSession ConfirmDialog.show(getUI(), "Confirm...", "Session will be closed. Continue?", "Continue", "Abort", new ConfirmDialog.Listener() { @Override public void onClose(ConfirmDialog arg0) { if (arg0.isConfirmed()) { // Redirect from the page getUI().getPage().setLocation("jGOffice/logoutpage.html"); getUI().getSession().close(); } else { } } }); } }); } @Override public void attach() { // Create the Application Menu for (Applications app : ((MainUI) UI.getCurrent()).getGlobal().getApplicationsForUser()) { programList.addComponent(app.getButton()); } ((MainUI) UI.getCurrent()).getGlobal().setFunctionMenu(menuBar_1.addItem("Functions", null)); MenuBar.Command com1 = new MenuBar.Command() { @Override public void menuSelected(MenuItem selectedItem) { ((MainUI) UI.getCurrent()).getMainNavigator().navigateTo("modulo1"); } }; MenuBar.Command com2 = new MenuBar.Command() { @Override public void menuSelected(MenuItem selectedItem) { ((MainUI) UI.getCurrent()).getMainNavigator().navigateTo("modul3"); } }; MenuItem tools = menuBar_1.addItem("Tools", com1); MenuItem help = menuBar_1.addItem("Help", com2); tools.addItem("Change password", null); help.addItem("Start Wiki", null); lblApplicationTitle.setContentMode(ContentMode.HTML); super.attach(); } public void setApplicationTitle(String title) { lblApplicationTitle .setValue("<div style='font-size:26px; padding:10px; font-family:Verdana, Geneva, sans-serif;'>" + title + "</div>"); } private VerticalLayout buildMainLayout() { // common part: create layout mainLayout = new VerticalLayout(); mainLayout.setImmediate(false); mainLayout.setWidth("100%"); mainLayout.setHeight("-1px"); mainLayout.setMargin(false); mainLayout.setSpacing(true); // top-level component properties setWidth("100.0%"); setHeight("-1px"); // horizontalLayout_2 horizontalLayout_2 = buildHorizontalLayout_2(); mainLayout.addComponent(horizontalLayout_2); mainLayout.setComponentAlignment(horizontalLayout_2, new Alignment(20)); // searchBar navigationBar = buildNavigationBar(); mainLayout.addComponent(navigationBar); mainLayout.setComponentAlignment(navigationBar, new Alignment(20)); return mainLayout; } private HorizontalLayout buildHorizontalLayout_2() { // common part: create layout horizontalLayout_2 = new HorizontalLayout(); horizontalLayout_2.setImmediate(false); horizontalLayout_2.setWidth("100.0%"); horizontalLayout_2.setHeight("-1px"); horizontalLayout_2.setMargin(false); horizontalLayout_2.setSpacing(true); // logoPicture logoPicture = new Embedded(); logoPicture.setImmediate(false); logoPicture.setWidth("-1px"); logoPicture.setHeight("-1px"); logoPicture.setSource(new ThemeResource("img/LogoSgvV1.png")); logoPicture.setType(1); logoPicture.setMimeType("image/png"); horizontalLayout_2.addComponent(logoPicture); // lblApplicationTitle lblApplicationTitle = new Label(); lblApplicationTitle.setStyleName("g-applicationtitle"); lblApplicationTitle.setImmediate(false); lblApplicationTitle.setWidth("-1px"); lblApplicationTitle.setHeight("-1px"); lblApplicationTitle.setValue("Label"); horizontalLayout_2.addComponent(lblApplicationTitle); horizontalLayout_2.setComponentAlignment(lblApplicationTitle, new Alignment(33)); // programList programList = new HorizontalLayout(); programList.setImmediate(false); programList.setWidth("-1px"); programList.setHeight("-1px"); programList.setMargin(false); programList.setSpacing(true); horizontalLayout_2.addComponent(programList); horizontalLayout_2.setExpandRatio(programList, 1.0f); horizontalLayout_2.setComponentAlignment(programList, new Alignment(34)); // btnLogout btnLogout = new Button(); btnLogout.setCaption("Logout"); btnLogout.setImmediate(true); btnLogout.setWidth("-1px"); btnLogout.setHeight("-1px"); horizontalLayout_2.addComponent(btnLogout); horizontalLayout_2.setComponentAlignment(btnLogout, new Alignment(34)); return horizontalLayout_2; } private HorizontalLayout buildNavigationBar() { // common part: create layout navigationBar = new HorizontalLayout(); navigationBar.setStyleName("g-commandBar"); navigationBar.setImmediate(false); navigationBar.setWidth("100.0%"); navigationBar.setHeight("-1px"); navigationBar.setMargin(true); // menuBar_1 menuBar_1 = new MenuBar(); menuBar_1.setImmediate(false); menuBar_1.setWidth("-1px"); menuBar_1.setHeight("-1px"); navigationBar.addComponent(menuBar_1); navigationBar.setComponentAlignment(menuBar_1, new Alignment(33)); // searchComponent searchComponent = SearchBarFactory.getInstance(); searchComponent.setWidth("100%"); navigationBar.addComponent(searchComponent); navigationBar.setExpandRatio(searchComponent, 1); return navigationBar; } }