List of usage examples for com.vaadin.server VaadinService getCurrent
public static VaadinService getCurrent()
From source file:org.vaadin.highlighter.ComponentHighlighterExtension.java
License:Apache License
/** * <p>//w w w. j a v a2 s . com * The given connector will only be extended with the highlighting label, if * the application is currently being run in debug mode. This operation will * do nothing if running in production mode. More specifically, the * client-side widget of the extended connector will not be touched when * running in production mode. * </p> * <p> * The extended component will display its fully qualified class name in the * highlighting label by default. This can be adjusted with method * {@link #setComponentDebugLabel(String)}. * </p> */ @Override public void extend(AbstractClientConnector target) { if (VaadinService.getCurrent().getDeploymentConfiguration().isProductionMode()) { return; } super.extend(target); setComponentDebugLabel(target.getClass().getCanonicalName()); }
From source file:org.vaadin.spring.security.managed.DefaultVaadinManagedSecurity.java
License:Apache License
/** * Clears the session of all attributes except some internal Vaadin attributes and reinitializes it. If Websocket * Push is used, the session will never be reinitialized since this throws errors on at least * Tomcat 8.//from ww w . j av a 2 s . c om */ protected void clearAndReinitializeSession() { final VaadinRequest currentRequest = VaadinService.getCurrentRequest(); final UI currentUI = UI.getCurrent(); if (currentUI != null) { final Transport transport = currentUI.getPushConfiguration().getTransport(); if (Transport.WEBSOCKET.equals(transport) || Transport.WEBSOCKET_XHR.equals(transport)) { LOGGER.warn( "Clearing and reinitializing the session is currently not supported when using Websocket Push."); return; } } if (currentRequest != null) { LOGGER.debug("Clearing the session"); final WrappedSession session = currentRequest.getWrappedSession(); final String serviceName = VaadinService.getCurrent().getServiceName(); final Set<String> attributesToSpare = new HashSet<String>(); attributesToSpare.add(serviceName + ".lock"); attributesToSpare.add(VaadinSession.class.getName() + "." + serviceName); for (String s : currentRequest.getWrappedSession().getAttributeNames()) { if (!attributesToSpare.contains(s)) { LOGGER.trace("Removing attribute {} from session", s); session.removeAttribute(s); } } LOGGER.debug("Reinitializing the session {}", session.getId()); VaadinService.reinitializeSession(currentRequest); LOGGER.debug("Session reinitialized, new ID is {}", VaadinService.getCurrentRequest().getWrappedSession().getId()); } else { LOGGER.warn( "No VaadinRequest bound to current thread, could NOT clear/reinitialize the session after login"); } }
From source file:org.vaadin.tori.ToriApiLoader.java
License:Apache License
private ToriMailService createToriMailService(final VaadinRequest request) { ToriMailService result = null;/* w ww . j a v a 2 s. c o m*/ if (request != null) { result = spi.createToriMailService(); try { String themeName = UI.getCurrent().getTheme(); InputStream postTemplateStream = VaadinService.getCurrent() .getThemeResourceAsStream(UI.getCurrent(), "tori", "toripostmailtemplate.xhtml"); InputStream themeStream = VaadinService.getCurrent().getThemeResourceAsStream(UI.getCurrent(), themeName, "styles.css"); if (postTemplateStream != null && themeStream != null) { result.setPostMailTemplate(readStream(postTemplateStream)); String themeCss = readStream(themeStream); String imagesUrl = getToriThemeImagesURL(request); String quoteImageUrl = imagesUrl + "emailquote.png"; String anonymousImageUrl = imagesUrl + "emailanonymous.png"; String defaultHeaderImageUrl = imagesUrl + "tori-icon.png"; //@formatter:off String quoteRule = "\n\n" + ".v-app blockquote cite, .v-app .quote-title { \n" + "background-image: url('" + quoteImageUrl + "'); \n" + "background-repeat: no-repeat; \n" + "}"; String anonymousRule = "\n\n" + ".avatar.anonymous-true { \n" + "background-image: url('" + anonymousImageUrl + "'); \n" + "height: 100%; \n" + "}" + "\n\n" + ".avatar.anonymous-true img { \n" + "display: none; \n" + "}"; String customHeaderImageRule = "\n\n" + ".defaultheaderimage-true { \n" + "background-image: url('" + defaultHeaderImageUrl + "'); \n" + "background-repeat: no-repeat; \n" + "}" + "\n\n" + ".defaultheaderimage-true .headerimageplaceholder { \n" + "width: 160px; \n" + "height: 40px; \n" + "}"; //@formatter:on result.setMailTheme(themeCss + quoteRule + anonymousRule + customHeaderImageRule); getLogger().debug(String.format("Using %s implementation: %s", ToriMailService.class.getSimpleName(), result.getClass().getName())); } else { getLogger().error("Unable to set mail service resources"); result = null; } } catch (IOException e) { getLogger().warn("Exception while closing input stream", e); } catch (Exception e) { getLogger().error("Exception while initiating ToriMailService", e); result = null; } } return result; }
From source file:tad.grupo7.ccamistadeslargas.AdminIndexView.java
public AdminIndexView() { setMenuCaption("CCAmistadesLargas - ADMIN"); String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + "/WEB-INF/wallpaper2.jpg"; FileResource resource = new FileResource(new File(basepath)); Image image = new Image(null, resource); image.setSizeFull();/*from w w w . ja v a 2s. c om*/ addComponent(image); addMenuItem("Listado", FontAwesome.LIST, () -> { removeAllComponents(); addComponent(new ListadoLayout()); }); addMenuItem("Grafica", FontAwesome.PIE_CHART, () -> { removeAllComponents(); addComponent(new GraficaLayout()); }); addMenuItem("Cerrar sesin", FontAwesome.POWER_OFF, () -> { Session.destroy(); UI.getCurrent().getNavigator().navigateTo(""); }); }
From source file:tad.grupo7.ccamistadeslargas.IndexView.java
public IndexView() { setMenuCaption("CCAmistadesLargas"); String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + "/WEB-INF/wallpaper2.jpg"; FileResource resource = new FileResource(new File(basepath)); Image image = new Image(null, resource); image.setSizeFull();//from w w w .ja va2 s .c om addComponent(image); addMenuItem("Perfil", FontAwesome.USER, () -> { removeAllComponents(); addComponent(new PerfilLayout()); }); addMenuItem("Eventos", FontAwesome.COMPASS, () -> { removeAllComponents(); addComponent(new EventosLayout()); }); addMenuItem("Amigos", FontAwesome.USERS, () -> { removeAllComponents(); addComponent(new AmigosLayout()); }); addMenuItem("Cerrar sesin", FontAwesome.POWER_OFF, () -> { Session.destroy(); UI.getCurrent().getNavigator().navigateTo(""); }); }
From source file:ubu.digit.ui.components.Footer.java
License:Creative Commons License
/** * Obtiene la fecha de ltima modificacin del fichero asociado a la vista. * //from w ww . j av a 2 s . co m * @param fileName * nombre del fichero * @return fecha de ltima modificacin del fichero */ private String getLastModified(String fileName) { String serverPath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); ExternalProperties config = ExternalProperties.getInstance("/WEB-INF/classes/config.properties", false); String dirCsv = config.getSetting("dataIn"); String dir = serverPath + dirCsv + "/"; SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); String lastModified = null; File file = new File(dir + fileName); if (file.exists()) { Date date = new Date(file.lastModified()); lastModified = sdf.format(date); } return lastModified; }
From source file:uk.co.q3c.util.ResourceUtils.java
License:Apache License
/** * Returns the base directory path for the application if there VaadinService is running, or the current directory * if not (the latter case is mainly for testing) * //from w ww .j ava 2 s . com * @return */ public static String applicationBasePath() { if (VaadinService.getCurrent() != null) { return VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); } else { return new File(".").getAbsolutePath(); } }
From source file:uk.q3c.krail.util.DefaultResourceUtils.java
License:Apache License
@Override public File applicationBaseDirectory() { if (VaadinService.getCurrent() != null) { File baseDir = VaadinService.getCurrent().getBaseDirectory(); if (baseDir != null) { log.info("Application base directory (from VaadinService) is {}", baseDir.getAbsolutePath()); } else {/* w w w. j a va2 s.c o m*/ log.error("Application base directory has not been set"); } return baseDir; } throw new IllegalStateException("There is no current VaadinService"); }
From source file:uk.q3c.krail.util.DefaultResourceUtils.java
License:Apache License
@Override public File resourcePath(String fileName) { Preconditions.checkNotNull(fileName); File baseDir;//from w w w. j av a2s . c om if (VaadinService.getCurrent() != null) { baseDir = applicationBaseDirectory(); } else { baseDir = new File("src/main/resources"); } return new File(baseDir, fileName); }
From source file:uk.q3c.util.ResourceUtils.java
License:Apache License
/** * Returns the base directory path for the application if there is a VaadinService is running, or throws a {@link * IllegalStateException} if no service is running * * @return//from w w w . j a v a2s. c om */ public static File applicationBaseDirectory() { if (VaadinService.getCurrent() != null) { File baseDir = VaadinService.getCurrent().getBaseDirectory(); if (baseDir != null) { log.info("Application base directory (from VaadinService) is {}", baseDir.getAbsolutePath()); } else { log.warn("Application base directory has not been set"); } return baseDir; } throw new IllegalStateException("There is no current VaadinService"); }