Java tutorial
/* * Copyright 2015 The original authors * * 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 org.freakz.hokan_ng_springboot.bot; import com.vaadin.navigator.Navigator; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.UIScope; import com.vaadin.spring.navigator.SpringViewProvider; import com.vaadin.ui.CssLayout; import com.vaadin.ui.CustomComponent; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.UI; import org.freakz.hokan_ng_springboot.bot.views.AccessDeniedView; import org.freakz.hokan_ng_springboot.bot.views.ErrorView; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.security.VaadinSecurity; import org.vaadin.spring.sidebar.components.ValoSideBar; import org.vaadin.spring.sidebar.security.VaadinSecurityItemFilter; /** * Full-screen UI component that allows the user to navigate between views, and log out. * * @author Petter Holmstrm (petter@vaadin.com) */ @UIScope @SpringComponent public class MainScreen extends CustomComponent { @Autowired public MainScreen(final VaadinSecurity vaadinSecurity, SpringViewProvider springViewProvider, ValoSideBar sideBar) { HorizontalLayout layout = new HorizontalLayout(); layout.setSizeFull(); setCompositionRoot(layout); setSizeFull(); // By adding a security item filter, only views that are accessible to the user will show up in the side bar. sideBar.setItemFilter(new VaadinSecurityItemFilter(vaadinSecurity)); layout.addComponent(sideBar); CssLayout viewContainer = new CssLayout(); viewContainer.setSizeFull(); layout.addComponent(viewContainer); layout.setExpandRatio(viewContainer, 1f); Navigator navigator = new Navigator(UI.getCurrent(), viewContainer); // Without an AccessDeniedView, the view provider would act like the restricted views did not exist at all. springViewProvider.setAccessDeniedViewClass(AccessDeniedView.class); navigator.addProvider(springViewProvider); navigator.setErrorView(ErrorView.class); navigator.navigateTo(navigator.getState()); } }