// Path: src/main/java/re/vianneyfaiv/persephone/domain/session/UserData.java
// public class UserData {
// 
// 	/**
// 	 * GET /logs page: current range retrieved by user
// 	 */
// 	private LogsRange currentRange;
// 
// 	/**
// 	 * GET /logs page: auto scroll to the bottom (enabled by default)
// 	 */
// 	private boolean tailAutoScrollEnabled = true;
// 
// 	public LogsRange getCurrentRange() {
// 		return currentRange;
// 	}
// 
// 	public void setCurrentRange(LogsRange currentRange) {
// 		this.currentRange = currentRange;
// 	}
// 
// 	public void toggleTailAutoScroll() {
// 		if(tailAutoScrollEnabled) {
// 			tailAutoScrollEnabled = false;
// 		} else {
// 			tailAutoScrollEnabled = true;
// 		}
// 	}
// 
// 	public boolean isTailAutoScrollEnabled() {
// 		return tailAutoScrollEnabled;
// 	}
// 
// }
// 
// Path: src/main/java/re/vianneyfaiv/persephone/exception/UIErrorHandler.java
// public class UIErrorHandler implements ErrorHandler {
// 
// 	private static final long serialVersionUID = 7441835079387513134L;
// 
// 	private static final Logger LOGGER = LoggerFactory.getLogger(UIErrorHandler.class);
// 
// 	@Override
//     public void error(com.vaadin.server.ErrorEvent event) {
// 
// 		// Loop through the exception stack
// 		for (Throwable t = event.getThrowable(); t != null; t = t.getCause()) {
// 
// 			// Try to get a persephone exception
// 			boolean exceptionHandled = handlePersephoneExceptions(t);
// 
// 			// If no persephone exception has been found => try from Exception#getCause
// 			if(!exceptionHandled) {
// 				exceptionHandled = handlePersephoneExceptions(t.getCause());
// 			}
// 
// 			if(exceptionHandled) {
// 				return;
// 			} else if(t instanceof RuntimeException) {
// 				displayErrorNotif("Unhandled runtime exception.", t);
// 				return;
// 			} else {
// 				LOGGER.error("Persephone Error Handler: {} ; Message: {}", t.getClass(), t.getMessage());
// 			}
// 		}
// 	}
// 
// 	private boolean handlePersephoneExceptions(Throwable t) {
// 		boolean handled = false;
// 
// 		// Technical runtime exceptions
// 		if(t instanceof ApplicationRuntimeException) {
// 			ApplicationRuntimeException e = (ApplicationRuntimeException) t;
// 			displayErrorNotif("Unable to reach " + e.getApplication().getUrl(), e);
// 			handled = true;
// 		}
// 		else if(t instanceof ApplicationNotFoundException) {
// 			ApplicationNotFoundException e = (ApplicationNotFoundException) t;
// 			displayErrorNotif(e.getMessage(), e);
// 			handled = true;
// 		}
// 		// Expected exceptions (not handled)
// 		else if(t instanceof ApplicationException) {
// 			ApplicationException e = (ApplicationException) t;
// 			displayErrorNotif("Unhandled error. Application " + e.getApplication().getName(), e);
// 			handled = true;
// 		}
// 
// 		return handled;
// 	}
// 
// 	private void displayErrorNotif(String msg, Throwable t) {
// 		   LOGGER.error(String.format("Error handler: %s", msg), t);
// 
// 		   if(!StringUtils.isEmpty(t.getMessage())) {
// 		           new Notification(
// 		                   msg,
// 		                   t.getMessage(),
// 		                   Notification.Type.ERROR_MESSAGE,
// 		                   false)
// 		                   .show(Page.getCurrent());
// 		       }
// 		}
// }


import org.springframework.beans.factory.annotation.Value;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewDisplay;
import com.vaadin.server.CustomizedSystemMessages;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinService;
import com.vaadin.shared.ui.BorderStyle;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.spring.annotation.SpringViewDisplay;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.Link;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import re.vianneyfaiv.persephone.domain.session.UserData;
import re.vianneyfaiv.persephone.exception.UIErrorHandler;
package re.vianneyfaiv.persephone.ui;




/**
 * Vaadin UI initializer
 */
@Title("Persephone")
@Theme("persephone")
@SpringUI
@SpringViewDisplay
public class PersephoneUI extends UI implements ViewDisplay {

	private Panel springViewDisplay;

	@Value("${info.persephone.version}")
	private String persephoneVersion;

	private UserData userData = new UserData();

