/** * Updates a UI that has already been initialized but is now loaded again, * e.g. because of {@link PreserveOnRefresh}. * * @param ui * @param request */ private void reinitUI(UI ui, VaadinRequest request) { UI.setCurrent(ui); ui.doRefresh(request); }
/** * Hack used to return existing LegacyWindow instances without regard for * out-of-sync problems. * * @param event * @return */ public UI getExistingUI(UIClassSelectionEvent event) { UI uiInstance = getUIInstance(event); if (uiInstance == null || uiInstance.getUIId() == -1) { // Not initialized -> Let go through createUIInstance to make it // initialized return null; } else { UI.setCurrent(uiInstance); return uiInstance; } }
/** * Sets the main window of this application. Setting window as a main window * of this application also adds the window to this application. * * @param mainWindow * the UI to set as the default window */ public void setMainWindow(LegacyWindow mainWindow) { if (this.mainWindow != null) { throw new IllegalStateException("mainWindow has already been set"); } if (mainWindow.isAttached()) { throw new IllegalStateException( "mainWindow is attached to another application"); } if (UI.getCurrent() == null) { // Assume setting a main window from Application.init if there's // no current UI -> set the main window as the current UI UI.setCurrent(mainWindow); } addWindow(mainWindow); this.mainWindow = mainWindow; }
/** * Finds the {@link UI} that belongs to the provided request. This is * generally only supported for UIDL requests as other request types are not * related to any particular UI or have the UI information encoded in a * non-standard way. The returned UI is also set as the current UI ( * {@link UI#setCurrent(UI)}). * * @param request * the request for which a UI is desired * @return the UI belonging to the request or null if no UI is found * */ public UI findUI(VaadinRequest request) { // getForSession asserts that the lock is held VaadinSession session = loadSession(request.getWrappedSession()); // Get UI id from the request String uiIdString = request.getParameter(UIConstants.UI_ID_PARAMETER); UI ui = null; if (uiIdString != null && session != null) { int uiId = Integer.parseInt(uiIdString); ui = session.getUIById(uiId); } UI.setCurrent(ui); return ui; }
try { UI uI = session.getUIById(Integer.parseInt(uiId)); UI.setCurrent(uI);
@Override public void run() { UI.setCurrent(current); eventBus.publish(this, CustomFilterUIEvent.FILTER_TARGET_BY_QUERY); } }
@Override public void run() { UI.setCurrent(current); eventBus.publish(this, CustomFilterUIEvent.FILTER_TARGET_BY_QUERY); } }
@Override public void tearDown() { UI.setCurrent(null); }
private void initializeVaadinUI(final URI returnURI) { UI.setCurrent(new UI() { @Override protected void init(VaadinRequest request) { } @Override public Locale getLocale() { return Locale.ENGLISH; } @Override public Page getPage() { Page page = mock(Page.class); doReturn(returnURI).when(page).getLocation(); return page; } }); }
public final void setScopeKey(int index) { UI.setCurrent(null); // overcomes the inheritable check in CurrentInstance.set //flush last test if there was one UIScope oldScope = UIScope.getCurrent(); if (oldScope != null) { oldScope.flush(); } UIKey uiKey = new UIKey(index); BasicUI ui = mock(BasicUI.class); when(ui.getInstanceKey()).thenReturn(uiKey); UI.setCurrent(ui); CurrentInstance.set(UIKey.class, uiKey); getUiScope().startScope(uiKey); } }
public final void setScopeKey(int index) { UI.setCurrent(null); // overcomes the inheritable check in CurrentInstance.set //flush last test if there was one UIScope oldScope = UIScope.getCurrent(); if (oldScope != null) { oldScope.flush(); } UIKey uiKey = new UIKey(UUID.randomUUID()); BasicUI ui = mock(BasicUI.class); when(ui.getInstanceKey()).thenReturn(uiKey); UI.setCurrent(ui); CurrentInstance.set(UIKey.class, uiKey); getUiScope().startScope(uiKey); } }
@Override public void run() { try { UI.setCurrent(vaadinUi); streamToRepository(); } catch (final RuntimeException e) { interruptUploadDueToUploadFailed(); publishUploadFailedAndFinishedEvent(fileUploadId, e); LOG.error("Failed to transfer file to repository", e); } finally { tryToCloseIOStream(inputStream); } }
@Override public void run() { try { UI.setCurrent(vaadinUi); streamToRepository(); } catch (final RuntimeException e) { publishUploadFailedEvent(fileUploadId, i18n.getMessage("message.upload.failed"), e); LOG.error("Failed to transfer file to repository", e); } finally { tryToCloseIOStream(inputStream); } }
@After public void tearDown() { UI.setCurrent(null); }
private void setUIScope(UUID index) { UI.setCurrent(null); // overcomes the inheritable check in CurrentInstance.set //flush last test if there was one UIScope oldScope = UIScope.getCurrent(); if (oldScope != null) { oldScope.flush(); } UIKey uiKey = new UIKey(index); BasicUI ui = mock(BasicUI.class); when(ui.getInstanceKey()).thenReturn(uiKey); UI.setCurrent(ui); CurrentInstance.set(UIKey.class, uiKey); }
@Override protected void before() { VaadinService.setCurrent(this.vaadinService); VaadinSession.setCurrent(this.vaadinSession); UI.setCurrent(this.ui); }
protected UI createAndInitUI(Class<? extends UI> uiClass, VaadinRequest request, VaadinSession session) { Integer uiId = Integer.valueOf(session.getNextUIid()); UI ui = ReflectTools.createInstance(uiClass); // Initialize some fields for a newly created UI ui.getInternals().setSession(session); PushMode pushMode = AnnotationReader.getPushMode(uiClass).orElseGet( session.getService().getDeploymentConfiguration()::getPushMode); ui.getPushConfiguration().setPushMode(pushMode); AnnotationReader.getPushTransport(uiClass) .ifPresent(ui.getPushConfiguration()::setTransport); // Set thread local here so it is available in init UI.setCurrent(ui); ui.doInit(request, uiId.intValue()); session.addUI(ui); return ui; }
@After public void tearDown() throws Exception { ComponentsTestUtil.clear(); MgnlContext.setInstance(null); UI.setCurrent(null); }
@Override public void setUp() throws Exception { super.setUp(); MockContext ctx = (MockContext) MgnlContext.getInstance(); user = mock(User.class); ctx.setUser(user); ctx.setLocale(Locale.FRANCE); DateFieldDefinition definition = dateFieldDefinition("startDate"); nodeAdapter = new JcrNewNodeAdapter(session.getRootNode(), ContentNode.NAME, "event"); SimpleTranslator i18n = mock(SimpleTranslator.class); factory = new DateFieldFactory(definition, nodeAdapter, uiContext, i18nAuthoringSupport, i18n, ctx); factory.setComponentProvider(componentProvider); UI ui = mock(UI.class); Page page = mock(Page.class); browserInfo = mock(WebBrowser.class); when(page.getWebBrowser()).thenReturn(browserInfo); when(ui.getPage()).thenReturn(page); UI.setCurrent(ui); }