Rocco has posted 2 posts at DZone. View Full User Profile

Tip: How to Create Submenus on the NetBeans Platform

04.08.2010
| 9134 views |
  • submit to reddit

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!

     

0
Your rating: None
Published at DZone with permission of its author, Rocco Casaburo.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Winston Dehaney replied on Tue, 2013/06/25 - 1:05am

Very nice tutorial Rocco. I know another simple alternative that I wish to share. Just have your Action reference in the anotation as the following:

@ActionReference(path = "Menu/My Submenu/Demo Action", ...

I hope it was helpful

Samad Khatri replied on Tue, 2014/05/13 - 6:18am

 ave encountered, I never prospective to discern a precise attractive advise online..Beyond viewing this sole, I felt so fortunate to remark its please.

how to get rid of genital herpes at home

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.