package edu.colorado.csdms.wmt.client.ui;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;

import edu.colorado.csdms.wmt.client.control.DataURL;

/**
 * A dialog box that shows information about a successfully submitted model
 * run.
 * 
 * @author Mark Piper (mark.piper@colorado.edu)
 */
public class RunInfoDialogBox extends DialogBox {

  private static String MSG =
      "<h2>Success!</h2><p>You have submitted your model run.</p>"
          + "<p>Check the status of the run by selecting "
          + "<b>View Run Status...</b> under the "
          + "<i class='fa fa-bars fa-lg'></i> menu, or by visiting:</p>"
          + "<a href='https://csdms.colorado.edu/wmt/run/show'>"
          + "https://csdms.colorado.edu/wmt/run/show</a>";

  /**
   * Displays a {@link RunInfoDialogBox}.
   */
  public RunInfoDialogBox() {

    super(true); // autohide
    this.setModal(true);
    this.setText("Model Run Information");

    VerticalPanel contents = new VerticalPanel();
    contents.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    contents.setWidth("25em");
    
    HTML msgHtml = new HTML(MSG);
    contents.add(msgHtml);
    
    Button closeButton = new Button("<i class='fa fa-times'></i> Close");
    closeButton.getElement().getStyle().setMarginTop(1, Unit.EM);
    closeButton.getElement().getStyle().setMarginBottom(0.5, Unit.EM);
    contents.add(closeButton);
    
    this.setWidget(contents);
    
    msgHtml.addClickHandler(new InterceptClickHandler());
    closeButton.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
        RunInfoDialogBox.this.hide();
      }
    });
  }

  /**
   * Intercepts the click on the link in the HTML, text or JSON cell and
   * directs it to open in another tab/window.
   */
  public class InterceptClickHandler implements ClickHandler {
    @Override
    public void onClick(ClickEvent event) {
      event.preventDefault();
      Window.open(DataURL.showModelRun(), "viewInputFiles", null);
    }
  }
}

@@ -1822,44 +1822,22 @@
 s);%0A
+%0A
     
+/*
 %0A    
-msgHtml.addClickHandler(new
+ *
  Int
@@ -1846,40 +1846,85 @@
 cept
-C
+s c
 lick
-Handler());%0A    closeButton
+ on link in dialog and opens the URL in a new tab.%0A     */%0A    msgHtml
 .add
@@ -2031,215 +2031,183 @@
     
-RunInfoDialogBox.this.hide();%0A      %7D%0A    %7D);%0A  %7D%0A%0A  /**%0A   * Intercepts the click on the link in the HTML, text or JSON cell and%0A   * directs it to open in another tab/window.%0A   */%0A  public class Intercept
+event.preventDefault();%0A      Window.open(DataURL.showModelRun(), %22viewInputFiles%22, null);%0A      %7D%0A    %7D);%0A    %0A    /*%0A     * Hides the dialog box.%0A     */%0A    closeButton.add
 Clic
@@ -2218,19 +2218,12 @@
 dler
- implements
+(new
  Cli
@@ -2231,23 +2231,27 @@
 kHandler
+()
  %7B%0A    
+ 
+ 
 @Overrid
@@ -2248,24 +2248,26 @@
   @Override%0A
+  
     public v
@@ -2308,104 +2308,55 @@
     
-event.preventDefault();%0A      Window.open(DataURL.showModelRun(), %22viewInputFiles%22, null);
+  RunInfoDialogBox.this.hide();%0A      %7D
 %0A    %7D
+);
 %0A  %7D

Remove custom click event handler from RunInfoDialogBox