Java tutorial
/* * Roperty - An advanced property management and retrival system * Copyright (C) 2013 PARSHIP GmbH * * 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.parship.roperty.ui; import com.parship.roperty.ui.command.LogoutCommand; import com.parship.roperty.ui.navigation.Frames; import com.parship.roperty.ui.navigation.NavigationRegistry; import com.parship.roperty.ui.navigation.Views; import com.parship.roperty.ui.permission.UIPermissionManager; import com.parship.roperty.ui.permission.UserManager; import com.parship.roperty.ui.persistence.entity.User; import com.vaadin.annotations.AutoGenerated; import com.vaadin.navigator.Navigator; import com.vaadin.navigator.View; import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; import com.vaadin.server.FileResource; import com.vaadin.server.VaadinService; import com.vaadin.ui.AbsoluteLayout; import com.vaadin.ui.CustomComponent; import com.vaadin.ui.MenuBar; import com.vaadin.ui.Notification; import java.io.File; /** * TODO * * @author marc * Since 18.07.2013 */ public class NavigationViewUI extends CustomComponent implements View { /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */ @AutoGenerated private AbsoluteLayout mainLayout; @AutoGenerated private WorkBenchSplitViewUI workBenchSplitViewUI; @AutoGenerated private MenuBar mainMenuBar; private static final long serialVersionUID = 1L; /** * The constructor should first build the main layout, set the * composition root and then do any custom initialization. * The constructor will not be automatically regenerated by the * visual editor. */ public NavigationViewUI() { buildMainLayout(); setCompositionRoot(mainLayout); /* Menu Bar */ // User Menu User currentUser = UserManager.getCurrentUser(); if (currentUser != null) { String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileResource resourceCloudIcon = new FileResource( new File(basepath + "/WEB-INF/images/icons/111-user.png")); MenuBar.MenuItem userMenu = mainMenuBar.addItem(currentUser.getFullName(), null); userMenu.setIcon(resourceCloudIcon); userMenu.addItem("Logout", new LogoutCommand()); } } @Override public void enter(ViewChangeEvent event) { if (!UIPermissionManager.getInstance().hasPermission(UserManager.getCurrentUser(), this.getClass())) { Notification.show("No Permission to enter this view", Notification.Type.ERROR_MESSAGE); event.getNavigator().navigateTo(Views.ERROR.name()); } if (!UserManager.isLoggedIn()) { try { Navigator navigator = NavigationRegistry.getNavigator(Frames.MAIN); navigator.navigateTo(Views.LOGIN.name()); } catch (Exception e) { this.setEnabled(false); Notification.show(e.getLocalizedMessage(), Notification.Type.ERROR_MESSAGE); } } } @AutoGenerated private AbsoluteLayout buildMainLayout() { // common part: create layout mainLayout = new AbsoluteLayout(); mainLayout.setImmediate(false); mainLayout.setWidth("100%"); mainLayout.setHeight("100%"); // top-level component properties setWidth("100.0%"); setHeight("100.0%"); // mainMenuBar mainMenuBar = new MenuBar(); mainMenuBar.setImmediate(false); mainMenuBar.setWidth("100.0%"); mainMenuBar.setHeight("-1px"); mainLayout.addComponent(mainMenuBar, "top:0.0px;right:0.0px;left:0.0px;"); // workBenchSplitViewUI workBenchSplitViewUI = new WorkBenchSplitViewUI(); workBenchSplitViewUI.setImmediate(false); workBenchSplitViewUI.setWidth("100.0%"); workBenchSplitViewUI.setHeight("100.0%"); mainLayout.addComponent(workBenchSplitViewUI, "top:40.0px;right:20.0px;bottom:20.0px;left:20.0px;"); return mainLayout; } }