I have a window with a toolbar containing a button:
When I click the button, an action that is registered in the layer is invoked. That's great, means that I can integrate my standard Swing components with the NetBeans System FileSystem. Plus that lets me empower the action declaratively with, for example, asynchronous processing by adding a single attribute to the related layer entry (see elsewhere in this blog for this 6.8 enhancement).
How is all this possible?
Well, this is how the action is registered in the layer:
<folder name="Actions">
<folder name="Bla">
<file name="org-demo-globloc-GlobLocAction.instance">
<attr name="delegate" newvalue="org.demo.globloc.GlobLocAction"/>
<attr name="displayName" bundlevalue="org.demo.globloc.Bundle#CTL_GlobLocAction"/>
<attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
<attr name="noIconInMenu" boolvalue="false"/>
</file>
</folder>
</folder>
<folder name="Menu">
<folder name="File">
<file name="org-demo-globloc-GlobLocAction.shadow">
<attr name="originalFile" stringvalue="Actions/Bla/org-demo-globloc-GlobLocAction.instance"/>
<attr name="position" intvalue="0"/>
</file>
</folder>
</folder>
Take note of the bits in bold above. Now, this is in the button's action performed:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
ActionListener al = Lookups.forPath("/Actions/Bla/").lookup(ActionListener.class);
al.actionPerformed(evt);
}
Here the scenario is very simple, since we know exactly where the action listener is registered and that there is only one file registered in the folder.
More complex scenarios, where you have separators as well as other actions registered in the same folder, require you to do some testing of the instances. See Layer-Based Popup Menus in TopComponents and the other references you find there for further details, if needed.
Also see this discussion from today, which includes code from Fabrizio.
In other news. What's the deal with OSGi and the NetBeans Platform? Watch this brand new screencast for all the details.