/**
 * <License>
 */
package edu.colorado.csdms.wmt.client.ui.handler;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

import edu.colorado.csdms.wmt.client.control.DataManager;
import edu.colorado.csdms.wmt.client.control.DataTransfer;
import edu.colorado.csdms.wmt.client.data.Constants;
import edu.colorado.csdms.wmt.client.ui.widgets.LoginPanel;
import edu.colorado.csdms.wmt.client.ui.widgets.QuestionDialogBox;

/**
 * Handles login and logout events in the WMT client.
 * 
 * @author Mark Piper (mark.piper@colorado.edu)
 */
public class AuthenticationHandler implements ClickHandler {

  private DataManager data;
  private LoginPanel panel;
  
  /**
   * Creates a new {@link AuthenticationHandler}.
   * 
   * @param data the DataManager object for the WMT session
   * @param panel the {@link LoginPanel} object for the WMT session
   */
  public AuthenticationHandler(DataManager data, LoginPanel panel) {
    this.data = data;
    this.panel = panel;
  }
  
  @Override
  public void onClick(ClickEvent event) {

    if (data.security.isLoggedIn()) {

      final QuestionDialogBox questionDialog =
          new QuestionDialogBox(Constants.QUESTION_SIGN_OUT);
      questionDialog.getChoicePanel().getOkButton().setHTML(Constants.SIGN_OUT);
      questionDialog.getChoicePanel().getOkButton().addClickHandler(
          new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
              DataTransfer.logout(data);
              questionDialog.hide();
            }
          });
      questionDialog.getChoicePanel().getCancelButton().addClickHandler(
          new DialogCancelHandler(questionDialog));
      questionDialog.center();

    } else {

      // Get WMT username.
      String userName = panel.getEmailBox().getText();
      data.security.setWmtUsername(userName);
      GWT.log(data.security.getWmtUsername());

      // Get WMT password.
      String password = panel.getPasswordBox().getText();
      data.security.setWmtPassword(password);
      GWT.log(data.security.getWmtPassword());

      // Authenticate the user.
      DataTransfer.login(data);
    }
  }
}

@@ -203,24 +203,77 @@
 lickHandler;
+%0Aimport com.google.gwt.event.dom.client.KeyDownEvent;
 %0A%0Aimport edu
@@ -792,18 +792,16 @@
  panel;%0A
-  
 %0A  /**%0A 
@@ -1108,18 +1108,16 @@
 el;%0A  %7D%0A
-  
 %0A  @Over
@@ -1397,86 +1397,65 @@
 T);%0A
+%0A
       
-questionDialog.getChoicePanel().getOkButton().addClickHandler(%0A         
+// Define handlers.%0A      ClickHandler okHandler =
  new
@@ -1480,20 +1480,16 @@
         
-   
- 
 @Overrid
@@ -1490,20 +1490,16 @@
 verride%0A
-    
         
@@ -1548,20 +1548,16 @@
         
-   
- 
 DataTran
@@ -1575,20 +1575,16 @@
 (data);%0A
-    
         
@@ -1618,137 +1618,540 @@
     
+  %7D%0A
       %7D
+;
 %0A      
-    %7D);%0A      questionDialog.getChoicePanel().getCancelButton().addClickHandler(%0A          new DialogCancelHandler(
+DialogCancelHandler cancelHandler =%0A          new DialogCancelHandler(questionDialog);%0A%0A      // Apply handlers to OK and Cancel buttons.%0A      questionDialog.getChoicePanel().getOkButton().addClickHandler(okHandler);%0A      questionDialog.getChoicePanel().getCancelButton().addClickHandler(%0A          cancelHandler);%0A%0A      // Also apply handlers to %22Enter%22 and %22Esc%22 keys.%0A      questionDialog%0A          .addDomHandler(new ModalKeyHandler(okHandler, cancelHandler),%0A              KeyDownEvent.getType());%0A%0A      
 ques
@@ -2160,17 +2160,24 @@
 onDialog
-)
+.center(
 );%0A     
@@ -2192,23 +2192,60 @@
 nDialog.
-center(
+getChoicePanel().getOkButton().setFocus(true
 );%0A%0A    

Use ModelKeyHandler in logout dialog