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

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.DialogBox;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

import edu.colorado.csdms.wmt.client.data.ComponentJSO;
import edu.colorado.csdms.wmt.client.ui.handler.DialogCancelHandler;

/**
 * A dialog box used to display metadata (id, url, author, etc.) about a WMT
 * component.
 * 
 * @author Mark Piper (mark.piper@colorado.edu)
 */
public class ComponentInfoDialogBox extends DialogBox {

  private static String[] LABELS = {"summary", "url", "author"};
  private Grid grid;
  private ClosePanel closePanel;

  /**
   * Creates an {@link ComponentInfoDialogBox}. It must be populated later by
   * calling {@link ComponentInfoDialogBox#update()}.
   */
  public ComponentInfoDialogBox() {

    this.setAutoHideEnabled(false);
    this.setModal(false);

    grid = new Grid(LABELS.length, 2);
    grid.setCellPadding(5); // px

    for (int i = 0; i < LABELS.length; i++) {
      Label label = new Label(LABELS[i] + ":");
      label.getElement().getStyle().setMarginLeft(2, Unit.EM);
      grid.setWidget(i, 0, label);
      grid.getCellFormatter().setHorizontalAlignment(i, 0,
          HasHorizontalAlignment.ALIGN_RIGHT);
    }

    VerticalPanel contents = new VerticalPanel();
    contents.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    contents.add(grid);
    contents.setWidth("40em");

    closePanel = new ClosePanel();
    contents.add(closePanel);

    this.setWidget(contents);

    /*
     * Hides the dialog box.
     */
    closePanel.getButton().addClickHandler(new DialogCancelHandler(this));
  }

  /**
   * Updates the {@link ComponentInfoDialogBox} with information from the
   * input component.
   * 
   * @param componentJso a {@link ComponentJSO} instance
   */
  public void update(final ComponentJSO componentJso) {

    String title = componentJso.getName();
    if (componentJso.getVersion() != null) {
      title += " v" + componentJso.getVersion();
    }
    if (componentJso.getDoi() != null) {
      title += " (" + componentJso.getDoi() + ")";
    }
    this.setText(title);

    String url =
        "<a href='" + componentJso.getURL() + "'>" + componentJso.getURL()
            + "</a>";
    String[] info = {componentJso.getSummary(), url, componentJso.getAuthor()};

    HTML urlHtml = null;
    for (int i = 0; i < LABELS.length; i++) {
      if (url.equals(info[i])) {
        urlHtml = new HTML(info[i]);
        grid.setWidget(i, 1, urlHtml);
      } else {
        grid.setWidget(i, 1, new HTML(info[i]));
      }
    }

    /*
     *  Intercepts the click on the component URL and opens it in a new tab.
     */
    urlHtml.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
        event.preventDefault();
        Window.open(componentJso.getURL(), "componentInfoDialog", null);
      }
    });
  }
}

@@ -69,53 +69,8 @@
 s;%0A%0A
-import com.google.gwt.dom.client.Style.Unit;%0A
 impo
@@ -410,52 +410,8 @@
 nt;%0A
-import com.google.gwt.user.client.ui.Label;%0A
 impo
@@ -1152,24 +1152,32 @@
 dal(false);%0A
+        
 %0A    grid = 
@@ -1200,17 +1200,17 @@
 length, 
-2
+1
 );%0A    g
@@ -1247,308 +1247,43 @@
     
-for (int i = 0; i %3C LABELS.length; i++) %7B%0A      Label label = new Label(LABELS%5Bi%5D + %22:%22);%0A      label.getElement().getStyle().setMarginLeft(2, Unit.EM);%0A      grid.setWidget(i, 0, label);%0A      grid.getCellFormatter().setHorizontalAlignment(i, 0,%0A          HasHorizontalAlignment.ALIGN_RIGHT
+closePanel = new ClosePanel(
 );%0A    
-%7D%0A
 %0A   
@@ -1405,32 +1405,8 @@
 T);%0A
-    contents.add(grid);%0A
     
@@ -1428,49 +1428,37 @@
 th(%22
-40
+35
 em%22);%0A
-%0A
     c
-losePanel = new ClosePanel(
+ontents.add(grid
 );%0A 
@@ -2499,17 +2499,17 @@
 dget(i, 
-1
+0
 , urlHtm
@@ -2553,17 +2553,17 @@
 dget(i, 
-1
+0
 , new HT

Remove labels from ComponentInfoDialogBox