001 package com.sptci.echo2;
002
003 import nextapp.echo2.app.event.ActionEvent;
004 import nextapp.echo2.app.event.ActionListener;
005
006 /**
007 * An abstract controller for the {@link LoginPane} view component.
008 * Sub-classes must implement the appropriate action to be performed
009 * when the login form is submitted.
010 *
011 * <p>Copyright 2006 Sans Pareil Technologies, Inc.</p>
012 * @author Rakesh Vidyadharan 2006-11-23
013 * @version $Id: LoginPaneController.java 3139 2007-04-24 12:22:39Z rakesh $
014 */
015 public abstract class LoginPaneController extends Controller<LoginPane>
016 {
017 /**
018 * Create a new instance controlling a new instance of {@link LoginPane}
019 * stored in the {@link #view} field.
020 */
021 public LoginPaneController()
022 {
023 super( new LoginPane() );
024 view.setController( this );
025 view.initComponents();
026 }
027
028 /**
029 * Check the {@link #view} components to ensure that appropriate values
030 * have been entered. The default implementation ensures that non-empty
031 * values have been entered into the {@link LoginPane#userName} and
032 * {@link LoginPane#password} fields.
033 *
034 * @see #checkUserName
035 * @see #checkPassword
036 * @return Returns <code>true</code> if the tests succeed.
037 */
038 public boolean checkView()
039 {
040 return ( checkUserName() && checkPassword() );
041 }
042
043 /**
044 * Check the {@link LoginPane#userName} field to ensure that a value has
045 * been input into the field.
046 *
047 * @see #checkText
048 * @return Returns <code>true</code> if the value of the field is
049 * not <code>null</code> or empty.
050 */
051 public boolean checkUserName()
052 {
053 return checkText( view.getUserName() );
054 }
055
056 /**
057 * Check the {@link LoginPane#password} field to ensure that a value has
058 * been input into the field.
059 *
060 * @see #checkText
061 * @return Returns <code>true</code> if the value of the field is
062 * not <code>null</code> or empty.
063 */
064 public boolean checkPassword()
065 {
066 return checkText( view.getUserName() );
067 }
068
069 /**
070 * Return the <code>ActionListener</code> for the component identified
071 * by the name specified.
072 *
073 * @param component The component for which the action listener is
074 * to be returned.
075 * @return The appropriate action listener instance.
076 */
077 public abstract ActionListener getListener( String component );
078
079 /**
080 * An action listener that transfers control from the {@link
081 * LoginPane#userName} field to the {@link LoginPane#password} field.
082 */
083 public class UserNameListener implements ActionListener
084 {
085 /**
086 * The action listener implementation. Transfer control to the
087 * {@link LoginPane#password} field on {@link #view} if {@link
088 * #checkUserName} returns <code>true</code>. Sub-classes that need
089 * different checks on the value should override this method or
090 * {@link #checkUserName} as appropriate.
091 */
092 public void actionPerformed( ActionEvent event )
093 {
094 if ( checkUserName() )
095 {
096 getApplication().setFocusedComponent( view.password );
097 }
098 }
099 }
100 }