@Override public String getTheme(UICreateEvent event) { // get theme from cookies before app ui initialized for smooth theme enabling WebConfig webConfig = configuration.getConfig(WebConfig.class); GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class); String appWindowTheme = webConfig.getAppWindowTheme(); String userAppTheme = getCookieValue(event.getRequest().getCookies(), App.APP_THEME_COOKIE_PREFIX + globalConfig.getWebContextName()); if (userAppTheme != null) { if (!Objects.equals(userAppTheme, appWindowTheme)) { // check theme support ThemeConstantsRepository themeRepository = AppBeans.get(ThemeConstantsRepository.NAME); Set<String> supportedThemes = themeRepository.getAvailableThemes(); if (supportedThemes.contains(userAppTheme)) { return userAppTheme; } } } return super.getTheme(event); }
@Test public void testCreateUIInstance() throws Exception { // expect constructing new UI instance PageletAwareUI ui = createMockAndExpectNew(PageletAwareUI.class, pageletTrackerMock); UICreateEvent event = createMock(UICreateEvent.class); UI uiInstance = null; replayAll(); try { uiInstance = provider.createInstance(event); } finally { verifyAll(); assertEquals(ui, uiInstance); } }
/** * Create a Vaadin UI using given UI class * @param <T> UI type * @param uiClass UI class to create * @param location Page location * @return UI instance */ @SuppressWarnings("unchecked") protected <T extends UI> T createUi(Class<T> uiClass, String location) { UICreateEvent evt = buildUiCreateEvent(uiClass, location); T ui = (T) uiProvider.createInstance(evt); CurrentInstance.set(UI.class, ui); ui.doInit(evt.getRequest(), TEST_UIID, null); return ui; }
@Override public UI createInstance(UICreateEvent event) { MainUI ui = this.mainUIFactory.getService(); ui.addComponentDetachListener(x -> this.mainUIFactory.ungetService(ui)); return ui; }
@Override public PushMode getPushMode(UICreateEvent event) { WebConfig webConfig = configuration.getConfig(WebConfig.class); if (!webConfig.getPushEnabled()) { return PushMode.DISABLED; } return super.getPushMode(event); }
@Override public Transport getPushTransport(UICreateEvent event) { WebConfig webConfig = configuration.getConfig(WebConfig.class); if (webConfig.getUsePushLongPolling()) { return Transport.LONG_POLLING; } return super.getPushTransport(event); }
@Override public UI createInstance(UICreateEvent event) { final Class<UIID> key = UIID.class; final UIID identifier = new UIID(event); CurrentInstance.set(key, identifier); try { Class<? extends UI> uiClass = event.getUIClass(); logger.debug("Creating a new UI bean of class [{}] with identifier [{}]", uiClass.getCanonicalName(), identifier); return applicationContext.getBean(uiClass); } finally { CurrentInstance.set(key, null); } }
@Override public UI createInstance(UICreateEvent event) { BaseVaadinUI ui = new BaseVaadinUI(); Dictionary<String, Object> props = new Hashtable<>(); props.put("instance.object", ui); try { factory.createComponentInstance(props); } catch (UnacceptableConfiguration | MissingHandlerException | ConfigurationException e) { e.printStackTrace(); } return ui; }
@Override public UI createInstance(UICreateEvent event) { ApplicationContext ctx = VaadinUtils.getApplicationContext(); CurrentInstance.set(UIid.class, new UIid(event.getUiId())); UI ui = this.uiMapping.getUi(event.getRequest()); if (ui == null) ui = ctx.getBean(event.getUIClass()); CurrentInstance.set(UIid.class, null); return ui; }
@Override public UI createInstance(UICreateEvent event) { //return super.createInstance(event); return vaadinProvider.getUI(); }
@Override public UI createInstance(UICreateEvent event) { return AppBeans.getPrototype(AppUI.NAME); }
@Override public UI createInstance(UICreateEvent event) { return IngestServletContextListener.injector().getProvider(uiClass).get(); }
@Override public UI createInstance(UICreateEvent event) { return new PageletAwareUI(pageletTracker); }
@Override public void modifyBootstrapPage(BootstrapPageResponse response) { Document document = response.getDocument(); // Add the widgetsetUrl parameter to the bootstrap parameters. // This is overridden to avoid adding the naive random query // parameter (used by core to avoid caching of js file). final VaadinService service = response.getSession().getService(); final VaadinRequest request = response.getRequest(); final String staticFilePath = service .getStaticFileLocation(request); // VAADIN folder location final String vaadinDir = staticFilePath + "/VAADIN/"; // Figure out widgetset final UICreateEvent event = new UICreateEvent(request, response.getUiClass()); String widgetset = response.getUIProvider().getWidgetset(event); if (widgetset == null) { widgetset = request.getService() .getConfiguredWidgetset(request); } // Url for the widgetset final String widgetsetUrl = String.format( "%swidgetsets/%s/%s.nocache.js", vaadinDir, widgetset, widgetset); // Update the bootstrap page Element scriptTag = document.getElementsByTag("script").last(); String script = scriptTag.html(); scriptTag.html(""); script = script.replace("});", ",\"widgetsetUrl\":\"" + widgetsetUrl + "\",\"offlineEnabled\":" + isOfflineModeEnabled() + "});"); scriptTag.appendChild(new DataNode(script, scriptTag.baseUri())); if (isCacheManifestEnabled()) { // Add cache manifest attribute to html tag document.getElementsByTag("html").attr( "manifest", vaadinDir + "widgetsets/" + widgetset + "/" + generateManifestFileName(response)); } }
/** * Build the UICreateEvent to pass to UIProvider * @param uiClass UI class * @param location Optional Page location * @return UICreateEvent */ protected UICreateEvent buildUiCreateEvent(Class<? extends UI> uiClass, String location) { VaadinServletRequest request = (location != null) ? buildVaadinRequest(location) : buildVaadinRequest(); CurrentInstance.set(VaadinRequest.class, request); CurrentInstance.set(VaadinSession.class, vaadinSession); return new UICreateEvent(request, uiClass, TEST_UIID); }