Accoring to the documentation it sounds as if one can register a few implementations of org.openide.util.ContextGlobalProvider and presto - the global Lookup will end up containing the goodies they provide:
public interface ContextGlobalProviderAn interface that can be registered in a lookup by subsystems wish to provide a global context actions should react to. The global context is accessible via
Utilities.actionsGlobalContext()method and is expected to contain similar content as the context used when context aware actions (seeContextAwareAction) are being manipulated for example via methodUtilities.actionsToPopup(javax.swing.Action[], org.openide.util.Lookup), so in current state it is reasonable to put there all currently active Node, their cookies andActionMap. By default this interface is implemented by window system to delegate to currently activated TopComponent's lookup.
Right?
No. A couple of frustrating hours later, and a grep through the actual source code (I should have known better) revealed that the framework only ever looks for a single instance of this interface. And using it only makes sense in the context of controlling the UI's focus, as Tim Boudreau demonstrated.
There's no point of trying to register more than one ContextGlobalProvider, as I wanted, in order to "inject" global lookup components, via lazy instantiation. The framework uses Lookup.lookup() method to get just the first one, in some random order.
If your modules need to inject instances in the global lookup the simplest way seems to be to use Java services extension mechanism (META-INF/services).
No comments:
Post a Comment