Connecting Help in NetBeans: From Help Set Installation to Hooking up Context-Sensitive Help

This document is designed to help NetBeans module writers with correctly setting up context-sensitive help for their modules. The document covers the following topics:

Introduction

The IDE's architecture enables you to:

In order to take advantage of these help features, a NetBeans module writer must be aware of different aspects of the NetBeans help system, specifically:

Adding Help to GUI components

There is an overview of adding help to various GUI NetBeans components in the NetBeans Module Document. This section expands a bit on the information provided there.

Explorer Nodes

If your node extends AbstractNode or one of its subclasses, you should implement the getHelpCtx method to return a HelpCtx for the node. The HelpCtx includes the specific Help ID for the help topic for this node. If the node is selected in the explorer and the user hits the F1 key, then the help associated with this node will be displayed.

public class MyNode extends AbstractNode{
    public HelpCtx getHelpCtx() {
        return new HelpCtx("org.netbeans.modules.xml.tree.nodes.XMLDataNode");   
    }
}

Wizards

Wizards are basically a series of Swing Components that are displayed via a WizardDescriptor.Iterator object. The object that the developer creates must implement the WizardDescriptor.Panel interface which includes a method that the developer implements to return the actual Swing Component that is to be displayed (usually a JPanel is returned). Additionally, the developer must implement the getHelp method and return a HelpCtx for this particular wizard step. By default, the Help button is displayed on the resulting JDialog and when the user selects this Help button, the getHelp method is called for the currently displayed WizardDescriptor.Panel object.

Public MyWizardPanel implements WizardDescriptor.Panel{

    private JPanel p;
    public Component getComponent() {
	if(p == null) {
	    p = new JPanel();
	    ... add Swing Components to JPanel ...
        }
	return p;
    }
    public HelpCtx getHelp() {
        return new HelpCtx("org.netbeans.modules.xml.core.wizard.DocumentPanel");  
    }
}

Dialogs

There are two different ways in which you can set help on a NetBeans dialog. If you wish to display a dialog of some sort, you typically create the Swing components you wish to display and then create a DialogDescriptor object which is a NetBeans object that is used to describe the behavior or the dialog. To display help:

  1. Specify the help on the DialogDescriptor object - As a rule, setting the help ID on the DialogDescriptor is the preferred way to set a help ID for a dialog. There are a couple of ways to do this:
  2. Set the help ID string on the displayed Swing Component - You'll notice that the DialogDescriptor constructor takes an Object which is typically the Swing Component to display in the JDialog. If you set the help ID string property on the Swing component, then this help id will be used as the help id for the JDialog and the corresponding help will be displayed if the user selects the Help button.
        JPanel p = new JPanel();
        ... add Swing Components to JPanel ...
        HelpCtx.setHelpIDString(p, "panel_help_id");   
        DialogDescriptor DD = new DialogDescriptor(p, "Dialog Title");
    
If you do not supply a HelpCtx object for the DialogDescriptor or set the help ID string for the displayed Swing Component, then no Help button will be displayed on the JDialog that is displayed for this DialogDescriptor.

Property Sheets

When creating a Property Sheet, the developer creates a Sheet.Set object. To populate the Sheet.Set the developer creates and adds a number of Node.Property objects. To display help for the Property Sheet, you must call the setValue method and set the helpID property:

    Sheet sheet = Sheet.createDefault();
    Sheet.Set ps = sheet.get(Sheet.PROPERTIES);
    ps.setValue("helpID", "org.netbeans.modules.xml.tree.nodes.XMLDataNode.Properties");  

Tabbed Property Sheets

Property sheets can actually contain multiple tabs, each having their own help associated with them. The method described above to set the help id of a Property Sheet still applies, the only difference is the way in which the additional Property Sheet is created:

    Sheet sheet = Sheet.createDefault();
    Sheet.Set referenceTab = new Sheet.Set();
    referenceTab.setValue("helpID", "org.netbeans.modules.xml.tree.nodes.XMLDataNode.ReferenceProperties");  
	referenceTab.setName("referenceTab"); // NOI18N
    sheet.put (referenceTab);

