/** * Adds an initialized UI to this session. * * @param ui * the initialized UI to add. */ public void addUI(UI ui) { assert hasLock(); if (ui.getUIId() == -1) { throw new IllegalArgumentException( "Can not add an UI that has not been initialized."); } if (ui.getSession() != this) { throw new IllegalArgumentException( "The UI belongs to a different session"); } Integer uiId = Integer.valueOf(ui.getUIId()); uIs.put(uiId, ui); String embedId = ui.getEmbedId(); if (embedId != null) { Integer previousUiId = embedIdMap.put(embedId, uiId); if (previousUiId != null) { UI previousUi = uIs.get(previousUiId); assert previousUi != null && embedId.equals(previousUi .getEmbedId()) : "UI id map and embed id map not in sync"; // Will fire cleanup events at the end of the request handling. previousUi.close(); } } }
/** * Called by the framework to remove an UI instance from the session because * it has been closed. * * @param ui * the UI to remove */ public void removeUI(UI ui) { assert hasLock() : "Session is locked"; assert UI.getCurrent() != null : "Current UI cannot be null"; assert ui != null : "Removed UI cannot be null"; assert UI.getCurrent().getUIId() == ui.getUIId() : "UIs don't match"; Integer id = Integer.valueOf(ui.getUIId()); ui.setSession(null); uIs.remove(id); String embedId = ui.getEmbedId(); if (embedId != null && id.equals(embedIdMap.get(embedId))) { embedIdMap.remove(embedId); } }
UiContextReferenceImpl(UI ui) { this.uiId = String.format("%s:%d", ui.getEmbedId(), ui.getUIId()); }
public StubVaadinSession(EventBus eventBus) { this.eventBus = eventBus; final VaadinServlet vaadinServlet = mock(VaadinServlet.class); final ServletConfig servletConfig = mock(ServletConfig.class); this.context = mock(ServletContext.class); doReturn(context).when(servletConfig).getServletContext(); doReturn(servletConfig).when(vaadinServlet).getServletConfig(); doReturn(context).when(vaadinServlet).getServletContext(); this.ui = mock(UI.class); doReturn("foo").when(ui).getEmbedId(); this.vaadinService = mock(VaadinServletService.class); doReturn(vaadinServlet).when(vaadinService).getServlet(); this.vaadinSession = new VaadinSession(vaadinService) { @Override public boolean hasLock() { return true; } }; this.vaadinSession.setAttribute(UI.class, this.ui); this.sessionStore = new SessionStore(vaadinSession, eventBus); this.vaadinSession.setAttribute(SessionStore.class, sessionStore); }
private void setUpUISession() { final VaadinServlet vaadinServlet = mock(VaadinServlet.class); UI ui = mock(UI.class); doReturn("foo").when(ui).getEmbedId(); VaadinServletService vaadinService = mock(VaadinServletService.class); doReturn(vaadinServlet).when(vaadinService).getServlet(); VaadinSession vaadinSession = new VaadinSession(vaadinService) { @Override public boolean hasLock() { return true; } }; vaadinSession.setAttribute(UI.class, ui); SessionStore sessionStore = new SessionStore(vaadinSession, eventBus); vaadinSession.setAttribute(SessionStore.class, sessionStore); UI.setCurrent(ui); VaadinSession.setCurrent(vaadinSession); VaadinService.setCurrent(vaadinService); sessionStore.createBeanStore(UiContextReference.ofCurrentUi()); sessionStore.getBeanStore(UiContextReference.ofCurrentUi()).put(Key.get(AdmincentralFlavour.class), AdmincentralFlavour.ofM5); }