package org.agmip.ui.quadui;

import java.io.IOException;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.zip.ZipOutputStream;
import java.util.zip.ZipEntry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.agmip.core.types.TranslatorOutput;

import com.google.common.io.Files;


public class TranslateRunner implements Runnable {
    private TranslatorOutput translator;
    private HashMap data;
    private String outputDirectory;
    private String model;
    private boolean compress;
    private static Logger LOG = LoggerFactory.getLogger(TranslateRunner.class);

    public TranslateRunner(TranslatorOutput translator, HashMap data, String outputDirectory, String model, boolean compress) {
        this.translator = translator;
        this.data = data;
        this.outputDirectory = outputDirectory;
        this.model = model;
        this.compress = compress;
    }


    @Override
    public void run() {
        LOG.debug("Starting new thread!");
        try {
            translator.writeFile(outputDirectory, data);
            if (compress) {
                compressOutput(outputDirectory, model);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void compressOutput(String outputDirectory, String model) throws IOException {
        File directory = new File(outputDirectory);
        File zipFile   = new File(directory, model+"_Input.zip");
        List<File> files   = Arrays.asList(directory.listFiles());
        FileOutputStream fos = new FileOutputStream(zipFile);
        ZipOutputStream  zos = new ZipOutputStream(fos);
        for(File f : files) {
            ZipEntry ze = new ZipEntry(f.getName());
            zos.putNextEntry(ze);
            zos.write(Files.toByteArray(f));
            zos.closeEntry();
            f.delete();
        }
        zos.close();
        fos.close();
    }
}

@@ -388,16 +388,74 @@
 .Files;%0A
+import java.util.Date;%0Aimport org.agmip.common.Functions;%0A
 %0A%0Apublic
@@ -1126,24 +1126,73 @@
  thread!%22);%0A
+        long timer = System.currentTimeMillis();%0A
         try 
@@ -1360,52 +1360,262 @@
     
-%7D catch (IOException e) %7B%0A            e.prin
+    timer = System.currentTimeMillis() - timer;%0A            LOG.info(%22%7B%7D Translator Finished in %7B%7Ds.%22, model, timer/1000.0);%0A        %7D catch (IOException e) %7B%0A            LOG.error(%22%7B%7D translator got an error.%22, model);%0A            LOG.error(Functions.ge
 tSta
@@ -1622,16 +1622,18 @@
 ckTrace(
+e)
 );%0A     

Add a few logs to show the status of translator running