Individual Properties

You can also set an individual help ID for each property (Node.Property) in a property sheet. Presently S1S and NetBeans help is not provided on a per-property basis - help on individual properties is provided in the form of a tooltip.

Custom Property Editors

Some Properties displayed on a Property Sheet require a custom editor. The user accesses the editor by selecting the "..." button on an entry for a specific Property when the user selects that Property. The developer of the custom editor provides a Swing Component (typically a JPanel) which is ultimately displayed in a JDialog. If Help is to be supplied on the resulting JDialog, then the help ID string of the supplied Swing Component must be set.

Public MyPropertyEditor extends PropertyEditorSupport{
    public Component TreeNodeFilterCustomEditor() {
	JPanel p = new JPanel();
	... add Swing Components to JPanel ...
	HelpCtx.setHelpIDString(p, "org.netbeans.modules.xml.tax.beans.editor.TreeNodeFilterCustomEditor");   
	return p;
    }
}

Tabbed Custom Property Editors

Some Custom Property Editors display a number of tabs. Depending on the tab that is displayed, different Help may need to be displayed. In this case, you should set the help ID on the property editor's JTabbedPane. If you want the help ID to change when the user switches tabs, then you should listen for changes in the selected tab, and change the ID on the JTabbedPane each time.

For NetBeans 3.4 and earlier, you can set help IDs on tabs as shown in this example:

class MyTabPane extends JTabbedPane implements ChangeListener {
    private HelpCtx[] helps = new HelpCtx[3];
    public MyTabPane() {
        add(new Panel1());
        helps[0] = new HelpCtx("help_1");
    // etc.
        stateChanged(null);
    }
    public void stateChanged(ChangeEvent ignore) {
        HelpCtx.setHelpIDString(this, helps[getSelectedIndex()]);
    }
}

In NetBeans releases later than 3.4, you can use the HelpCtx.Provider to simplify the process, as shown in the following example:

class MyTabPane extends JTabbedPane implements HelpCtx.Provider{
    private HelpCtx[] helps = new HelpCtx[3];
    public MyTabPane() {
        add(new Panel1());
        helps[0] = new HelpCtx("help_1");
	// etc.
    }
    public HelpCtx getHelpCtx() {
	return helps[getSelectedIndex()];
    }
}

Service Types and System Options

Many modules define their own Service Types such as Ant Compilation. Additionally, many define their own System Options such as the UDDI Registries. In both cases, developers extend either the ServiceType or the SystemOption abstract class. Defined in each class is the getHelpCtx method. If you wish to display help for your Service Type or System Option, implement the method:

public class AntCompilerType extends CompilerType{
    public HelpCtx getHelpCtx() {
        return new HelpCtx ("org.apache.tools.ant.module.run.AntCompilerType");   
    }
}
Note that the CompilerType class extends the ServiceType class.

Making the Help Set Known to the IDE

