001    package com.sptci.rwt.webui.tree;
002    
003    import com.sptci.echo2.Application;
004    import com.sptci.echo2.Configuration;
005    
006    import com.sptci.rwt.ConnectionManager;
007    import com.sptci.rwt.PrimaryKeyMetaData;
008    import com.sptci.rwt.PrimaryKeyAnalyser;
009    import com.sptci.rwt.TableMetaData;
010    import com.sptci.rwt.webui.MainController;
011    
012    /**
013     * A {@link echopointng.tree.TreeNode} that contains nodes that represent
014     * the primary key columns for the specified table.
015     *
016     * <p>&copy; Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
017     * @author Rakesh Vidyadharan 2007-09-28
018     * @version $Id: PrimaryKeysNode.java 4123 2008-05-25 21:49:01Z rakesh $
019     */
020    public class PrimaryKeysNode extends ContainerNode<TableMetaData>
021    {
022      /**
023       * Create a new tree node using the specified metadata object.  The
024       * object represents a table in the database.
025       *
026       * @param metadata The metadata object to use as the model for this node.
027       */
028      public PrimaryKeysNode( final TableMetaData metadata )
029      {
030        super( metadata );
031      }
032    
033      /**
034       * Create the child nodes for this node.  Child nodes are instances of
035       * {@link ContainerNode}.
036       *
037       * @see PrimaryKeyNode
038       */
039      protected void createChildren()
040      {
041        initialised = true;
042    
043        try
044        {
045          PrimaryKeyMetaData pkmd = metadata.getPrimaryKey();
046    
047          if ( pkmd == null )
048          {
049            ConnectionManager manager = (ConnectionManager)
050              Application.getApplication().getProperty(
051                MainController.CONNECTION_MANAGER );
052            PrimaryKeyAnalyser analyser = new PrimaryKeyAnalyser( manager );
053    
054            for ( PrimaryKeyMetaData md :
055                analyser.analyse( metadata.getRoot(), metadata ) )
056            {
057              pkmd = md;
058            }
059          }
060    
061          if ( pkmd != null ) add( new PrimaryKeyNode( pkmd ) );
062        }
063        catch ( Throwable t )
064        {
065          processFatalException( metadata.getName(), t );
066        }
067      }
068    }