Navagation view for XML multiview editor
Saturday Aug 04, 2007
In an earlier blog entry, (the first part of the XML multiview + Visual Library integration series) Sunny left a comment that he wanted to provide the Navigator view for the XML editor embedded inside the XML multiview editor. I was trying to do this before, using the code and reading the help on Navigator API. But the reality is so simple... no need to create our own custom NavigatorLookup hint and Navigator Panel and no complex code to generate tree structure for XML file to display in Navigator Panel! Ok, then how to get the XML tree structure that we get to see when we open any XML file in the normal Netbeans editor similar to the following picture?
After some poking around, I thought let's see how this is done in web.xml XML multiview editor. When we create a Web application in Netbeans and want to edit web.xml, this editor pops up in the editor area. There I see that there is a Navigator View with XML tree structure and when we open the XML view, and click on a tag in the navigator view, that particular tag gets the cursor in the editor on the right side. Just like the normal XML navigator view!!.. Ok.. fine I got it
!!
Yes we got it.. how? Look into the source :D. I opened the J2EE DD loaders module under j2ee module and searched for 'navigat' and there I go.. I found how this is done.. this module re-uses the same navigator view as of normal one !..
The layer.xml file under 'org.netbeans.modules.j2ee.ddloaders.resources' shows the following :
<folder name="Navigator">
<folder name="Panels">
<folder name="text">
<folder name="x-dd-application5.0">
<file name="org-netbeans-modules-xml-text-navigator-XMLNavigatorPanel.instance"/>
</folder>
<folder name="x-dd-application1.4">
<file name="org-netbeans-modules-xml-text-navigator-XMLNavigatorPanel.instance"/>
</folder>
..........
..........
<folder name="x-dd-servlet2.4">
<file name="org-netbeans-modules-xml-text-navigator-XMLNavigatorPanel.instance"/>
</folder>
<folder name="x-dd-servlet2.5">
<file name="org-netbeans-modules-xml-text-navigator-XMLNavigatorPanel.instance"/>
</folder>
</folder>
</folder>
</folder>
For every XML file type, the code registers the same default XML navigator panel.. how cool is that? I used the same in the BookExample tutorial that I have been using in the XML multiview series.. and here is the Navigator view created with adding following lines in the layer.xml (which is created using the New FileType wizard.
<folder name="Navigator">
<folder name="Panels">
<folder name="text">
<folder name="x-book">
<file name="org-netbeans-modules-xml-text-navigator-XMLNavigatorPanel.instance"/>
</folder>
</folder>
</folder>
</folder>

And here is how the visual editor with same navigator view.. Note that in this, the navigation does not occur because the default navigator understands how to navigate in the XML editor and not in this XML multiview Visual Editor. 











