001 package com.sptci.rwt.webui;
002
003 import nextapp.echo2.app.Column;
004 import nextapp.echo2.app.Component;
005 import nextapp.echo2.app.ContentPane;
006 import nextapp.echo2.app.SplitPane;
007
008 import com.sptci.echo2.Header;
009 import com.sptci.echo2.View;
010 import com.sptci.echo2.style.Extent;
011
012 /**
013 * The primary {@link nextapp.echo2.app.ContentPane} for the application.
014 *
015 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
016 * @author Rakesh Vidyadharan 2007-09-29
017 * @version $Id: MainView.java 4123 2008-05-25 21:49:01Z rakesh $
018 */
019 public class MainView extends ContentPane implements View
020 {
021 /** The controller for this view component. */
022 private final MainController controller;
023
024 /** The component used to display the menu for the application. */
025 private MenuComponent menuComponent;
026
027 /** The component used to display the database object hierarchy. */
028 private MetaDataTree tree;
029
030 /** container used to hold the metadata objects (tree). */
031 private Component left;
032
033 /**
034 * The container used to hold all the information displayed in the
035 * detail view area (right side).
036 */
037 private Component right;
038
039 /**
040 * Create a new instance of the pane.
041 *
042 * @see #layout
043 * @see #createLeft
044 * @see #createRight
045 */
046 public MainView()
047 {
048 controller = new MainController( this );
049 layout();
050 }
051
052 /**
053 * Refreshes the view. Usually used to initiate a new connection.
054 */
055 void refresh()
056 {
057 left.remove( tree );
058 left.add( createTree() );
059 right.removeAll();
060 }
061
062 /**
063 * Set the content of the {@link #right} using the specified component.
064 *
065 * @param component The component that is to be displayed in the right
066 * container component.
067 */
068 void setContent( final Component component )
069 {
070 right.removeAll();
071 right.add( component );
072 }
073
074 /**
075 * Layout the content pane to accomodate top menu, database object
076 * navigation (left) and detail content (right).
077 *
078 * @see #createTop
079 * @see #createLeft
080 * @see #createRight
081 */
082 private void layout()
083 {
084 SplitPane main = new SplitPane( SplitPane.ORIENTATION_VERTICAL );
085 main.setStyleName( getClass().getName() + ".mainSplitPane" );
086 main.add( createTop() );
087
088 SplitPane displayArea = new SplitPane();
089 displayArea.setStyleName( getClass().getName() + ".displayArea" );
090 displayArea.add( createLeft() );
091 displayArea.add( createRight() );
092
093 main.add( displayArea );
094 add( main );
095 }
096
097 /**
098 * Create the component that displays header and menu.
099 *
100 * @see com.sptci.echo2.Header
101 * @see MenuComponent
102 */
103 private Component createTop()
104 {
105 Column column = new Column();
106 column.setCellSpacing( Extent.getInstance( 0 ) );
107 column.add( new Header() );
108
109 menuComponent = new MenuComponent( controller );
110 column.add( menuComponent );
111
112 return column;
113 }
114
115 /**
116 * Create the left navigation area.
117 */
118 private Component createLeft()
119 {
120 left = new Column();
121 return left;
122 }
123
124 /**
125 * Create the right area that holds the main content.
126 */
127 private Component createRight()
128 {
129 right = new Column();
130 return right;
131 }
132
133 /**
134 * Create the component that displays the database metadata objects in
135 * a tree.
136 *
137 * @return The tree component.
138 */
139 private MetaDataTree createTree()
140 {
141 tree = new MetaDataTree( controller );
142 return tree;
143 }
144
145 /**
146 * Returns {@link #controller}.
147 *
148 * @return The value/reference of/to controller.
149 */
150 public MainController getController()
151 {
152 return controller;
153 }
154
155 /**
156 * Returns {@link #menuComponent}.
157 *
158 * @return The value/reference of/to menuComponent.
159 */
160 public MenuComponent getMenuComponent()
161 {
162 return menuComponent;
163 }
164
165 /**
166 * Rebuilds the {@link #menuComponent}.
167 */
168 public void rebuildMenu()
169 {
170 final Component parent = menuComponent.getParent();
171 final int index = parent.indexOf( menuComponent );
172 parent.remove( index );
173 menuComponent = new MenuComponent( controller );
174 parent.add( menuComponent, index );
175 }
176 }