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

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.ui.widgets.OpenDialogBox;

/**
 * Handles click on the "Open Model..." button in the ModelActionPanel. Pops up an
 * instance of {@link OpenDialogBox} to prompt the user for a model to open.
 * Events are sent to {@link OpenModelHandler} and {@link DialogCancelHandler}.
 */
public class ModelActionPanelOpenHandler implements ClickHandler {

  private DataManager data;
  private OpenDialogBox openDialog;

  /**
   * Creates a new instance of {@link ModelActionPanelOpenHandler}.
   * 
   * @param data the DataManager object for the WMT session
   */
  public ModelActionPanelOpenHandler(DataManager data) {
    this.data = data;
  }

  @Override
  public void onClick(ClickEvent event) {

    openDialog = new OpenDialogBox(data);

    // Populate the droplist with the available models on the server.
    for (int i = 0; i < data.modelNameList.size(); i++) {
      openDialog.getDroplistPanel().getDroplist().addItem(
          data.modelNameList.get(i));
    }

    openDialog.getChoicePanel().getOkButton().addClickHandler(
        new OpenModelHandler(data, openDialog));
    openDialog.getChoicePanel().getCancelButton().addClickHandler(
        new DialogCancelHandler(openDialog));

    openDialog.center();

    // Give the droplist focus.
    openDialog.getDroplistPanel().getDroplist().setFocus(true);    
  }
}

@@ -164,24 +164,181 @@
 lickHandler;
+%0Aimport com.google.gwt.event.dom.client.KeyCodes;%0Aimport com.google.gwt.event.dom.client.KeyDownEvent;%0Aimport com.google.gwt.event.dom.client.KeyDownHandler;
 %0A%0Aimport edu
@@ -536,14 +536,14 @@
 s up
- an
 %0A *
+ an
  ins
@@ -664,39 +664,160 @@
 er%7D 
-and %7B@link DialogCancelHandler%7D
+(on clicking %22OK%22 button or%0A * hitting %3Ccode%3EEnter%3C/code%3E key) and %7B@link DialogCancelHandler%7D (on clicking%0A * %22Cancel%22 or hitting %3Ccode%3EEsc%3C/code%3E key)
 .%0A *
@@ -1519,113 +1519,364 @@
     
-openDialog.getChoicePanel().getOkButton().addClickHandler(%0A        new OpenModelHandler(data, openDialog)
+// Define open and cancel handlers.%0A    final OpenModelHandler openHandler = new OpenModelHandler(data, openDialog);%0A    final DialogCancelHandler cancelHandler =%0A        new DialogCancelHandler(openDialog);%0A%0A    // Set the open and cancel handlers on the %22OK%22 and %22Cancel%22 buttons.%0A    openDialog.getChoicePanel().getOkButton().addClickHandler(openHandler
 );%0A 
@@ -1915,32 +1915,41 @@
 etCancelButton()
+%0A        
 .addClickHandler
@@ -1953,51 +1953,533 @@
 ler(
-%0A        new DialogCancelHandler(openDialog
+cancelHandler);%0A%0A    // Also use the handlers for the %22Enter%22 and %22Esc%22 keys.%0A    // XXX There's likely a more stylish way to do this.%0A    openDialog.addDomHandler(new KeyDownHandler() %7B%0A      @Override%0A      public void onKeyDown(KeyDownEvent event) %7B%0A        Integer keyCode = event.getNativeKeyCode();%0A        if (keyCode == KeyCodes.KEY_ESCAPE) %7B%0A          cancelHandler.onClick(null);%0A        %7D else if (keyCode == KeyCodes.KEY_ENTER) %7B%0A          openHandler.onClick(null);%0A        %7D%0A      %7D%0A    %7D, KeyDownEvent.getType(
 ));%0A
@@ -2600,19 +2600,15 @@
 s(true);
-    
 %0A  %7D%0A%7D%0A

Add "Enter" and "Esc" shortcuts to model open dialog