In order to use the result help set within the IDE at runtime, a couple of things need to be added to various files associated with the module. These are outlined in part in the the NetBeans Module Document. There is an outstanding issue (#25594) in Issuzilla to create a separate set of documentation for the JavaHelp integration in the NetBeans Core.

Manifest File

There are two lines you need to add to your module's manifest file in order for your help set to be used at runtime:

Layer File

A module's help set must be defined in the JavaHelp Folder and this is specified in its Layer file. Layer files are typically called mf-layer.xml, layer.xml, or modulemf-layer.xml, layer.xml, or *Layer.xmlLayer.xml. You can find the name of your module's layer file in the module JAR's manifest. The following was taken from the HTTP Monitor Module mf-layer.xml file:

<filesystem>
   <folder name="Menu">
    <folder name="Help">
      <folder name="HelpShortcuts">
        <!-- Insert help set under the separator line below the Usersguide help -->
        <attr name="org-netbeans-modules-usersguide-sep.instance/org-netbeans-modules-web-monitor-mainpage.xml" boolvalue="true"/>
        <!-- Insert help set under JSP/Servlet Help -->
        <attr name="org-netbeans-modules-web-ie-mainpage.xml/org-netbeans-modules-web-monitor-mainpage.xml" boolvalue="true"/>
        <file name="org-netbeans-modules-web-monitor-mainpage.xml" url="help-main-ref.xml">
          <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.web.monitor.Bundle"/>
          <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/web/monitor/resources/blank.gif"/>
        </file>
        <!-- Insert help set above the separator line separating 3rd party help -->
        <attr name="org-netbeans-modules-web-monitor-mainpage.xml/org-netbeans-modules-usersguide-second-sep.instance" boolvalue="true"/>
      </folder>
    </folder>
  </folder>

  <folder name="Actions">
    <folder name="Help">
      <file name="org-netbeans-modules-web-monitor-mainpage.xml" url="help-main-ref.xml">
        <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.web.monitor.Bundle"/>
        <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/web/monitor/client/icons/menuitem.gif"/>
      </file>
    </folder>
  </folder>

  <folder name="Services"> 
    <folder name="JavaHelp">
      <!-- Merge after Core IDE Help: -->
      <attr name="org-netbeans-modules-usersguide-above-regular.txt/org-netbeans-modules-web-monitor-resources-helpset.xml" boolvalue="true"/>
      <!-- Merge after JSP/Servlet Help: -->
      <attr name="org-netbeans-modules-web-ie-helpset.xml/org-netbeans-modules-web-monitor-resources-helpset.xml" boolvalue="true"/>
      <file name="org-netbeans-modules-web-monitor-resources-helpset.xml" url="helpset-decl.xml"/>
      <!-- Merge before 3rd party help: -->
      <attr name="org-netbeans-modules-web-monitor-resources-helpset.xml/org-netbeans-modules-usersguide-below-regular.txt" boolvalue="true"/>
    </folder>
  </folder>
</filesystem>

Menu Folder - Use the Menu folder to place the shortcut to the help set in the IDE's Help | Help Sets menu. Notice that in standard NetBeans releases this submenu contains two separators. One is below the Core IDE Help shortcut, the other is above all third-party help sets like the Ant manual. (If you do not have the Ant Documentation module installed, this second separator doesn't appear. Sun One Studio or third-party releases may have additional separators between the Core IDE Help and 3rd party help.)

The shortcuts to all module help sets should appear between these two separators. Thus the layer file should always specify the following:

    <!-- Insert help set under the separator line below the Usersguide help -->
    <attr name="org-netbeans-modules-usersguide-sep.instance/org-netbeans-modules-web-monitor-mainpage.xml" boolvalue="true"/>
    <!-- Set the location of the help set by specifying which help set it should follow -->
    <attr name="org-netbeans-modules-web-ie-mainpage.xml/org-netbeans-modules-web-monitor-mainpage.xml" boolvalue="true"/>
    <!-- Insert help set above the separator line separating 3rd party help -->
    <attr name="org-netbeans-modules-web-monitor-mainpage.xml/org-netbeans-modules-usersguide-second-sep.instance" boolvalue="true"/>

The Menu folder also lets you set the icon that precedes the shortcut in the Help menu. The Core IDE Help should be the only help set that has an icon. Every other help set should be preceded by a blank 16x16 pixels icons, like so:

    <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/web/monitor/resources/blank.gif"/>

Actions Folder - Provides the general action that opens the HTTP Monitor help set in the IDE's help viewer. By default this action displays in the Help | Help Sets menu, but it can also be configured in Tools | Options.

Services Folder - Use the Services folder to merge the help set into the IDE's JavaHelp viewer. This folder also specifies the order in which the help sets appear in the table of contents and index. As with the shortcuts in the Help menu, all module help sets should be located between the Core IDE Help and third party help. You can specify this by with the following:

    <!-- Merge after Core IDE Help: -->
    <attr name="org-netbeans-modules-usersguide-above-regular.txt/org-netbeans-modules-web-monitor-resources-helpset.xml" boolvalue="true"/>
    <!-- Set the location of the help set by specifying which help set it should follow: -->
    <attr name="org-netbeans-modules-web-ie-helpset.xml/org-netbeans-modules-web-monitor-resources-helpset.xml" boolvalue="true"/>
    <!-- Merge before 3rd party help: -->
    <attr name="org-netbeans-modules-web-monitor-resources-helpset.xml/org-netbeans-modules-usersguide-below-regular.txt" boolvalue="true"/>

