Thursday Sep 20, 2012

Ordering of NetBeans Platform Menu/Toolbar Positions

Since there's no annotation for setting the position of a menu/toolbar (but only for items within them), here's a quick and easy way to do it by combining a layer file with the standard annorations:

<folder name="Menu">
    <folder name="Analyzers">
        <attr intvalue="300" name="position"/>
    </folder>
</folder>

And now that the menu position is set, you can use the annotations exactly as before:

@ActionID(
    category = "Tools",
id = "de.damaico.connection.analyzer.AnalyzeConnectionsActionListener")
@ActionRegistration(
    iconBase = "de/damaico/connection/analyzer/customer.png",
displayName = "#CTL_AnalyzeConnectionsActionListener")
@ActionReferences({
    @ActionReference(path = "Menu/Analyzers", position = 0),
    @ActionReference(path = "Toolbars/Analyzers", position = 300)
})
@Messages("CTL_AnalyzeConnectionsActionListener=Analyze Connections")
public final class AnalyzeConnectionsActionListener implements ActionListener {

I.e., thanks to this tip (from Benno Markiewicz from Leipzig), you get the best of both worlds.

There's also a related patch in Issuezilla by Ernest Lotter. The patch creates a new annotation for registering menu positions:

http://netbeans.org/bugzilla/show_bug.cgi?id=203556

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« September 2012 »
SunMonTueWedThuFriSat
      
2
16
19
      
Today