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