Thursday, July 13, 2006

Displaying Non-Resource Content Using the Common Navigator Framework

Introduction
This post discusses the procedure for displaying non-resource nodes in a CNF Viewer. Examples of non-resource nodes are database tables or servers.

Prerequisites
The article assumes that you have some familiarity with the Common Navigator Framework. If not there are some great articles by Michael Elder.

Define a View and a Viewer
Define a view and a viewer using the common navigator framework.


This definition also adds the content binding for displaying standard resource nodes in the project structure.

Our Content
Our content will consist of the class called Child which represents a non-resource child and a class called NRParent, which will form the parent of all Child classes in the project tree. Note that in a real world the Child class could be something like a database table.





Next a Content provider and a Label provider need to be defined for this content. The content provider is simple - if a parent is of type IProject, it contributes a NRParent instance, if a parent is of type NRParent, it provides some children of type Child and if it is of type Child, it just provides more children.

Here are the relevant code sections from the content provider and the label provider -






The point to note is that when the parent is of type IProject, is when you need to provide first level non-resource nodes to the project structure. Ofcourse you can provide non-resource nodes to a specific folder within a project too or even a file. In that case, check for the parent being of type IFolder or IFile respectively. I can't think of a specific use-case for it right now, but it is something that is possible.


Now add a navigatorContent extension that defines the content provider, the label provider and trigger point. Note the trigger point and the possible children elements.


Finally, add a viewerContentBinding to bind the above navigatorContent to the viewer.



That is it. Execute a Run configuration for the plugin and open the view to see the new non-resource nodes.

As suggested by Michael, the source code has been added as an attachment to bug 143127: [CommonNavigator] Examples

  DB Reading BASE: An Acid Alternative: In partitioned databases, trading some consistency for availability can lead to dramatic improvement...