/** * Navigates forward. This has the same effect as if the user would press * the forward button in the browser. This causes a * {@link HistoryStateChangeEvent} to be fired asynchronously if the * conditions described in the <a href= * "https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate"> * onpopstate documentation</a> are met. */ public void forward() { ui.getPage().executeJavaScript("history.forward()"); }
private Locale findLocale() { Locale locale = null; if (UI.getCurrent() != null) { locale = UI.getCurrent().getLocale(); } if (locale == null) { locale = Locale.getDefault(); } return locale; }
/** * 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) { checkHasLock(); 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"; ui.getInternals().setSession(null); uIs.remove(ui.getUIId()); }
BeanStore getBeanStore(UI ui) { BeanStore beanStore = uiStores.get(ui.getUIId()); if (beanStore == null) { beanStore = new BeanStore(session); uiStores.put(ui.getUIId(), beanStore); ui.addDetachListener(this); } return beanStore; }
@Override protected ContextualStorage newContextualStorage(Integer uiId) { UI.getCurrent().addDetachListener(this::destroy); return super.newContextualStorage(uiId); }
private UI getCurrentUI() { UI ui = UI.getCurrent(); if (ui == null) { throw new IllegalStateException("UI instance is not available. " + "It means that you are calling this method " + "out of a normal workflow where it's always implicitly set. " + "That may happen if you call the method from the custom thread without " + "'UI::access' or from tests without proper initialization."); } return ui; } }
@Override protected void onAttach(AttachEvent attachEvent) { getElement().getNode().runWhenAttached(ui -> ui.beforeClientResponse( this, context -> ui.getPage().executeJavaScript( "$0.addEventListener('items-changed', " + "function(){ this.$server.updateSelectedTab(true); });", getElement()))); }
public ContextualStorage getContextualStorage(boolean createIfNotExist) { final Integer uiId = UI.getCurrent().getUIId(); return super.getContextualStorage(uiId, createIfNotExist); }
private void queueBeforeExecutionCallback() { if (lifecycleOwner == null || !lifecycleOwner.getUI().isPresent()) { return; } if (executionRegistration != null) { executionRegistration.remove(); } executionRegistration = lifecycleOwner.getUI().get() .beforeClientResponse(lifecycleOwner, beforeClientResponseConsumer); }
ui -> ui.beforeClientResponse(this, context -> ui.getPage() .executeJavaScript("$0.listenOn=$1", this, target))); ui -> ui.beforeClientResponse(target, context -> { ui.getInternals() .addComponentDependencies(ContextMenuBase.class); ui.getPage().executeJavaScript( "window.Vaadin.Flow.contextMenuConnector.init($0)", target.getElement());
/** * Opens or closes the notification. * <p> * Note: You don't need to add the component anywhere before opening it. * Since {@code <vaadin-notification>}'s location in the DOM doesn't really * matter, opening a notification will automatically add it to the * {@code <body>} if it's not yet attached anywhere. * * @param opened * {@code true} to open the notification, {@code false} to close * it */ @Override public void setOpened(boolean opened) { UI ui = UI.getCurrent(); if (ui == null) { throw new IllegalStateException("UI instance is not available. " + "It means that you are calling this method " + "out of a normal workflow where it's always implicitely set. " + "That may happen if you call the method from the custom thread without " + "'UI::access' or from tests without proper initialization."); } if (opened && getElement().getNode().getParent() == null) { ui.beforeClientResponse(ui, context -> { ui.add(this); autoAddedToTheUi = true; }); } super.setOpened(opened); }
private static void execJS(Component component, String js) { StateNode node = component.getElement().getNode(); node.runWhenAttached(ui -> ui.getInternals().getStateTree() .beforeClientResponse(node, context -> ui.getPage() .executeJavaScript(js, component.getElement()))); }
public String getRoute() { if (className != null) { return UI.getCurrent().getRouter().getUrl(className); } else if (view != null) { return UI.getCurrent().getRouter().getUrl(view.getClass()); } else { return getCaption(); } }
private static AtmospherePushConnection getConnectionForUI(UI ui) { PushConnection pushConnection = ui.getInternals().getPushConnection(); if (pushConnection instanceof AtmospherePushConnection) { return (AtmospherePushConnection) pushConnection; } else { return null; } }
private void destroy(DetachEvent event) { final int uiId = event.getUI().getUIId(); super.destroy(uiId); } }
private void ensureAttached() { if (getElement().getNode().getParent() == null) { UI ui = getCurrentUI(); ui.beforeClientResponse(ui, context -> { ui.add(this); autoAddedToTheUi = true; }); } } }
JsonObject response = Json.createObject(); UIInternals uiInternals = ui.getInternals(); VaadinSession session = ui.getSession(); VaadinService service = session.getService(); nextClientToServerMessageId); SystemMessages messages = ui.getSession().getService() .getSystemMessages(ui.getLocale(), null); encodeExecuteJavaScriptList(executeJavaScriptList)); if (ui.getSession().getService().getDeploymentConfiguration() .isRequestTiming()) { response.put("timings", createPerformanceData(ui));
/** * Closes those UIs in the given session for which {@link #isUIActive} * yields false. */ private void closeInactiveUIs(VaadinSession session) { final String sessionId = session.getSession().getId(); for (final UI ui : session.getUIs()) { if (!isUIActive(ui) && !ui.isClosing()) { ui.accessSynchronously(() -> { getLogger().debug("Closing inactive UI #{} in session {}", ui.getUIId(), sessionId); ui.close(); }); } } }
/** * Removes those UIs from the given session for which {@link UI#isClosing() * isClosing} yields true. * * @param session */ private void removeClosedUIs(final VaadinSession session) { List<UI> uis = new ArrayList<>(session.getUIs()); for (final UI ui : uis) { if (ui.isClosing()) { ui.accessSynchronously(() -> { getLogger().debug("Removing closed UI {}", ui.getUIId()); session.removeUI(ui); }); } } }
@Override public void run() { // We can acquire the lock after the request started this thread is processed // Needed to make sure that this is sent as a push message Lock lockInstance = ui.getSession().getLockInstance(); lockInstance.lock(); lockInstance.unlock(); ui.access(() -> execute(ui)); }