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


##########
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) {
+        if (sync) {
+            refresh(context, false);
+        } else {
+            needsRefresh = true;
+            pendingContext = context;
+            pendingRefresh.schedule(100);
+        }
+    }
+
+    /** For testing: makes {@link #scheduleRefresh} run synchronously. */
+    void setSynchronousRefresh(boolean sync) {

Review Comment:
   It is unfortunate the testing code tests something different than the 
production....



##########
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:
   We are coding against JDK21 APIs. For a while I am thinking:
   - can we use 
[CompletionStage](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/concurrent/CompletionStage.html)
 somehow?
      - or maybe `CompletableFuture`?
   - would it help to have `RequestProcessor.Task.toStage()` returning the 
current stage refreshed with every `schedule`?
   
   Maybe the tests could then run in asynchronous mode and just ask for 
`CompletionStage` when they need to wait for pending action to finish.



##########
ide/projectui/test/unit/src/org/netbeans/modules/project/ui/actions/LookupSensitiveActionBase.java:
##########
@@ -113,6 +113,7 @@ private void doTestRefreshAfterBeingHidden(boolean clone, 
boolean menu) throws I
         } else {
             instance = create(context);
         }
+        ((LookupSensitiveAction) instance).setSynchronousRefresh(true);

Review Comment:
   I guess the alternative would be to insert various `waitFinished` calls into 
the test to make sure all pending updates are processed.



-- 
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