Creating context-sensitive Oracle Help

Note: The information in this topic is intended for developers who need to connect context-sensitive Oracle Help topics to applications.

Creating context-sensitive Oracle Help is a collaborative effort between authors and developers. Oracle Help supports context-sensitive Help, but all of the code to make it work properly must be written and customized by your developer.

A complete working example of a simple Java application with context-sensitive Help is shown below. Follow these steps to run the example:

  1. Ensure that you have the Oracle Help for Java components and the Java Development Kit (JDK) 1.2 or later.

  2. Copy and paste the code below into a file called CSHDemo.java.

  3. Compile the file (e.g., javac CSHDemo.java).

  4. Run the Java applet (e.g., java .cSHDemo <Oracle Help Helpset file>). The Oracle Help helpset file parameter is the fully-qualified path to the helpset file. As an example, if you create an Oracle Help helpset file named "sample.hs" and saved it in "C:\myFiles," the command to run this application with your helpset file would be:

 java CSHDemo C:\myFiles\Sample.hs

Sample Context Sensitive Java Application

/*********************************************************************************
 * Oracle Help Context Sensitive Help Sample Application

 *

 * This application is intended to demonstrate a few methods for invoking

 * context sensitive help with Oracle Help.

 *

 * USAGE:  CSHSample <full path to helpset file>

 *

 *********************************************************************************/


import oracle.help.Help;

import oracle.help.CSHManager;

import oracle.help.library.Book;

import oracle.help.library.helpset.HelpSet;

import oracle.help.navigator.Navigator;


import java.awt.*;

import java.awt.event.*;

import java.net.URL;

public class CSHSample extends Frame implements ActionListener
{

  private Help helpObj;

  private Book bookObj;

  private CSHManager contextManager;

  private MenuItem exitMenu;

  private MenuItem contentsMenu;

  private MenuItem searchMenu;

  private MenuItem indexMenu;


  // Constants set to TopicIDs from map file for Helpset passed in

  // via command line.

  public static final String LABEL = "what_is_a_label_htm";

  public static final String FIELD = "what_is_a_text_field_htm";


  public static void main(String[] args)

  {

    if (args.length != 1)
{
      System.err.println("Usage: CSHSample <full path to helpset file>");

      System.exit(1);

    }


    Book bookObj = null;

    String filename = args[0];


    // Expects filename format to be: "file:/[<drive>:/]dir/<helpset_file>"

 
  // e.g., "file:/c:/myPath/myHelp.hs"

    if (filename.charAt(0) == '/')

      filename = "file:" + filename;

    else

      filename = "file:/" + filename;


    try {

      bookObj = (Book) new HelpSet(new URL(filename));

    }

    catch (Exception e) {

      System.err.println("CSHSample Error: " + e.getMessage());

      System.exit(1);

    }


    CSHSample sampApp = new CSHSample(bookObj);

    sampApp.setVisible(true);

  }


  // Class Constructor

  public CSHSample(Book bookObj)

  {

    super("CSH Sample Application");


    setResizable(false);

    setSize(300, 200);


    // Create Help Objects

    try {

      helpObj = new Help(false, false);

      contextManager = new CSHManager(helpObj);

      contextManager.addBook(bookObj, true);

    }

    catch (Exception e)
{
      System.err.println("CSHSample:: Failed While Creating Help object");

      e.printStackTrace();

      System.exit(1);

    }


    /********************************************************************

 
   * Add UI Components

 
   *******************************************************************/

    MenuBar menubar = new MenuBar();


    Menu filemenu = new Menu("File");

    exitMenu = new MenuItem("Exit");

    filemenu.add(exitMenu);

    exitMenu.addActionListener(this);

    menubar.add(filemenu);


    Menu helpmenu = new Menu("Help");

    contentsMenu = new MenuItem("Help Contents");

    contentsMenu.addActionListener(this);

    helpmenu.add(contentsMenu);

    indexMenu = new MenuItem("Topic Index");

    indexMenu.addActionListener(this);

    helpmenu.add(indexMenu);

    searchMenu = new MenuItem("Full Text Search");

    searchMenu.addActionListener(this);

    helpmenu.add(searchMenu);

    menubar.add(helpmenu);


    setMenuBar(menubar);


    Panel mainPanel = new Panel();

    add(mainPanel, BorderLayout.CENTER);


    // Add label

    Label label = new Label("Country:", Label.LEFT);

    mainPanel.add(label);

    // Set context help for component. TopicID = LABEL

 
  // Pass the component with the associated TopicID to the CSHManager Object

    contextManager.addComponent(label, LABEL, true, true);


    // Add TextField

    TextField field = new TextField(15);

    mainPanel.add(field);

    // Set context help for component. TopicID = FIELD

 
  // Pass the component with the associated TopicID to the CSHManager Object

    contextManager.addComponent(field, FIELD, true, true);


    /********************************************************************

     * End: Add UI Components

     *******************************************************************/


    addWindowListener(

      new WindowAdapter()

      {

        public void windowClosing(WindowEvent e)

        {

          setVisible(false);

          System.exit(0);

        }

      }

    );

  }


  public void actionPerformed(ActionEvent e)

  {

    Object source = e.getSource();


    if (source == exitMenu) {

      setVisible(false);

      System.exit(0);

    }

    else if (source == contentsMenu) {

      // Show Help; Display Contents tab

      Navigator[] navs = contextManager.getAllNavigators();

      if (navs != null)

        contextManager.showNavigatorWindow(navs[0]);

    }

    else if (source == indexMenu) {

      // Show Help; Display Index tab

      Navigator[] navs = contextManager.getAllNavigators();

      if (navs != null)

        contextManager.showNavigatorWindow(navs[1]);

    }

    else if (source == searchMenu) {

      // Show Help; Display Search tab

      Navigator[] navs = contextManager.getAllNavigators();

      if (navs != null)

        contextManager.showNavigatorWindow(navs[2]);

    }

  }

}