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