mbien commented on code in PR #9776:
URL: https://github.com/apache/netbeans/pull/9776#discussion_r4498300748


##########
ide/projectui/src/org/netbeans/modules/project/ui/actions/LookupSensitiveAction.java:
##########
@@ -176,17 +180,34 @@ private void doRefresh(boolean immediate) {
         needsRefresh = false;
     }
 
-    // Abstract methods 
--------------------------------------------------------
-
     /** Called when the action is performed
      */
     protected abstract void actionPerformed( Lookup context );
 
-    /** Place where to change properties (enablement/name) when
-     *  the set of current projects changes.
+    /** 
+     * Place where to change properties (enablement/name) when
+     * the set of current projects changes.
      */
     protected abstract void refresh(Lookup context, boolean immediate);
 
+    /**
+     * Schedules a debounced refresh. Override (without calling super) to use 
custom scheduling.
+     */
+    protected void scheduleRefresh(Lookup context) {

Review Comment:
   I probably wouldn't touch RP API anymore but maybe implement something 
parallel to it. (although I do have a branch locally which essentially rewrites 
RP to be backed by virtual threads - but the debugger doesn't support VTs very 
well so it can't really debug itself atm).
   
   For short running tasks (like here) I would use VTs directly without using 
NB API. This is from another project:
   
   ```java
       <T> void submit(Object key, Duration delay, Supplier<T> compute, 
Consumer<T> apply) {
           long gen = generations.merge(key, 1L, Long::sum);
   
           ScheduledFuture<?> timer = scheduler.schedule(() -> {
               CompletableFuture
                       .supplyAsync(compute, vtExec)
                       .thenAcceptAsync(result -> {
                           if (generations.get(key) == gen) {
                               apply.accept(result);
                           }
                       }, edtExec);
           }, delay.toMillis(), TimeUnit.MILLISECONDS);
   
           Pending old = pending.put(key, new Pending(timer, gen));
           if (old != null) old.timer().cancel(false);
       }
       private final Map<Object, Long> generations = new ConcurrentHashMap<>();
       private final ExecutorService vtExec = 
Executors.newVirtualThreadPerTaskExecutor();
   // class itself is AutoCloseable etc
   ```
   
   usage becomes:
   
   ```java
   UiUpdater updater = new UiUpdater(SwingUtilities::invokeLater);
   
   updater.submit(MyAction.KEY, Duration.ofMillis(100),
           () -> buildHeavyModel(context),
           model -> panel.render(model));  
   ```
   
   
   but this is beyond the scope of this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to