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.ErrorPane;
007
008 import com.sptci.rwt.CatalogueAnalyser;
009 import com.sptci.rwt.CatalogueMetaData;
010 import com.sptci.rwt.ConnectionManager;
011 import com.sptci.rwt.DBMSMetaData;
012 import com.sptci.rwt.SchemaAnalyser;
013 import com.sptci.rwt.SchemaMetaData;
014 import com.sptci.rwt.webui.MainController;
015
016 /**
017 * A root {@link echopointng.tree.TreeNode} that represents the currently
018 * active database connection. This class uses the {@link
019 * com.sptci.rwt.DBMSMetaData} value object as the model.
020 *
021 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
022 * @author Rakesh Vidyadharan 2007-09-27
023 * @version $Id: DBMSNode.java 4123 2008-05-25 21:49:01Z rakesh $
024 */
025 public class DBMSNode extends AbstractNode<DBMSMetaData>
026 {
027 /**
028 * Create a new root tree node using the specified metadata object.
029 *
030 * @param metadata The metadata object to use as the model for this node.
031 */
032 public DBMSNode( final DBMSMetaData metadata )
033 {
034 super( metadata );
035 }
036
037 /**
038 * Create the child nodes for this node. Child nodes are instances of
039 * {@link SchemaNode}.
040 *
041 * @see SchemaAnalyser
042 * @see SchemaNode
043 */
044 @Override
045 protected void createChildren()
046 {
047 initialised = true;
048
049 try
050 {
051 final DBMSMetaData dmd = getUserObject();
052
053 Collection<CatalogueMetaData> catalogues = dmd.getCatalogues();
054
055 if ( catalogues.isEmpty() )
056 {
057 final ConnectionManager manager = (ConnectionManager)
058 Application.getApplication().getProperty(
059 MainController.CONNECTION_MANAGER );
060 final CatalogueAnalyser analyser = new CatalogueAnalyser( manager );
061 catalogues = analyser.analyse( dmd );
062 }
063
064 for ( CatalogueMetaData catalogue : catalogues )
065 {
066 add( new CatalogueNode( catalogue ) );
067 }
068
069 Collection<SchemaMetaData> schemas = dmd.getSchemas();
070
071 if ( schemas.isEmpty() )
072 {
073 final ConnectionManager manager = (ConnectionManager)
074 Application.getApplication().getProperty(
075 MainController.CONNECTION_MANAGER );
076 final SchemaAnalyser analyser = new SchemaAnalyser( manager );
077 schemas = analyser.analyse( dmd );
078 }
079
080 for ( SchemaMetaData schema : schemas )
081 {
082 add( new SchemaNode( schema ) );
083 }
084 }
085 catch ( Throwable t )
086 {
087 processFatalException( t );
088 }
089 }
090 }