001    package com.sptci.system;
002    
003    import nextapp.echo2.app.Button;
004    import nextapp.echo2.app.Component;
005    import nextapp.echo2.app.Grid;
006    import nextapp.echo2.app.Label;
007    import nextapp.echo2.app.PasswordField;
008    import nextapp.echo2.app.Row;
009    import nextapp.echo2.app.SplitPane;
010    import nextapp.echo2.app.TextField;
011    import nextapp.echo2.app.WindowPane;
012    
013    import com.sptci.echo2.Configuration;
014    import com.sptci.echo2.Utilities;
015    import com.sptci.echo2.Logout;
016    
017    /**
018     * A view component that is used to display the change password form to the
019     * user.
020     *
021     * <p>Copyright 2007 Sans Pareil Technologies, Inc.</p>
022     * @author Rakesh Vidyadharan 2007-04-22
023     * @version $Id: PasswordPane.java 3252 2007-05-12 19:12:31Z rakesh $
024     */
025    public class PasswordPane extends WindowPane
026    {
027      /**
028       * The component to use to capture the current password for the logged
029       * in user.
030       */
031      protected TextField password;
032    
033      /**
034       * The component on which the suggested password will be displayed.
035       */
036      protected Label suggest;
037    
038      /**
039       * The component to use to capture new password.
040       */
041      protected PasswordField newPassword;
042    
043      /**
044       * The component to use to capture the confirmation of the new password.
045       */
046      protected PasswordField confirmPassword;
047    
048      /**
049       * The button used to trigger a login action.
050       */
051      protected Button change;
052    
053      /**
054       * The controller for this view.
055       */
056      protected final PasswordController controller;
057    
058      /**
059       * Initialise the view using the specified {@link #controller}.
060       */
061      protected PasswordPane()
062      {
063        controller = new PasswordController( this );
064        setStyleName( getClass().getName() );
065        setTitle( Configuration.getString( this, "title" ) );
066        setDefaultCloseOperation( WindowPane.DO_NOTHING_ON_CLOSE );
067        initComponents();
068      }
069    
070      /**
071       * Initialise the components of this pane.
072       *
073       * @see #createComponent
074       * @see #createSuggestPassword
075       * @see #createChange
076       * @see #createCancel
077       */
078      protected void initComponents()
079      {
080        Grid grid = new Grid();
081        grid.setStyleName( getClass().getName() + ".grid" );
082    
083        createComponent( "password", grid );
084        createSuggestPassword( grid );
085        createComponent( "newPassword", grid );
086        createComponent( "confirmPassword", grid );
087        createChange( grid );
088        createCancel( grid );
089    
090        confirmPassword.addActionListener( new ChangePasswordListener( controller ) );
091    
092        add( grid );
093        controller.getApplication().setFocusedComponent( password );
094      }
095    
096      /**
097       * Initialise the specified component and add to the specified container
098       * component.
099       * 
100       * @param field The field that is to be initialised.
101       * @param component The parent container to which the field is to be
102       *   added.
103       */
104      protected void createComponent( String field, Component component )
105      {
106        component.add( Utilities.createLabel( getClass().getName(), field ) );
107    
108        component.add( Utilities.createTextField( getClass().getName(),
109              field, this ) );
110      }
111    
112      /**
113       * Create the components necessary to display a recommended password
114       * value.
115       *
116       * @param component The parent container to which the components created
117       *   are to be added.
118       */
119      protected void createSuggestPassword( Component component )
120      {
121        component.add( Utilities.createButton( getClass().getName(), "suggest",
122              new SuggestPasswordListener( controller ) ) );
123        component.add( Utilities.createLabel(
124              getClass().getName(), "suggest", this ) );
125      }
126    
127      /**
128       * Initialise the {@link #change} component and add to the specified
129       * container component.
130       * 
131       * @param component The parent container to which the field is to be
132       *   added.
133       */
134      protected void createChange( Component component )
135      {
136        component.add( Utilities.createButton( getClass().getName(),
137              "change", new ChangePasswordListener( controller ), this ) );
138      }
139    
140      /**
141       * Initialise the component used to cancel the password change action
142       * and log out of the application.
143       * 
144       * @param component The parent container to which the component is to be
145       *   added.
146       */
147      protected void createCancel( Component component )
148      {
149        Logout logout = new Logout();
150        //logout.setStyleName( "com.sptci.system.Logout" );
151        component.add( logout );
152      }
153    
154      /**
155       * Return the text entered into {@link #password}.
156       *
157       * @return The value entered into the component.
158       */
159      protected String getPassword()
160      {
161        return password.getText();
162      }
163    
164      /**
165       * Return the text entered into {@link #password}.
166       *
167       * @return The value entered into the component.
168       */
169      protected String getNewPassword()
170      {
171        return newPassword.getText();
172      }
173    
174      /**
175       * Return the text entered into {@link #password}.
176       *
177       * @return The value entered into the component.
178       */
179      protected String getConfirmPassword()
180      {
181        return confirmPassword.getText();
182      }
183    }