001 package com.sptci.rwt.webui.model;
002
003 import java.util.Collection;
004
005 import nextapp.echo2.app.Component;
006 import nextapp.echo2.app.Grid;
007 import nextapp.echo2.app.Label;
008
009 import echopointng.GroupBox;
010
011 import com.sptci.ReflectionUtility;
012 import com.sptci.echo2.Application;
013 import com.sptci.echo2.Configuration;
014 import com.sptci.echo2.Utilities;
015
016 import com.sptci.rwt.MetaData;
017 import com.sptci.rwt.CatalogueMetaData;
018
019 /**
020 * A view component used to display the information contained in
021 * {@link com.sptci.rwt.CatalogueMetaData}.
022 *
023 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
024 * @author Rakesh Vidyadharan 2007-10-07
025 * @version $Id: CatalogueView.java 4123 2008-05-25 21:49:01Z rakesh $
026 * @since Version 1.1
027 */
028 public class CatalogueView extends AbstractView
029 {
030 /** The meta data object whose details are to be displayed. */
031 private final CatalogueMetaData metaData;
032
033 /**
034 * Create a new instance of the view using the specified model object.
035 *
036 * @param metaData The {@link #metaData} model object to use.
037 */
038 public CatalogueView( final CatalogueMetaData metaData )
039 {
040 this.metaData = metaData;
041 }
042
043 /**
044 * Lifecycle method used to initialise component when added to a
045 * container hierarchy.
046 *
047 * @see #createDetails
048 */
049 @Override
050 public void init()
051 {
052 removeAll();
053 add( createDetails() );
054 }
055
056 /**
057 * Create the component used to display the default limits enforced by
058 * the database engine.
059 *
060 * @see #createLabels
061 * @return The component that displays the limits information.
062 */
063 protected Component createDetails()
064 {
065 Grid grid = new Grid();
066
067 createLabels( "schemas", metaData, grid );
068 createLabels( "tables", metaData, grid );
069 createLabels( "views", metaData, grid );
070 createLabels( "triggers", metaData, grid );
071 createLabels( "procedures", metaData, grid );
072 createLabels( "sequences", metaData, grid );
073
074 GroupBox box = new GroupBox( Configuration.getString( this, "title" ) );
075 box.add( grid );
076 return box;
077 }
078
079 /**
080 * Create standard {@link nextapp.echo2.app.Label} components that
081 * represent the name of the specified field and the value in the
082 * specified model. Over-ridden to invoke the {@link
083 * java.util.Collection#size} method instead of just the accessor in
084 * the model.
085 *
086 * @param name The name of the field.
087 * @param metaData The model object.
088 * @param component The container component to which the labels are to
089 * be added.
090 */
091 @Override
092 protected void createLabels( final String name, final MetaData metaData,
093 final Component component )
094 {
095 final String method = "get" + name.substring( 0, 1 ).toUpperCase() +
096 name.substring( 1 );
097
098 try
099 {
100 component.add( Utilities.createLabel(
101 getClass().getName(), name, "Title.Label" ) );
102
103 Collection collection =
104 (Collection) ReflectionUtility.execute( metaData, method );
105 int size = collection.size();
106 component.add( new Label(
107 ( ( size == 0 ) ? "Not loaded or 0" : String.valueOf( size ) ) ) );
108 }
109 catch ( Throwable t )
110 {
111 processFatalException( method, metaData.getClass().getName(), t );
112 }
113 }
114 }