001 package com.sptci.rwt.webui.model;
002
003 import java.util.Collection;
004 import java.util.Map;
005
006 import nextapp.echo2.app.Component;
007 import nextapp.echo2.app.Grid;
008 import nextapp.echo2.app.Label;
009
010 import echopointng.GroupBox;
011
012 import com.sptci.echo2.Configuration;
013 import com.sptci.echo2.Utilities;
014
015 import com.sptci.rwt.ColumnMetaData;
016 import com.sptci.rwt.KeyMetaData;
017 import com.sptci.rwt.ForeignKeyMetaData;
018
019 /**
020 * A view component used to display the information contained in
021 * {@link com.sptci.rwt.ForeignKeyMetaData}.
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: ForeignKeyView.java 4123 2008-05-25 21:49:01Z rakesh $
026 */
027 public class ForeignKeyView extends KeyView
028 {
029 /** The meta data object whose details are to be displayed. */
030 private final ForeignKeyMetaData metaData;
031
032 /**
033 * Create a new instance of the view using the specified model object.
034 *
035 * @param metaData The {@link #metaData} model object to use.
036 */
037 public ForeignKeyView( final ForeignKeyMetaData metaData )
038 {
039 this.metaData = metaData;
040 }
041
042 /**
043 * Lifecycle method used to initialise component when added to a
044 * container hierarchy.
045 *
046 * @see #createDetails
047 * @see #createColumnDetails
048 * @see #createColumnMappings
049 */
050 @Override
051 public void init()
052 {
053 removeAll();
054 add( createDetails() );
055 add( createColumnDetails() );
056 add( createColumnMappings() );
057 }
058
059 /**
060 * Create the component used to display the details of the foreign key.
061 *
062 * @see #createLabels
063 * @return The component that displays the foreign key information.
064 */
065 protected Component createDetails()
066 {
067 Grid grid = new Grid();
068
069 createLabels( "name", metaData, grid );
070 createLabels( "referencedSchema", metaData, grid );
071 createLabels( "referencedTable", metaData, grid );
072 createLabels( "updateRule", metaData, grid );
073 createLabels( "deleteRule", metaData, grid );
074 createLabels( "deferrability", metaData, grid );
075
076 GroupBox box = new GroupBox( Configuration.getString( this, "title" ) );
077 box.add( grid );
078 return box;
079 }
080
081 /**
082 * Create the component used to display the mapping of the table column(s)
083 * to the referenced table column(s).
084 *
085 * @return The component that displays the mappings.
086 */
087 protected Component createColumnMappings()
088 {
089 Map<ColumnMetaData,String> map = metaData.getColumnMappings();
090 Grid grid = new Grid( map.size() + 1 );
091
092 for ( ColumnMetaData cmd : map.keySet() )
093 {
094 grid.add( Utilities.createLabel(
095 getClass().getName(), "columnLabel", "Title.Label" ) );
096 grid.add( new Label( cmd.getName() ) );
097 }
098
099 for ( String column : map.values() )
100 {
101 grid.add( Utilities.createLabel(
102 getClass().getName(), "referencedColumn", "Title.Label" ) );
103 grid.add( new Label( column ) );
104 }
105
106 GroupBox box = new GroupBox(
107 Configuration.getString( this, "columnMappings.title" ) );
108 box.add( grid );
109 return box;
110 }
111
112 /**
113 * Method to return the model object for this view.
114 *
115 * @return The meta data object.
116 */
117 @Override
118 protected KeyMetaData getMetaData()
119 {
120 return metaData;
121 }
122 }