@Override public void execute() { command.accept(getUI()); removeAttachListener(this); } });
private boolean applyValue(T value) { presentationUpdateInProgress = true; /* * Toggled to true by setModelValue if that method is run while * presentationUpdateInProgress is also true. */ valueSetFromPresentationUpdate = false; try { setPresentationValue.accept(value); } finally { presentationUpdateInProgress = false; } return valueSetFromPresentationUpdate; } }
private void flushUpdatedData() { if (updatedData.isEmpty()) { return; } dataUpdater.accept(updatedData.stream().map(this::generateJson) .collect(JsonUtils.asArray())); updatedData.clear(); }
@Override public void setValue(V value) { V oldValue = this.value; this.value = value; valueProcessor.accept(value); if (listenerList != null && !Objects.equals(oldValue, value)) { for (ValueChangeListener<? super ValueChangeEvent<V>> valueChangeListener : listenerList) { valueChangeListener.valueChanged( new ReadOnlyValueChangeEvent<>(this, value, oldValue)); } } }
/** * Wraps the given access task as a consumer that passes a value to the * given task with this UI locked. The wrapped task may be run synchronously * or asynchronously. If the UI is detached when the returned consumer is * run, the provided detach handler is run instead. If the provided detach * handler is <code>null</code>, the returned runnable may throw an * {@link UIDetachedException}. * <p> * This method can be used to create a callback that can be passed to an * external notifier that isn't aware of the synchronization needed to * update a UI instance. * * @param accessTask * the task that updates this UI, not <code>null</code> * @param detachHandler * the callback that will be invoked if the UI is detached, or * <code>null</code> as described above * @return a consumer that will run either the access task or the detach * handler, possibly asynchronously */ public <T> SerializableConsumer<T> accessLater( SerializableConsumer<T> accessTask, SerializableRunnable detachHandler) { Objects.requireNonNull(accessTask, "Access task cannot be null"); return value -> access(() -> accessTask.accept(value), detachHandler); }
Collection<String> parseDependencies(VaadinService service) { Set<String> dependencies = new HashSet<>(); String rooUri = SharedUtil.prefixIfRelative(root, ApplicationConstants.FRONTEND_PROTOCOL_PREFIX); SerializableConsumer<String> dependencyWalker = new SerializableConsumer<String>() { private final WebBrowser browser = FakeBrowser.getEs6(); @Override public void accept(String uri) { if (dependencies.contains(uri)) { return; } dependencies.add(uri); HtmlImportParser.parseImports(uri, path -> service.getResourceAsStream(path, browser, null), path -> service.resolveResource(path, browser), this); } }; dependencyWalker.accept(rooUri); return dependencies; } }
private void runBeforeClientResponse(SerializableConsumer<UI> command) { getElement().getNode().runWhenAttached(ui -> ui .beforeClientResponse(this, context -> command.accept(ui))); } }
/** * Runs the command when the node is attached to a UI. * <p> * If the node is already attached when this method is called, the method is * run immediately. * * @param command * the command to run immediately or when the node is attached */ public void runWhenAttached(SerializableConsumer<UI> command) { if (isAttached()) { command.accept(getUI()); } else { addAttachListener(new Command() { @Override public void execute() { command.accept(getUI()); removeAttachListener(this); } }); } }
void runBeforeClientResponse(SerializableConsumer<UI> command) { getElement().getNode().runWhenAttached(ui -> ui .beforeClientResponse(this, context -> command.accept(ui))); }
void runBeforeClientResponse(SerializableConsumer<UI> command) { getElement().getNode().runWhenAttached(ui -> ui .beforeClientResponse(this, context -> command.accept(ui))); }
void runBeforeClientResponse(SerializableConsumer<UI> command) { getElement().getNode().runWhenAttached(ui -> ui .beforeClientResponse(this, context -> command.accept(ui))); }
private void runBeforeClientResponse(SerializableConsumer<UI> command) { getElement().getNode().runWhenAttached(ui -> ui .beforeClientResponse(this, context -> command.accept(ui))); }
/** * Called internally by the framework before the response is sent to the * client. All tasks registered at * {@link #beforeClientResponse(StateNode, SerializableConsumer)} are * evaluated and executed if able. */ public void runExecutionsBeforeClientResponse() { while (true) { List<StateTree.BeforeClientResponseEntry> callbacks = flushCallbacks(); if (callbacks.isEmpty()) { return; } callbacks.forEach(entry -> { ExecutionContext context = new ExecutionContext(getUI(), entry.getStateNode().isClientSideInitialized()); entry.getExecution().accept(context); }); } }
private void attachComponentTemplate() { deferredJob = new AttachComponentTemplate(); getElement().getNode().runWhenAttached(ui -> ui .beforeClientResponse(this, context -> deferredJob.accept(ui))); } }
/** * 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()))); }
/** * Default constructor. Create an empty notification with component support * and non-auto-closing * <p> * Note: To mix text and child components in notification that also supports * child components, use the {@link Text} component for the textual parts. */ public Notification() { initBaseElementsAndListeners(); getElement().getNode().runWhenAttached(ui -> ui .beforeClientResponse(this, context -> deferredJob.accept(ui))); setPosition(DEFAULT_POSITION); setDuration(0); }