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

import com.google.gwt.dom.client.Style.Cursor;
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.Grid;
import com.google.gwt.user.client.ui.HTML;

/**
 * Supplies a Grid with links for viewing or downloading the input
 * configuration files generated by the parameters set for a component in a
 * model.
 * 
 * @author Mark Piper (mark.piper@colorado.edu)
 */
public class ViewInputFilesPanel extends Grid {

  private String componentId;
  private String urlHtml;
  private String urlText;
  private String urlJson;

  /**
   * Creates a new ViewInputFilesPanel with links built for the current state
   * of a model component parameter.
   * 
   * @param componentId the id of the model component, a String
   */
  public ViewInputFilesPanel(String componentId) {

    super(1, 6);
    this.componentId = componentId;
    this.getElement().getStyle().setMarginTop(2, Unit.EM);
    this.setCellPadding(5); // px

    // TODO Should use DataURL.
    String baseURL = "http://csdms.colorado.edu/wmt/components/format/";
    urlHtml = baseURL + this.componentId + "?defaults=True&format=html";
    urlText = baseURL + this.componentId + "?defaults=True&format=text";
    urlJson = baseURL + this.componentId + "?defaults=True&format=json";
    HTML viewHTML = new HTML("<a href='" + urlHtml + "'>HTML</a>");
    HTML viewText = new HTML("<a href='" + urlText + "'>text</a>");
    HTML viewJSON = new HTML("<a href='" + urlJson + "'>JSON</a>");

    viewHTML.getElement().getStyle().setCursor(Cursor.POINTER);
    viewText.getElement().getStyle().setCursor(Cursor.POINTER);
    viewJSON.getElement().getStyle().setCursor(Cursor.POINTER);

    HTML viewTitle = new HTML("View input files:");
    viewTitle.setTitle("View the model configuration files generated by "
        + "these parameter values");

    this.setWidget(0, 0, viewTitle);
    this.setWidget(0, 1, viewHTML);
    this.setWidget(0, 2, new HTML("|"));
    this.setWidget(0, 3, viewText);
    this.setWidget(0, 4, new HTML("|"));
    this.setWidget(0, 5, viewJSON);

    viewHTML.addClickHandler(new InterceptClickHandler(urlHtml));
    viewText.addClickHandler(new InterceptClickHandler(urlText));
    viewJSON.addClickHandler(new InterceptClickHandler(urlJson));
  }

  /**
   * 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 {

    private String url;

    public InterceptClickHandler(String url) {
      this.url = url;
    }

    @Override
    public void onClick(ClickEvent event) {
      event.preventDefault();
      Window.open(url, "viewInputFiles", null);
    }
  }
}

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

import com.google.gwt.dom.client.Style.Cursor;
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.Grid;
import com.google.gwt.user.client.ui.HTML;

/**
 * Supplies a Grid with links for viewing or downloading the input
 * configuration files generated by the parameters set for a component in a
 * model.
 * 
 * @author Mark Piper (mark.piper@colorado.edu)
 */
public class ViewInputFilesPanel extends Grid {

  private String componentId;
  private String urlHtml;
  private String urlText;
  private String urlJson;

  /**
   * Creates a new ViewInputFilesPanel with links built for the current state
   * of a model component parameter.
   * 
   * @param componentId the id of the model component, a String
   */
  public ViewInputFilesPanel(String componentId) {

    super(1, 6);
    this.componentId = componentId;
    this.getElement().getStyle().setMarginTop(2, Unit.EM);
    this.setCellPadding(5); // px

    // TODO Should use DataURL.
    String baseUrl = "http://csdms.colorado.edu/wmt/components/format/";
    urlHtml = baseUrl + this.componentId + "?defaults=True&format=html";
    urlText = baseUrl + this.componentId + "?defaults=True&format=text";
    urlJson = baseUrl + this.componentId + "?defaults=True&format=json";
    HTML viewHtml = new HTML("<a href='" + urlHtml + "'>HTML</a>");
    HTML viewText = new HTML("<a href='" + urlText + "'>text</a>");
    HTML viewJson = new HTML("<a href='" + urlJson + "'>JSON</a>");

    viewHtml.getElement().getStyle().setCursor(Cursor.POINTER);
    viewText.getElement().getStyle().setCursor(Cursor.POINTER);
    viewJson.getElement().getStyle().setCursor(Cursor.POINTER);

    HTML viewTitle = new HTML("View input files:");
    viewTitle.setTitle("View the model configuration files generated by "
        + "these parameter values");

    this.setWidget(0, 0, viewTitle);
    this.setWidget(0, 1, viewHtml);
    this.setWidget(0, 2, new HTML("|"));
    this.setWidget(0, 3, viewText);
    this.setWidget(0, 4, new HTML("|"));
    this.setWidget(0, 5, viewJson);

    viewHtml.addClickHandler(new InterceptClickHandler(urlHtml));
    viewText.addClickHandler(new InterceptClickHandler(urlText));
    viewJson.addClickHandler(new InterceptClickHandler(urlJson));
  }

  /**
   * 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 {

    private String url;

    public InterceptClickHandler(String url) {
      this.url = url;
    }

    @Override
    public void onClick(ClickEvent event) {
      event.preventDefault();
      Window.open(url, "viewInputFiles", null);
    }
  }
}

Update variable names to align with GWT recommendation