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

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
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.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

import edu.colorado.csdms.wmt.client.control.DataTransfer;
import edu.colorado.csdms.wmt.client.data.ModelComponentParametersJSO;

public class ViewInputFilesDialogBox extends DialogBox {

  public ViewInputFilesDialogBox(ModelComponentParametersJSO jso, String type) {

    super(false); // autohide
    this.setModal(false);
    this.setText("View Input Files");

    Integer nKeys = jso.getKeys().length();
    String content;
    if (nKeys == 0) {
      content = "No files are available for this component";
    } else {
      String key = jso.getKeys().get(0);
      String value = jso.getValues().get(0);
      if (type.matches("text")) {
        content =
            "<p><pre>" + key + "</pre></p>" + "<p><pre>" + value + "</pre></p>";
      } else if (type.matches("html")) {
        content = "<h2>" + key + "</h2>" + "<p><pre>" + value + "</pre></p>";
      } else {
        content = DataTransfer.stringify(jso);
      }
    }
    HTML html = new HTML(content);

    ScrollPanel scrollPanel = new ScrollPanel();
    scrollPanel.setSize("500px", "400px");
    scrollPanel.add(html);

    ChoicePanel choicePanel = new ChoicePanel();
    choicePanel.getOkButton().setHTML("<i class='fa fa-save'></i> Save");

    VerticalPanel panel = new VerticalPanel();
    panel.add(scrollPanel);

    VerticalPanel mainPanel = new VerticalPanel();
    mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    mainPanel.add(panel);
    mainPanel.add(choicePanel);

    this.setWidget(mainPanel);

    choicePanel.getCancelButton().addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
        ViewInputFilesDialogBox.this.hide();
      }
    });
  }

}

@@ -823,16 +823,21 @@
  content
+ = %22%22
 ;%0A    if
@@ -866,16 +866,17 @@
 content 
++
 = %22No fi
@@ -923,24 +923,66 @@
    %7D else %7B%0A
+      for (int i = 0; i %3C nKeys; i++) %7B%0A  
       String
@@ -1002,28 +1002,30 @@
 tKeys().get(
-0
+i
 );%0A
+  
       String
@@ -1057,12 +1057,14 @@
 get(
-0
+i
 );%0A
+  
     
@@ -1089,24 +1089,26 @@
 (%22text%22)) %7B%0A
+  
         cont
@@ -1115,10 +1115,13 @@
 ent 
++
 =%0A
+  
     
@@ -1172,32 +1172,50 @@
 p%3E%3Cpre%3E%22 + value
+%0A                 
  + %22%3C/pre%3E%3C/p%3E%22;
@@ -1207,32 +1207,34 @@
 + %22%3C/pre%3E%3C/p%3E%22;%0A
+  
       %7D else if 
@@ -1266,24 +1266,26 @@
         
+ 
+ 
 content 
 = %22%3Ch2%3E%22
@@ -1276,16 +1276,17 @@
 content 
++
 = %22%3Ch2%3E%22
@@ -1341,24 +1341,26 @@
 /p%3E%22;%0A      
+  
 %7D else %7B%0A   
@@ -1352,24 +1352,26 @@
    %7D else %7B%0A
+  
         cont
@@ -1374,16 +1374,17 @@
 content 
++
 = DataTr
@@ -1406,16 +1406,26 @@
 y(jso);%0A
+        %7D%0A
       %7D%0A

Fix bug when displaying multiple input files