Skip to content
Last updated

Adding A Menu Item Walkthrough

A menu item is a line of a menu that has an associated action. In this example, we will add a menu item in the first position of the "Window" menu. The action associated with this menu item will be a warning dialog box.

Reviewing Dependencies

The creation of a menu item requires one INT module that is part of the INTViewer platform:

  • IntviewerCore

See the list of INTViewer modules to load the INTViewer platform and for a description of each module.

Creating your module template using NetBeans wizard

  • Click File -> New Project

  • In the New Project wizard select NetBeans Modules from the Categories list and Module from the Projects list and click Next >

  • For Project Name, specify mydemomenuitemmodule

  • Select option Standalone Module and make sure to specify the INTViewer platform in the NetBeans Platform field.

  • Click Next > and specify com.mycompany.myviewer.mydemomenuitemmodule for the Code Name Base and MyDemoMenuItemModule for the Module Display Name.

  • Check Generate XML Layer (if this option is not present, check the Registering the layer.xml file article)

  • Click on Finish

  • In the Projects tree view, you should see your project which includes a number of files that have been created for you

Configuring your Module

  • In the Projects tree, right click on the module MyDemoMenuItemModule and select Properties from the list.
  • Under Categories, select Libraries.
  • Select Java plaform JDK1.7 . If you don't see this option, you will need to install jdk1.7 and load it into NetBeans using option Tools->Java Platforms
  • Click on the Add button next to Module Dependencies
  • In the list, select IntviewerCore and click OK.
  • Click OK in Project Properties Dialog

Creating an Action class

  • In the Projects tree, right click on the module MyDemoMenuItemModule and select New -> Java Class... from the list and click NEXT.

  • Enter DemoMenuItemAction as Class Name and select com.mycompany.myviewer.mydemomenuitem as Package.

  • click FINISH

  • Automatically add an import for ActionListener. Add the phrase "implements ActionListener" to the class declaration.

  • Automatically create the skeleton of required methods for this class

  • Customize the actionPerformed method

This requires the import of com.interactive.intviewerapi.util.DialogManager. You can download the DemoMenuItemAction.java file from the attachments at the bottom this page.

More details about dialog boxes are available.

Customizing the layer.xml file

Modify the layer.xml file as follow:

In this layer.xml file:

  • <folder name="Actions"> indicates the start of the list of actions available in the module (do not change this line)
  • <folder name="WindowActions"> indicates the list of actions in the Windows menu (the name WindowsAction is arbitrary)
  • <file name="com-mycompany-myviewer-mydemomenuitem-DemoMenuItemAction.instance"> indicates a unique name for the menu item
  • <attr name="delegate" newvalue="com.mycompany.myviewer.mydemomenuitem.DemoMenuItemAction"/> specifies the action class associated with the menu item
  • <attr name="displayName" stringvalue="DemoMenuItemDisplayName"/> indicates the name of the menu item, as see by the end-user
  • <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/> specifies the class controlling the visibility of the menu item. In this case, it's always visible
  • <attr name="noIconInMenu" boolvalue="false"/> indicates that no icon is associated with the menu item
  • <folder name="Menu"> indicates the start of the list of menus customized in the module (do not change this line)
  • <folder name="Window"> indicates the name of the menu being customized
  • <file name="com-mycompany-myviewer-mydemomenuitem-DemoMenuItemAction.shadow"> indicates a unique name for the menu item
  • <attr name="originalFile" stringvalue="Actions/WindowActions/com-mycompany-myviewer-mydemomenuitem-DemoMenuItemAction.instance"/> indicates the name hierarchy of the menu item being added
  • <attr name="position" intvalue="0"/> indicates the position of the menu item in the menu

You can download the layer.xml file from the attachments at the bottom this page.

Running your Menu Item

Click the green arrow in the Netbeans toolbar to run your customized INTViewer. Your menu item should be available from the Window menu:

When clicked, this menu item should display this dialog box: