Developing exteNd Director Applications

CHAPTER 8

Using the Relationship Viewer

This chapter explains how to use the Relationship Viewer to navigate relationships within a resource set. It contains the following sections:

 
Top of page

About the Relationship Viewer

The Relationship Viewer shows the relationships that exist for the currently open object. When you open an object in a resource set, the Relationship Viewer displays an easy navigation path from this object to other items within the resource set that may be of interest to you. The possible navigation paths are represented as a tree of folders and files, similar to the tree presentation used in Windows Explorer. You can expand or collapse the branches of the tree to navigate the relationships within the resource set.

The Relationship Viewer is a visual rendering of output produced by a relationship analyzer. The relationship analyzer determines which navigation paths are interesting to show to the user from any object within the resource set. The relationship analyzer generates an XML tree as output, which is processed by the Relationship Viewer. Typically, these navigation paths are based on relationships that are fundamental to an exteNd Director application. If you open a PID page, for example, the Relationship Viewer displays the PID descriptors for the page.

exteNd Director includes built-in relationship analyzers for the common items in a resource set. And you can create custom relationship analyzers to suit your own application requirements.

 
Top of page

Navigating relationships within a resource set

To use the Relationship Viewer you must first open a file, and you do that from either the Search tab or a view.

Procedure To navigate the relationships for a resource:

  1. In the exteNd Director Navigation Pane, click the Resources tab.

  2. Click the Search tab or the View tab.

  3. Find the item you want to open.

    For more information    For more information on using the Search tab, see Searching a Resource Set. For more information on the View tab, see Working with Views.

  4. Double-click the item.

    The source file editor displays the contents of the file, and the Relationship Viewer shows one or more relationships that are specific to the type of file you opened.

    Items that were read from disk are editable and appear in black. Items that were read from JAR files are not editable. These items appear in blue and are marked with RO (read-only).

  5. In the Relationship Viewer, expand or collapse the branches of the tree to see the possible navigation paths.

  6. When you see another file you want to open, double-click it.

    The source file editor displays the contents of the file, and the Relationship Viewer displays one or more relationships that are specific to this file.

 
Top of page

Creating a custom relationship analyzer

You might create a custom relationship analyzer when you want to create a new type of element that an exteNd Director resource set should know about.

For example, suppose you create custom elements in a directory called my-stuff within the resource set. Within the my-stuff directory, you place XML files that list portlets of interest. In this case, for each XML document in the my-stuff directory, you might want to process portlet information and add each portlet listed to the XML tree.

Here's the source for example.xml, a sample file in the my-stuff directory:

  <portlets>
    <portlet cid="FireRule.xml">
    <portlet cid="MyPages.xml">
  </portlets>

When the example.xml file is opened in the development environment, the custom relationship analyzer is called; it reads the document and converts it into an XML structure that represents the tree that should be displayed.

The Relationship Viewer renders the tree generated by a custom relationship analyzer just as it would render any tree generated by one of the built-in relationship analyzers. Items that were read from disk are editable and appear in black. Those items that were read from JAR files are not editable. These items appear in blue and are marked with RO (read-only).

 
Top of section

Creating a relationship analyzer class

To determine which relationship analyzers are available, the development environment asks the resource set for a list of all classes that implement the EbiElementRelationshipAnalyzer interface. When it has this list, it cycles through the classes on the list asking each if it wants to be the provider of the relationship tree. It does this by calling the analyzeFile() method. If the method returns true, processing is stopped and the same class is asked a second time to provide the XML structure that represents the tree of relationships. It does this by calling the getTreeXML() method.

To create a custom relationship analyzer, you need to create a class that implements the EbiElementRelationshipAnalyzer interface and put that class inside the resource set. For example, to support custom elements in the my-stuff directory (as described above), you might create a source file called MyStuffRelationshipAnalyzer.java and put it in the ResourceSet/src directory.

Here's the code for the MyStuffRelationshipAnalyzer:

  import java.io.*;
  import java.util.*;
  import com.sssw.fw.resource.*;
  import com.sssw.extensions.xwb.util.*;
  import com.sssw.extensions.xwb.fw.resource.api.*;
  import com.sssw.extensions.xwb.fw.resource.ui.*;
  
  public class MyStuffRelationshipAnalyzer implements EbiElementRelationshipAnalyzer {
      
  public boolean analyzeFile( EboResourceElement element ) {
   // make sure we have an element
    if ( element != null ) {
     // if it is from the "my-stuff" directory & is XML, then I will
     // provide the relationship analyzer for it
     if ( element.getDirectoryName().equals( "my-stuff" ) ) {
        return element.isXML();
     }
   }
   return false;
      }
  
  public org.jdom.Document getTreeXml( EboResourceElement element ) {
   // create the xml tree
   EboTreeXmlHelper th = new EboTreeXmlHelper();        
   try {
      // add the opened object as a node
      th.addElement( th.makeElement( element,
         EbiElementRelationshipAnalyzer.XML_ICON ) );                                           
      // create a portlets folder
      EboFolder portletsFolder = new EboFolder( "Portlets" );
      th.addFolder( portletsFolder );
      // find all the portlets nodes
      org.w3c.dom.NodeList portlets =
        element.getDocument().getElementsByTagName( "portlet" ); 
      if ( portlets != null ) {
          String cid = null;
          org.w3c.dom.Element portletElem = null;                
          int len = portlets.getLength();                
          // process through the portlets nodeList
          for ( int i = 0; i < len; i++ ) {
              if ( portlets.item( i ) instanceof org.w3c.dom.Element ) {
              portletElem = (org.w3c.dom.Element)( portlets.item( i ) );
              // get the portlet id ( cid )
              cid = portletElem.getAttribute( "cid" );
              if ( cid != null ) {
               // try and find the portlet in the portal-portlet
               // directory
                  EboResourceElement re = 
                  EboResource.getCurrent().getResourceElement( 
                      "portal-portlet", cid );
                  // add it to the portlets folder
                  th.addElement( portletsFolder, th.makeElement( re,
                      EbiElementRelationshipAnalyzer.XML_ICON ) );                                           
                          }
                      }
                  }
              }
          }
          catch( Exception e ) {
              System.out.println( e );
          }
          return th.getDocument();        
      }    
  
  }
  


Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved.  more ...