	@Override
	protected void init(VaadinRequest request) {

		// Root layout
        final VerticalLayout root = new VerticalLayout();
        root.setSizeFull();

        root.setSpacing(false);
        root.setMargin(false);

        setContent(root);

        // Main panel
        springViewDisplay = new Panel();
        springViewDisplay.setSizeFull();

        root.addComponent(springViewDisplay);
        root.setExpandRatio(springViewDisplay, 1);

        // Footer
        Layout footer = getFooter();
        root.addComponent(footer);
        root.setExpandRatio(footer, 0);

        // Error handler
// Path: src/main/java/re/vianneyfaiv/persephone/domain/session/UserData.java
// public class UserData {
// 
// 	/**
// 	 * GET /logs page: current range retrieved by user
// 	 */
// 	private LogsRange currentRange;
// 
// 	/**
// 	 * GET /logs page: auto scroll to the bottom (enabled by default)
// 	 */
// 	private boolean tailAutoScrollEnabled = true;
// 
// 	public LogsRange getCurrentRange() {
// 		return currentRange;
// 	}
// 
// 	public void setCurrentRange(LogsRange currentRange) {
// 		this.currentRange = currentRange;
// 	}
// 
// 	public void toggleTailAutoScroll() {
// 		if(tailAutoScrollEnabled) {
// 			tailAutoScrollEnabled = false;
// 		} else {
// 			tailAutoScrollEnabled = true;
// 		}
// 	}
// 
// 	public boolean isTailAutoScrollEnabled() {
// 		return tailAutoScrollEnabled;
// 	}
// 
// }
// 
// Path: src/main/java/re/vianneyfaiv/persephone/exception/UIErrorHandler.java
// public class UIErrorHandler implements ErrorHandler {
// 
// 	private static final long serialVersionUID = 7441835079387513134L;
// 
// 	private static final Logger LOGGER = LoggerFactory.getLogger(UIErrorHandler.class);
// 
// 	@Override
//     public void error(com.vaadin.server.ErrorEvent event) {
// 
// 		// Loop through the exception stack
// 		for (Throwable t = event.getThrowable(); t != null; t = t.getCause()) {
// 
// 			// Try to get a persephone exception
// 			boolean exceptionHandled = handlePersephoneExceptions(t);
// 
// 			// If no persephone exception has been found => try from Exception#getCause
// 			if(!exceptionHandled) {
// 				exceptionHandled = handlePersephoneExceptions(t.getCause());
// 			}
// 
// 			if(exceptionHandled) {
// 				return;
// 			} else if(t instanceof RuntimeException) {
// 				displayErrorNotif("Unhandled runtime exception.", t);
// 				return;
// 			} else {
// 				LOGGER.error("Persephone Error Handler: {} ; Message: {}", t.getClass(), t.getMessage());
// 			}
// 		}
// 	}
// 
// 	private boolean handlePersephoneExceptions(Throwable t) {
// 		boolean handled = false;
// 
// 		// Technical runtime exceptions
// 		if(t instanceof ApplicationRuntimeException) {
// 			ApplicationRuntimeException e = (ApplicationRuntimeException) t;
// 			displayErrorNotif("Unable to reach " + e.getApplication().getUrl(), e);
// 			handled = true;
// 		}
// 		else if(t instanceof ApplicationNotFoundException) {
// 			ApplicationNotFoundException e = (ApplicationNotFoundException) t;
// 			displayErrorNotif(e.getMessage(), e);
// 			handled = true;
// 		}
// 		// Expected exceptions (not handled)
// 		else if(t instanceof ApplicationException) {
// 			ApplicationException e = (ApplicationException) t;
// 			displayErrorNotif("Unhandled error. Application " + e.getApplication().getName(), e);
// 			handled = true;
// 		}
// 
// 		return handled;
// 	}
// 
// 	private void displayErrorNotif(String msg, Throwable t) {
// 		   LOGGER.error(String.format("Error handler: %s", msg), t);
// 
// 		   if(!StringUtils.isEmpty(t.getMessage())) {
// 		           new Notification(
// 		                   msg,
// 		                   t.getMessage(),
// 		                   Notification.Type.ERROR_MESSAGE,
// 		                   false)
// 		                   .show(Page.getCurrent());
// 		       }
// 		}
// }


// Path: src/main/java/re/vianneyfaiv/persephone/ui/PersephoneUI.java
import org.springframework.beans.factory.annotation.Value;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewDisplay;
import com.vaadin.server.CustomizedSystemMessages;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinService;
import com.vaadin.shared.ui.BorderStyle;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.spring.annotation.SpringViewDisplay;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
import com.vaadin.ui.Link;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import re.vianneyfaiv.persephone.domain.session.UserData;
import re.vianneyfaiv.persephone.exception.UIErrorHandler;

package re.vianneyfaiv.persephone.ui;




/**
 * Vaadin UI initializer
 */
@Title("Persephone")
@Theme("persephone")
@SpringUI
@SpringViewDisplay
public class PersephoneUI extends UI implements ViewDisplay {

	private Panel springViewDisplay;

	@Value("${info.persephone.version}")
	private String persephoneVersion;

	private UserData userData = new UserData();

	@Override
	protected void init(VaadinRequest request) {

		// Root layout
        final VerticalLayout root = new VerticalLayout();
        root.setSizeFull();

        root.setSpacing(false);
        root.setMargin(false);

        setContent(root);

        // Main panel
        springViewDisplay = new Panel();
        springViewDisplay.setSizeFull();

        root.addComponent(springViewDisplay);
        root.setExpandRatio(springViewDisplay, 1);

        // Footer
        Layout footer = getFooter();
        root.addComponent(footer);
        root.setExpandRatio(footer, 0);

        // Error handler
		UI.getCurrent().setErrorHandler(new UIErrorHandler());