If you have any questions about this, please send e-mail to Paul Fussell as he is the one who added this to the various Layer files and understands it.

Where to Put Help Files in the Module Source

Typically, the Help files are added under a javahelp subdirectory off of the module root directory. Like source code, all JavaHelp documentation must be placed into a globally unique package to avoid conflicts. If two modules put help files into the same package, it will result in broken links. Therefore, the javahelp subdirectories should mirror the package structure of the src directory where the java source is located. While this is not a hard requirement and Help files can be put anywhere, this is the best way to avoid conflicts between module help sets.

For example, the structure of the module source and documentation of the EJB module in SunTM ONE Studio 4, Enterprise Edition for JavaTM is as follows:

    ejb (module root directory)
     |
     src/com/sun/forte4j/j2ee/ejb/ (several subdirectories of source files)
     |
     javahelp/com/sun/forte4j/j2ee/ejb/docs/ (several subdirectories of documentation files)
Wherever you choose to place your documentation files, your build.xml file must correctly that specify where the Help files are located so that the module build process can find them and build the help set.

Building the Help Set

In order to build the module help set, the javahelp target must be specified in the module's build.xml file. Additionally the netbeans target must depend on the javahelp target since that is the target that is built during a full build of the source. Here is a sample from the EJB build.xml in Sun ONE Studio 4, Enterprise Edition..
  <target name="netbeans" depends="jars,javahelp">
    <genlist targetname="nbm" outputfiledir="netbeans"/>
  </target>

  <target name="javahelp">
    <mkdir dir="javahelp/com/sun/forte4j/j2ee/ejb/docs/JavaHelpSearch2"/>
    <jhindexer basedir="javahelp/com/sun/forte4j/j2ee/ejb/docs/"
               db="javahelp/com/sun/forte4j/j2ee/ejb/docs/JavaHelpSearch2"
               jhall="${nbroot}/nbbuild/external/jhall-1.1.2_02.jar">
      <include name="**/*.html"/>
      <include name="**/*.htm"/>
      <exclude name="JavaHelpSearch2/"/>
      <exclude name="ja/"/>
      <exclude name="credits.html"/>
    </jhindexer>
    <mkdir dir="javahelp/com/sun/forte4j/j2ee/ejb/docs/ja/JavaHelpSearch2"/>
    <jhindexer basedir="javahelp/com/sun/forte4j/j2ee/ejb/docs/"
               dB="javahelp/com/sun/forte4j/j2ee/ejb/docs/ja/JavaHelpSearch2"
               locale="ja"
               jhall="${nbroot}/nbbuild/external/jhall-1.1.2_02.jar">
      <include name="ja/**/*.html"/>
      <include name="ja/**/*.htm"/>
      <exclude name="ja/JavaHelpSearch2/"/>
      <exclude name="ja/credits.html"/>
    </jhindexer>
    <mkdir dir="netbeans/modules/docs"/>
    <locjar jarfile="netbeans/modules/docs/ejb.jar"
            compress="true">
      <fileset dir="javahelp" excludesfile="${nbroot}/nbbuild/standard-jar-excludes.txt"/>
      <locale name="ja"/>
    </locjar>
  </target>

The path to the javahelp sources above follows the standard NetBeans pattern of matching documentation package hierarchies to source package heirarchies as described above. If you want to use a different directory structure, you must alter the entries in the javahelp target to correctly locate the directory where the files are located.

Note: The details of how build scripts work may vary from release to release. You should always compare against existing scripts in case of problems.

Additional Notes

This section includes any additional comments or issues regarding Help for IDE modules.

Questions or Comments? Send me email.