List of usage examples for com.vaadin.server DefaultErrorHandler DefaultErrorHandler
DefaultErrorHandler
From source file:org.jumpmind.metl.ui.init.AppUI.java
License:Open Source License
@SuppressWarnings("serial") @Override// w w w . ja v a2 s . c o m protected void init(VaadinRequest request) { WebApplicationContext ctx = getWebApplicationContext(); backgroundRefresherService = ctx.getBean(BackgroundRefresherService.class); backgroundRefresherService.init(this); UI.getCurrent().setErrorHandler(new DefaultErrorHandler() { public void error(com.vaadin.server.ErrorEvent event) { String intro = "Exception of type <b>"; String message = ""; for (Throwable t = event.getThrowable(); t != null; t = t.getCause()) { if (t.getCause() == null) { intro += t.getClass().getName() + "</b> with the following message:<br/><br/>"; message = t.getMessage(); } } ErrorWindow window = new ErrorWindow(intro, message); window.show(); Throwable ex = event.getThrowable(); if (ex != null) { log.error(ex.getMessage(), ex); } else { log.error("An unexpected error occurred"); } } }); VaadinSession.getCurrent().setConverterFactory(new DefaultConverterFactory() { private static final long serialVersionUID = 1L; @Override protected Converter<Date, ?> createDateConverter(Class<?> sourceType) { return super.createDateConverter(sourceType); } protected Converter<String, ?> createStringConverter(Class<?> sourceType) { if (Double.class.isAssignableFrom(sourceType)) { return new StringToDoubleConverter(); } else if (Float.class.isAssignableFrom(sourceType)) { return new StringToFloatConverter(); } else if (Integer.class.isAssignableFrom(sourceType)) { return new StringToIntegerConverter() { private static final long serialVersionUID = 1L; @Override protected NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; } }; } else if (Long.class.isAssignableFrom(sourceType)) { return new StringToLongConverter() { private static final long serialVersionUID = 1L; @Override protected NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; } }; } else if (BigDecimal.class.isAssignableFrom(sourceType)) { return new StringToBigDecimalConverter(); } else if (Boolean.class.isAssignableFrom(sourceType)) { return new StringToBooleanConverter(); } else if (Date.class.isAssignableFrom(sourceType)) { return new StringToDateConverter(); } else { return null; } } }); Responsive.makeResponsive(this); ApplicationContext appCtx = ctx.getBean(ApplicationContext.class); if (appCtx.getConfigurationService().isUserLoginEnabled()) { LoginDialog login = new LoginDialog(appCtx, this); UI.getCurrent().addWindow(login); } else { User user = appCtx.getConfigurationService().findUserByLoginId(DEFAULT_USER); if (user == null) { user = new User(); user.setLoginId(DEFAULT_USER); appCtx.getConfigurationService().save(user); Group group = new Group(DEFAULT_USER); user.getGroups().add(group); appCtx.getConfigurationService().save(group); for (Privilege priv : Privilege.values()) { GroupPrivilege groupPriv = new GroupPrivilege(group.getId(), priv.name()); group.getGroupPrivileges().add(groupPriv); appCtx.getConfigurationService().save(groupPriv); } UserGroup userGroup = new UserGroup(user.getId(), group.getId()); appCtx.getConfigurationService().save(userGroup); } appCtx.setUser(user); login(user); } }
From source file:org.jumpmind.vaadin.ui.common.AbstractSpringUI.java
License:Open Source License
@Override protected void init(VaadinRequest request) { setErrorHandler(new DefaultErrorHandler() { private static final long serialVersionUID = 1L; @Override/* w ww . ja v a 2 s.c om*/ public void error(com.vaadin.server.ErrorEvent event) { Throwable ex = event.getThrowable(); CommonUiUtils.notify(ex); if (ex != null) { log.error(ex.getMessage(), ex); } else { log.error("An unexpected error occurred"); } } }); VaadinSession.getCurrent().setConverterFactory(new DefaultConverterFactory() { private static final long serialVersionUID = 1L; @Override protected Converter<Date, ?> createDateConverter(Class<?> sourceType) { return super.createDateConverter(sourceType); } protected Converter<String, ?> createStringConverter(Class<?> sourceType) { if (Double.class.isAssignableFrom(sourceType)) { return new StringToDoubleConverter(); } else if (Float.class.isAssignableFrom(sourceType)) { return new StringToFloatConverter(); } else if (Integer.class.isAssignableFrom(sourceType)) { return new StringToIntegerConverter() { private static final long serialVersionUID = 1L; @Override protected NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; } }; } else if (Long.class.isAssignableFrom(sourceType)) { return new StringToLongConverter() { private static final long serialVersionUID = 1L; @Override protected NumberFormat getFormat(Locale locale) { NumberFormat format = super.getFormat(locale); format.setGroupingUsed(false); return format; } }; } else if (BigDecimal.class.isAssignableFrom(sourceType)) { return new StringToBigDecimalConverter(); } else if (Boolean.class.isAssignableFrom(sourceType)) { return new StringToBooleanConverter(); } else if (Date.class.isAssignableFrom(sourceType)) { return new StringToDateConverter(); } else { return null; } } }); Responsive.makeResponsive(this); }
From source file:org.opennms.features.topology.app.internal.TopologyUI.java
License:Open Source License
private void setupErrorHandler() { setErrorHandler(new DefaultErrorHandler() { @Override/* www .j a v a2 s. c o m*/ public void error(com.vaadin.server.ErrorEvent event) { Notification.show("An Exception Occurred: see karaf.log", Notification.Type.TRAY_NOTIFICATION); LOG.warn("An Exception Occurred: in the TopologyUI", event.getThrowable()); } }); }
From source file:org.vaadin.spring.samples.security.managed.SingleSecuredUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { getPage().setTitle("Vaadin Managed Security Demo"); // Let's register a custom error handler to make the 'access denied' messages a bit friendlier. setErrorHandler(new DefaultErrorHandler() { @Override//from w ww . ja v a 2 s . com public void error(com.vaadin.server.ErrorEvent event) { if (SecurityExceptionUtils.isAccessDeniedException(event.getThrowable())) { Notification.show("Sorry, you don't have access to do that."); } else { super.error(event); } } }); if (vaadinSecurity.isAuthenticated()) { showMainScreen(); } else { showLoginScreen(request.getParameter("goodbye") != null); } }
From source file:org.vaadin.spring.samples.security.shared.MainUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { getPage().setTitle("Vaadin Shared Security Demo"); // Let's register a custom error handler to make the 'access denied' messages a bit friendlier. setErrorHandler(new DefaultErrorHandler() { @Override/*w ww . ja va2 s.com*/ public void error(com.vaadin.server.ErrorEvent event) { if (SecurityExceptionUtils.isAccessDeniedException(event.getThrowable())) { Notification.show("Sorry, you don't have access to do that."); } else { super.error(event); } } }); HorizontalLayout layout = new HorizontalLayout(); 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(this, 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()); setContent(layout); // Call this here because the Navigator must have been configured before the Side Bar can be attached to a UI. }