private static AtmospherePushConnection getConnectionForUI(UI ui) { PushConnection pushConnection = ui.getInternals().getPushConnection(); if (pushConnection instanceof AtmospherePushConnection) { return (AtmospherePushConnection) pushConnection; } else { return null; } }
/** * Sets the page title. The title is displayed by the browser e.g. as the * title of the browser window or tab. * <p> * To clear the page title, use an empty string. * * @param title * the page title to set, not <code>null</code> */ public void setTitle(String title) { if (title == null) { throw new IllegalArgumentException("Cannot set a null page title."); } ui.getInternals().setTitle(title); }
private void storeContinueNavigationAction(UI ui, ContinueNavigationAction currentAction) { ContinueNavigationAction previousAction = ui.getInternals() .getContinueNavigationAction(); if (previousAction != null && previousAction != currentAction) { // Any earlier action is now obsolete, so it must be defused // to prevent it from wreaking havoc if it's ever called previousAction.setReferences(null, null); } ui.getInternals().setContinueNavigationAction(currentAction); }
private boolean handleNavigationForLocation(UI ui, Location location) { if (ui.getInternals().hasLastHandledLocation()) { return !location.getPathWithQueryParameters() .equals(ui.getInternals().getLastHandledLocation() .getPathWithQueryParameters()); } return true; }
/** * Gets the state node for this UI. * * @return the state node for the UI, in practice the state tree root node */ private StateNode getNode() { return getInternals().getStateTree().getRootNode(); }
private void addDependency(Dependency dependency) { assert dependency != null; ui.getInternals().getDependencyList().add(dependency); }
private static UI findUiUsingResource(AtmosphereResource resource, Collection<UI> uIs) { for (UI ui : uIs) { PushConnection pushConnection = ui.getInternals() .getPushConnection(); if (pushConnection instanceof AtmospherePushConnection) { if (((AtmospherePushConnection) pushConnection) .getResource() == resource) { return ui; } } } return null; }
@Override public void accept(UI ui) { if (this == deferredJob) { String appId = ui.getInternals().getAppId(); int nodeId = container.getNode().getId(); String template = String.format( "<flow-component-renderer appid=\"%s\" nodeid=\"%s\"></flow-component-renderer>", appId, nodeId); templateElement.setProperty("innerHTML", template); } } }
private PushConfigurationMap getPushConfigurationMap() { return ui.getInternals().getStateTree().getRootNode() .getFeature(PushConfigurationMap.class); }
private void requestFlush(HierarchicalCommunicationController<T> update) { SerializableConsumer<ExecutionContext> flushRequest = context -> update .flush(); stateNode.runWhenAttached(ui -> ui.getInternals().getStateTree() .beforeClientResponse(stateNode, flushRequest)); }
private void requestFlushUpdatedData() { if (flushUpdatedDataRequest == null) { flushUpdatedDataRequest = context -> { flushUpdatedData(); flushUpdatedDataRequest = null; }; stateNode.runWhenAttached(ui -> ui.getInternals().getStateTree() .beforeClientResponse(stateNode, flushUpdatedDataRequest)); } }
private void requestFlush(HierarchicalUpdate update) { SerializableConsumer<ExecutionContext> flushRequest = context -> update .commit(); stateNode.runWhenAttached(ui -> ui.getInternals().getStateTree() .beforeClientResponse(stateNode, flushRequest)); }
private static Object getTemplateItem(PolymerTemplate<?> template, JsonObject argValue, Type convertedType) { StateNode node = template.getUI().get().getInternals().getStateTree() .getNodeById((int) argValue.getNumber("nodeId")); ModelType propertyType = template.getModelType(convertedType); return propertyType.modelToApplication(node); }
private void setupTemplate(Element owner, SimpleValueRendering rendering, DataKeyMapper<SOURCE> keyMapper) { owner.getNode() .runWhenAttached(ui -> ui.getInternals().getStateTree() .beforeClientResponse(owner.getNode(), context -> setupTemplateWhenAttached(owner, rendering, keyMapper))); }
/** * Runs the given action right before the next response during which this * element is attached. * * @param action * the action to run */ private void runBeforeAttachedResponse(SerializableConsumer<UI> action) { getNode().runWhenAttached( ui -> ui.getInternals().getStateTree().beforeClientResponse( getNode(), context -> action.accept(context.getUI()))); }
private void resetContent() { if (updateScheduled) { return; } updateScheduled = true; runBeforeClientResponse(ui -> { container.removeAllChildren(); getItems().forEach(this::resetContainers); int containerNodeId = createNewContainer(getChildren()); String appId = ui.getInternals().getAppId(); ui.getPage().executeJavaScript( "window.Vaadin.Flow.contextMenuConnector.generateItems($0, $1, $2)", getElement(), appId, containerNodeId); updateScheduled = false; }); }
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()))); }
private void requestFlush() { if (flushRequest == null) { flushRequest = context -> { if (!context.isClientSideInitialized()) { reset(); arrayUpdater.initialize(); } flush(); flushRequest = null; }; stateNode.runWhenAttached(ui -> ui.getInternals().getStateTree() .beforeClientResponse(stateNode, flushRequest)); } }
private void runBeforeClientResponse(Command command) { getElement().getNode() .runWhenAttached(ui -> ui.getInternals().getStateTree() .beforeClientResponse(getElement().getNode(), context -> command.execute())); }
@Override public Rendering<SOURCE> render(Element container, DataKeyMapper<SOURCE> keyMapper, Element contentTemplate) { ComponentRendering rendering = new ComponentRendering( keyMapper == null ? null : keyMapper::key); rendering.setTemplateElement(contentTemplate); container.getNode() .runWhenAttached(ui -> ui.getInternals().getStateTree() .beforeClientResponse(container.getNode(), context -> setupTemplateWhenAttached( context.getUI(), container, rendering, keyMapper))); return rendering; }