NetBeans Platform Cookbook Chapter 02 03


For navigation in the document IDEs provide Navigator panel. It shows important parts of the document or document's structure. The user moves caret in the editor by double-click on the node in the navigator window to wished location. You know it while editing sources.


The Navigator API module is available in the “ide” cluster - it is important when you want add it into module dependencies. You must open properties of the suite project, select Libraries and in the ide cluster add the Navigator API module to used platform module set. Then it gets available to add as dependency.

You define binding for your MIME-type of the file with the navigator in the layer file. If you want provide navigator without having own file-type (with DataObject, DataNode support) store the NavigatorLookupHint interface implementation into TopComponent's lookup - it returns the MIME-type only. The Navigator listens to global action context lookup changes and gets opened if registered MIME-type DataObject or NavigatorLookupHint looks up here.

You do not create TopComponent for Navigator but the NavigatorPanel implementation only. It is then integrated into NavigatorTopComponent We will show it.


Figure 2.7 Navigator

How to

If you have your MIME-type file support (or already registered by other installed modules) you ask the Platform open Navigator window by registering it in the layer file:

 <!--  Register your Navigator for MIME type    -->
 <folder name="Navigator">
     <folder name="Panels">
         <folder name="text">
             <folder name="nboutline">
                 <file name="nbpcook-navigator-nav-OutlineNavigator.instance"/>

If you do not have MIME-type add an NavigatorLookupHint into TopComponent's lookup:

  // in TopComponent you want associate with the Navigator
                , editorOutlineText
                , new OutlineNavigationHint()

  public static class OutlineNavigationHint 
                      implements NavigatorLookupHint { 
       public String getContentType() {
            return OutlineText.MIME_TYPE;
  } // OutlineNavigationHint

Now create declared OutlineNavigator (in our example) JComponent and implement the NavigatorPanel interface. The getDisplayName() method returns name of the view in the Navigator window, getDisplayHint() returns description of purpose, getComponent() returns created component (this, if you implement is in JComponent subclass). The panelActivated(Lookup context) and panelDeactivated() methods are used to register/unregister listeners listening data changes.

In the getLookup() method expose objects you will have contained in the actionsGlobalContext(). You have three variants (see documentation):

  • Expose selected node. The contained Node becomes as activated nodes of the Navigator TopComponent.
  • Return null null. Then the default mechanism chooses first Node from the Utilities.actionsGlobalContext() call as activated nodes of the Navigator TopComponent.

If you include an ActionMap it will be included in the actionsGlobalContext() when the Navigator is active.

Tip - sources

Text and sources were created under NB 6.8 6.9, 7.0, 7.1, 7.2. TODO 7.2 each line opens a new Navigator.


!-- Register your Navigator for MIME type --

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo