Over a million developers have joined DZone.

Tip: How to Create Submenus on the NetBeans Platform

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

This tip shows the way I usually create an action for a NetBeans Platform application and then include it into a submenu.

  1. Create a new module, then use the Action wizard to create my DemoAction.

  2. The first panel asks for the type of Action, I leave Always Enabled selected. In the next panels, I fill the forms with all required data, as shown below:






  3. Nothing new, as you can see. And then let's tweak the layer.xml file entries that were created by the wizard shown above. This is what was generated:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE
    filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN"
    "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
    <filesystem>
    <folder name="Actions">
    <folder name="Edit">
    <file name="org-casaburo-submenuDemo-DemoAction.instance">
    <attr name="delegate" newvalue="org.casaburo.submenuDemo.DemoAction"/>
    <attr name="displayName" bundlevalue="org.casaburo.submenuDemo.Bundle#CTL_DemoAction"/>
    <attr name="iconBase" stringvalue="org/casaburo/submenuDemo/add.png"/>
    <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
    <attr name="noIconInMenu" boolvalue="false"/>
    </file>
    </folder>
    </folder>
    <folder name="Menu">
    <folder name="Edit">
    <file name="org-casaburo-submenuDemo-DemoAction.shadow">
    <attr name="originalFile" stringvalue="Actions/Edit/org-casaburo-submenuDemo-DemoAction.instance"/>
    <attr name="position" intvalue="100"/>
    </file>
    </folder>
    </folder>
    <folder name="Toolbars">
    <folder name="File">
    <file name="org-casaburo-submenuDemo-DemoAction.shadow">
    <attr name="originalFile" stringvalue="Actions/Edit/org-casaburo-submenuDemo-DemoAction.instance"/>
    <attr name="position" intvalue="0"/>
    </file>
    </folder>
    </folder>
    </filesystem>

     

    Now, let's say I want to place my Demo Action menu item under "My Submenu". I modify the layer.xml as below (notice the lines 20 to 25 below):

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN"
    "http://www.netbeans.org/dtds/filesystem-1_2.dtd">

    <filesystem>
    <folder name="Actions">
    <folder name="Edit">
    <file name="org-casaburo-submenuDemo-DemoAction.instance">
    <attr name="delegate" newvalue="org.casaburo.submenuDemo.DemoAction"/>
    <attr name="displayName" bundlevalue="org.casaburo.submenuDemo.Bundle#CTL_DemoAction"/>
    <attr name="iconBase" stringvalue="org/casaburo/submenuDemo/add.png"/>
    <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
    <attr name="noIconInMenu" boolvalue="false"/>
    </file>
    </folder>
    </folder>
    <folder name="Menu">
    <folder name="Edit">
    <folder name="My Submenu">
    <file name="org-casaburo-submenuDemo-DemoAction.shadow">
    <attr name="originalFile" stringvalue="Actions/Edit/org-casaburo-submenuDemo-DemoAction.instance"/>
    <attr name="position" intvalue="100"/>
    </file>
    </folder>
    </folder>
    </folder>
    <folder name="Toolbars">
    <folder name="File">
    <file name="org-casaburo-submenuDemo-DemoAction.shadow">
    <attr name="originalFile" stringvalue="Actions/Edit/org-casaburo-submenuDemo-DemoAction.instance"/>
    <attr name="position" intvalue="0"/>
    </file>
    </folder>
    </folder>
    </filesystem>

    And this is the result:

    That's all!

     

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}