001 package com.sptci.rwt.webui;
002
003 import nextapp.echo2.app.Component;
004 import nextapp.echo2.app.Grid;
005 import nextapp.echo2.app.TextField;
006 import nextapp.echo2.app.list.DefaultListModel;
007
008 import echopointng.ComboBox;
009 import echopointng.PopUp;
010
011 import com.sptci.echo2.Configuration;
012 import com.sptci.echo2.Utilities;
013 import com.sptci.echo2.View;
014 import com.sptci.rwt.Category;
015
016 /**
017 * A component that is used to display the components necessary to
018 * prompt the user for entering information to save a SQL statement.
019 *
020 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
021 * @author Rakesh Vidyadharan 2007-10-10
022 * @version $Id: SaveQueryComponent.java 4123 2008-05-25 21:49:01Z rakesh $
023 */
024 public class SaveQueryComponent extends Grid implements View
025 {
026 /** The component used to display available categories. */
027 private ComboBox category;
028
029 /** The component used to enter the name for the query. */
030 private TextField name;
031
032 /** The controller to use to interact with the rest of the application. */
033 private final MainController controller;
034
035 /**
036 * Create a new instance with the specified controller.
037 *
038 * @param controller The controller to use to interact with the
039 * application.
040 */
041 public SaveQueryComponent( final MainController controller )
042 {
043 this.controller = controller;
044 }
045
046 /**
047 * Life-cycle method used to initialise the component.
048 *
049 * @see #createCategory
050 * @see #createName
051 */
052 @Override
053 public void init()
054 {
055 removeAll();
056 createCategory();
057 createName();
058 }
059
060 /**
061 * Initialise the {@link #category} component with data from the {@link
062 * com.sptci.rwt.Queries} data object.
063 */
064 protected void createCategory()
065 {
066 add( Utilities.createLabel(
067 getClass().getName(), "category", "Title.Label" ) );
068
069 category = new ComboBox();
070 category.setToolTipText(
071 Configuration.getString( this, "category.tooltip" ) );
072 DefaultListModel model = new DefaultListModel();
073
074 for ( Category category : controller.getCategories() )
075 {
076 model.add( category.getName() );
077 }
078
079 category.setListModel( model );
080 add( category );
081 }
082
083 /**
084 * Initialise the {@link #name} component and its associated {@link
085 * nextapp.echo2.app.Label}.
086 */
087 protected void createName()
088 {
089 add( Utilities.createLabel(
090 getClass().getName(), "name", "Title.Label" ) );
091 add( Utilities.createTextField(
092 getClass().getName(), "name",
093 new SaveQueryListener( controller ), this ) );
094 }
095
096 /**
097 * Return the value entered/selected in {@link #category} field.
098 *
099 * @return The value entered/selected or an empty string if no value
100 * was selected or entered.
101 */
102 public String getCategory()
103 {
104 return category.getText();
105 }
106
107 /**
108 * Return the value entered in {@link #name} field.
109 *
110 * @return The value entered or an empty string if no value was entered.
111 */
112 public String getName()
113 {
114 return name.getText();
115 }
116 }