/*
* Copyright 2002-2013 the original author or 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 com.es.app;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Component;
import ru.xpoft.vaadin.VaadinView;
import com.es.universalwebframe.composite.MainComponent;
import com.vaadin.annotations.StyleSheet;
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.server.DefaultErrorHandler;
import com.vaadin.server.ErrorHandler;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.Notification;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("serial")
@Component
@Scope("prototype")
@VaadinView(eliteSystemSOUI.NAME)
@StyleSheet("styles.css")
public class eliteSystemSOUI extends UI implements View, ErrorHandler {
public static final String NAME = "EliteSystemSOUI";
private static Logger logger = LoggerFactory
.getLogger(eliteSystemSOUI.class);
// SecurityService securityService;
@Autowired
private transient ApplicationContext applicationContext;
@Override
protected void init(VaadinRequest request) {
try {
logger.info("Inicio AvanteSOUI");
VaadinSession.getCurrent().setErrorHandler(this);
// Notification.show(String.format("Session counter"));
// Create a navigator to control the views
Navigator navigator = new Navigator(this, this);
navigator.getUI().getPage().setTitle("GOBIERNO AUTONOMO EL ORO");
MainComponent mainComponent = new MainComponent(applicationContext);
mainComponent.getMaintab().removeTab(
mainComponent.getMaintab().getTab(0));
mainComponent.getMaintab().addTab(new Label(), "Inicio");
mainComponent.setWidth("100%");
mainComponent.setHeight("100%");
// Create and register the views
navigator.addView("", mainComponent);
setContent(mainComponent);
} catch (Exception e) {
setNavigator(null);
getSession().close();
getUI().getPage().setLocation("login");
return;
}
}
@Override
public void enter(ViewChangeEvent event) {
// TODO Auto-generated method stub
}
@Override
public void error(com.vaadin.server.ErrorEvent event) {
// TODO Auto-generated method stub
// connector event
if (event.getThrowable().getCause() instanceof AccessDeniedException) {
AccessDeniedException accessDeniedException = (AccessDeniedException) event
.getThrowable().getCause();
Notification.show(accessDeniedException.getMessage(),
Notification.Type.ERROR_MESSAGE);
// Cleanup view. Now Vaadin ignores errors and always shows the
// view. :-(
// since beta10
setContent(null);
return;
}
// Error on page load. Now it doesn't work. User sees standard error
// page.
if (event.getThrowable() instanceof AccessDeniedException) {
AccessDeniedException exception = (AccessDeniedException) event
.getThrowable();
Label label = new Label(exception.getMessage());
label.setWidth(-1, Unit.PERCENTAGE);
Link goToMain = new Link("Go to main", new ExternalResource("/"));
VerticalLayout layout = new VerticalLayout();
layout.addComponent(label);
layout.addComponent(goToMain);
layout.setComponentAlignment(label, Alignment.MIDDLE_CENTER);
layout.setComponentAlignment(goToMain, Alignment.MIDDLE_CENTER);
VerticalLayout mainLayout = new VerticalLayout();
mainLayout.setSizeFull();
mainLayout.addComponent(layout);
mainLayout.setComponentAlignment(layout, Alignment.MIDDLE_CENTER);
setContent(mainLayout);
Notification.show(exception.getMessage(),
Notification.Type.ERROR_MESSAGE);
return;
}
DefaultErrorHandler.doDefault(event);
}
}