@@ -629,9 +629,69 @@ public void handleError(Exception exception) {
629
629
* <code>null</code> as described above
630
630
* @return a runnable that will run either the access task or the detach
631
631
* handler, possibly asynchronously
632
+ * @deprecated Use
633
+ * {@link #wrapWithAccess(SerializableRunnable, SerializableRunnable)}
634
+ * instead which is a better name for the method
635
+ *
632
636
*/
637
+ @ Deprecated (forRemoval = true )
633
638
public SerializableRunnable accessLater (SerializableRunnable accessTask ,
634
639
SerializableRunnable detachHandler ) {
640
+ return wrapWithAccess (accessTask , detachHandler );
641
+ }
642
+
643
+ /**
644
+ * Wraps the given access task as a consumer that passes a value to the
645
+ * given task with this UI locked. The wrapped task may be run synchronously
646
+ * or asynchronously. If the UI is detached when the returned consumer is
647
+ * run, the provided detach handler is run instead. If the provided detach
648
+ * handler is <code>null</code>, the returned runnable may throw an
649
+ * {@link UIDetachedException}.
650
+ * <p>
651
+ * This method can be used to create a callback that can be passed to an
652
+ * external notifier that isn't aware of the synchronization needed to
653
+ * update a UI instance.
654
+ *
655
+ * @param accessTask
656
+ * the task that updates this UI, not <code>null</code>
657
+ * @param detachHandler
658
+ * the callback that will be invoked if the UI is detached, or
659
+ * <code>null</code> as described above
660
+ * @return a consumer that will run either the access task or the detach
661
+ * handler, possibly asynchronously
662
+ * @deprecated Use
663
+ * {@link #wrapWithAccess(SerializableConsumer, SerializableRunnable)}
664
+ * instead which is a better name for the method
665
+ */
666
+ @ Deprecated (forRemoval = true )
667
+ public <T > SerializableConsumer <T > accessLater (
668
+ SerializableConsumer <T > accessTask ,
669
+ SerializableRunnable detachHandler ) {
670
+ return wrapWithAccess (accessTask , detachHandler );
671
+ }
672
+
673
+ /**
674
+ * Wraps the given access task as a runnable that runs the given task with
675
+ * this UI locked. The wrapped task may be run synchronously or
676
+ * asynchronously. If the UI is detached when the returned runnable is run,
677
+ * the provided detach handler is run instead. If the provided detach
678
+ * handler is <code>null</code>, the returned runnable may throw an
679
+ * {@link UIDetachedException}.
680
+ * <p>
681
+ * This method can be used to create a callback that can be passed to an
682
+ * external notifier that isn't aware of the synchronization needed to
683
+ * update a UI instance.
684
+ *
685
+ * @param accessTask
686
+ * the task that updates this UI, not <code>null</code>
687
+ * @param detachHandler
688
+ * the callback that will be invoked if the UI is detached, or
689
+ * <code>null</code> as described above
690
+ * @return a runnable that will run either the access task or the detach
691
+ * handler, possibly asynchronously
692
+ */
693
+ public SerializableRunnable wrapWithAccess (SerializableRunnable accessTask ,
694
+ SerializableRunnable detachHandler ) {
635
695
Objects .requireNonNull (accessTask , "Access task cannot be null" );
636
696
637
697
return () -> access (accessTask ::run , detachHandler );
@@ -657,7 +717,7 @@ public SerializableRunnable accessLater(SerializableRunnable accessTask,
657
717
* @return a consumer that will run either the access task or the detach
658
718
* handler, possibly asynchronously
659
719
*/
660
- public <T > SerializableConsumer <T > accessLater (
720
+ public <T > SerializableConsumer <T > wrapWithAccess (
661
721
SerializableConsumer <T > accessTask ,
662
722
SerializableRunnable detachHandler ) {
663
723
Objects .requireNonNull (accessTask , "Access task cannot be null" );
0 commit comments