Re: Utilities.actionsForPath() question
Michael Bien <[email protected]> Tue, 7 Oct 2025 17:41:56 +0200
| Newsgroups | gmane.comp.java.ide.netbeans.user |
|---|---|
| Message-ID | <[email protected]> |
On 10/4/25 14:28, Jerome Lelasseux wrote:
> I'll try to update some NB docs regarding actions, because the overall thing is (too IMHO) complex...
thanks for updating the online doc btw! Some of it might be a but dusty by now.
(replied inline on your PR)
-mbien
> Jerome
>
>
> On 2025/10/03 19:31:02 Jerome Lelasseux wrote:
> Still trying to use NB annotations to declare a singleton action class, this is driving me nuts... I did some tests. Calling Actions.forID(x, y) twice in a row returns the same instance. Same for Utilities.actionsForPath(). Same in my app. BUT, if I run the second call to Actions.forID(x,y) a few seconds later in my app (I trigger it manually with the mouse) then, *sometimes* (1/3?), I get a new instance ! Same problem for Utilities.actionsForPath(). Note that both calls are done on the EDT. I looked at the NB code on github, the underlying lookup mechanism in filesystem/RecognizeInstanceFiles.java is based on ProxyLookup, which uses lazy instanciation. So I assume that sometimes something happens differently here. But can not understand why... I noticed that Actions.forID() uses FileUtil.getFileObject(). Doc says "In environment with multiple contextual Lookups, the method may return different FileObject depending on what Lookup serves the executing thread." And
> recommends to use FileUtil.getSystemFileObject() to make sure to get a single instance. What is a "contextual lookup" here ? I guess I have to try recoding forID() with getSystemFileObject... Jerome On 2025/10/02 21:17:20 Jerome Lelasseux wrote: Hi, I have an action with a no-arg constructor : @ActionID(category = "jjazz", id = "myactionid") @ActionRegistration(displayName = "not_used", lazy = false) @ActionReference(path = "Actions/popupmenu", position = 100)public class MyAction extends AbstractAction........ In my code an instance is first created using Actions.forId("jjazz", "myactionid") I also want to use MyAction in a popup menu. I use Utilities.actionsForPath("Actions/popupmenu") to retrieve the actions before creating the popupmenu. But actionsForPath() creates a new instance of MyAction. Why ? I'm pretty sure in other cases it reuses the initial instance. Tried to debug but it does not work inside actionsForPath() -don't know why... Any tip welcome, thanks.
> Jerome
>
---------------------------------------------------------------------
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