Switch to side-by-side view

--- a/tool/run/plugins/spdx/show.java
+++ b/tool/run/plugins/spdx/show.java
@@ -16,6 +16,7 @@
 package spdx;
 
 import GUI.swingUtils;
+import definitions.Messages;
 import definitions.is;
 import java.io.File;
 import www.Table;
@@ -39,6 +40,20 @@
 public class show extends Plugin{
    
     
+    String showSPDX = "showSPDX";
+    
+    @Override
+    public void startup(){
+        // add our node to the tree right after the "Tools" node is added
+        log.hooks.addAction(Messages.RefreshSPDX, thisFile, "refreshCache");
+    }
+    
+    /**
+     * Cache our front page to speed up loading time when clicked by end user
+     */
+    void refreshCache(){
+        log.write(is.ACCEPTED, "Re-doing our cache again");
+    }
     
     /**
      * Shows a summary of details about the selected package
@@ -53,7 +68,6 @@
                 ;
         
         
-        
         // get some statistical data
         for(Object object : core.products){
             SPDXfile spdx = (SPDXfile) object;
@@ -73,11 +87,12 @@
                 html.div()
                 + "<h2>"
                 //+ html.getCommonFolderIcon("wooden-box-label.png")
-                + "SPDX archive"
+                + "SPDX documents"
                 + "</h2>"
                 + html._div
                 + html.div(20)
                 //+ html.getCommonFolderIcon("documents-stack.png")
+                + core.products.size() + " SPDX documents containing "
                 + counterFiles + " files in total" 
                 + html.br
                 //+ html.getCommonFolderIcon("calculator.png")
@@ -85,6 +100,8 @@
                 + percentage
                 //+ html.getCommonFolderIcon("stickman.png")
                 + counterCreators + " SPDX creators" + html.br
+                + html.br
+                + listFilesSPDX(request)
                 //+ html.br
                 + html._div
                 + html.br
@@ -93,8 +110,115 @@
         // provide an answer
         request.setAnswer(result);
     }
+ 
+    /**
+     * List all the files that are on the disk
+     */
+    private String listFilesSPDX(WebRequest request){
+        
+//        String[] line = new String[]{"SPDX", "Last modified"};
+        
+//        Table table = new Table(line);
+        
+        String result = "";
+//        for(SPDXfile product : core.products){
+//            String lastModified = utils.time.getTimeFromLong
+//                (product.file.lastModified());
+//            
+//            line = new String[]{product.getId(), lastModified};
+//            table.add(line);
+////        }
+        
+        result = findFiles(core.getProductsFolder(), 25, request);
+        
+        return result;           
+    }
+  
+    
+    
+    
+    /**
+     * Find all files in a given folder and respective subfolders
+     * @param where A file object of the start folder
+     * @param maxDeep How deep is the crawl allowed to proceed
+     * @param request
+     * @return An array containing all the found files, returns null if none is
+     * found
+     */
+    public String findFiles(File where, int maxDeep, WebRequest request){
 
-  
+    File[] files = where.listFiles();
+    String result = "";
+    
+    int[] sizes = new int[]{10,200};
+    
+    if(files != null)
+    for (File file : files) {
+      if (file.isFile()){
+         String filePath = file.getAbsolutePath();
+         // we only want .spdx files
+         if(filePath.endsWith("spdx")){
+             
+            // remove the local disk path with a generic one
+             String filteredPath = "." 
+                     + file.getAbsolutePath().replace(core.getProductsFolder()
+                             .getAbsolutePath(), "");
+             
+             String fileLink = html.link(file.getName(), 
+                             "?x=summary&spdx="
+                             + filteredPath
+                             + "");
+             
+             
+           result +=  Table.alignedTable(new String[]{
+                 html.getIcon("document-text.png", request), 
+                 fileLink},
+                 sizes);
+             
+            
+      }
+         
+      }
+      else
+      if ( (file.isDirectory())
+         &&( maxDeep-1 > 0 ) ){
+            String folderName = file.getName();
+            // do the recursive crawling
+            String temp = findFiles(file, maxDeep-1, request);
+            // we don't need empty folders
+            if(temp.length() == 0){
+                continue;
+            }
+            
+            String folderText = Table.alignedTable(new String[]{
+                 html.getIcon("folder-horizontal-open.png", request), 
+                 folderName},
+                 sizes);
+            
+            String current = 
+                    html.div()
+                    + folderText
+                    //+ html.br
+                    + html.div()
+                    + temp
+                    + html._div
+                    + html._div;
+
+            // add a pretty paragraph
+            if(maxDeep == 25){
+                current = html.br + current;
+            }
+            
+            result += current;
+            
+            
+      }
+    
+    }
+    
+    return result;
+    }
+    
     /**
      * Verifies if a given SPDX document exists inside our archive or or not
      * @param spdxTarget The file inside the SPDX Archive
@@ -109,7 +233,7 @@
         File file = new File(core.getProductsFolder(), spdxTarget);
         // this file needs to exist
         if((file.exists() == false) || (file.isDirectory())){
-            request.setAnswer("File was not found in our archive, sorry");
+            request.setAnswer("Sorry, the file was not found: " + spdxTarget);
             return null;
         }
         // all done
@@ -147,6 +271,14 @@
         if(file == null){
             return;
         }
+        
+//        String cache = (String) core.temp.get(showSPDX);
+//        if(cache != null){
+//            log.write(is.COMPLETED, "Using the cached version of show SPDX");
+//            request.setAnswer(cache);
+//            return;
+//        }
+        
         
         // get the SPDX file from the root node
         SPDXfile spdx = new SPDXfile(file);
@@ -225,6 +357,9 @@
                         + param.spdx + "=" + spdxTarget)
                 + html._div
                 + "";
+        
+        // save our cache for next time
+        core.temp.put(showSPDX, result);
         
         // write everything on our UI text area
         request.setAnswer(result);