<commit_before>/**
 * <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 <NAME> (<EMAIL>)
 */
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.<commit_msg>Use ModelKeyHandler in logout dialog<commit_after>/**
 * <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 com.google.gwt.event.dom.client.KeyDownEvent;

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 <NAME> (<EMAIL>)
 */
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);

      // Define handlers.
      ClickHandler okHandler = new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
          DataTransfer.logout(data);
          questionDialog.hide();
        }
      };
      DialogCancelHandler cancelHandler =
          new DialogCancelHandler(questionDialog);

      // Apply handlers to OK and Cancel buttons.
      questionDialog.getChoicePanel().getOkButton().addClickHandler(okHandler);
      questionDialog.getChoicePanel().getCancelButton().addClickHandler(
          cancelHandler);

      // Also apply handlers to "Enter" and "Esc" keys.
      questionDialog
          .addDomHandler(new ModalKeyHandler(okHandler, cancelHandler),
              KeyDownEvent.getType());

      questionDialog.center();
      questionDialog.getChoicePanel().getOkButton().setFocus(true);

    } else {

      // Get WMT username.
{'fraction_non_alphanumeric': 0.10621387283236994, 'fraction_numerical': 0.0, 'mean_word_length': 3.3623949579831933, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4047087', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1210, 'n_words': 247}