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