return access(command, null);
/** * Wraps the given access task as a runnable that runs the given task with * this UI locked. The wrapped task may be run synchronously or * asynchronously. If the UI is detached when the returned runnable 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 runnable that will run either the access task or the detach * handler, possibly asynchronously */ public SerializableRunnable accessLater(SerializableRunnable accessTask, SerializableRunnable detachHandler) { Objects.requireNonNull(accessTask, "Access task cannot be null"); return () -> access(accessTask::run, detachHandler); }
public void refreshNotifications(NotificationHolder notificationHolder) { getUI().ifPresent(ui -> ui.access(() -> { notificationsView.initView(); //setContent(new NotificationsView(notificationHolder)); })); }
/** * 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); }
@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)); }
private void reloadNotifications() { if (currentThread != null && !currentThread.isInterrupted()) { currentThread.interrupt(); } badgeHolder.clearCount(); notificationHolder.clearNotifications(); currentThread = new Thread(() -> { try { Thread.sleep(1000); for (int i = 0; i < 3; i++) { getUI().ifPresent(ui -> ui.access(() -> { addNotification(MEDIUM); badgeHolder.increase(); badgeHolder.increase(); })); } } catch (InterruptedException e) { e.printStackTrace(); } }); currentThread.start(); }
public void reloadNotifications() { if (currentThread != null && !currentThread.isInterrupted()) { currentThread.interrupt(); } badgeHolder.clearCount(); notificationHolder.clearNotifications(); currentThread = new Thread(() -> { try { Thread.sleep(1000); for (int i = 0; i < 3; i++) { //Thread.sleep(5000); getUI().ifPresent(ui -> ui.access(() -> { addNotification(MEDIUM); badgeHolder.increase(); badgeHolder.increase(); })); } } catch (InterruptedException e) { e.printStackTrace(); } }); currentThread.start(); }
@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(() -> { Paragraph world = new Paragraph("World"); world.setId("world"); add(world); }); } }
holder.addClickListener(newStatus -> getUI().ifPresent(ui -> ui.access(AppBarNotificationButton.this::close))); holder.bind(((IconBadgeButton) getTriggerComponent()).getBadge());