Switch to side-by-side view

--- a/tool/run/plugins/spdx/create.java
+++ b/tool/run/plugins/spdx/create.java
@@ -12,8 +12,10 @@
 
 package spdx;
 
+import GUI.swingUtils;
 import spdxlib.DocumentCreate;
 import definitions.Messages;
+import definitions.is;
 import java.io.File;
 import java.io.IOException;
 import java.util.logging.Level;
@@ -29,6 +31,8 @@
 import script.DownloadBigFile;
 import script.RunningTask;
 import utils.html;
+import www.Form;
+import www.RequestOrigin;
 import www.WebRequest;
 
 
@@ -40,9 +44,9 @@
 public class create extends Plugin{
     
     final String 
-            LastFolderNewSPDX = "LastFolderNewSPDX",
-            id = "Create New SPDX";
-    
+            id = "Create SPDX",
+            LastFolderNewSPDX = "LastFolderNewSPDX";
+            
     final String acceptedExtension = 
             ".tar.gz"
             + ">>"
@@ -61,6 +65,11 @@
      */
     public void addNode(){
         addTreeNode(id, "box--plus.png", "main");
+        
+        addChildNode("from web", "application-dock-270.png", "mainWeb");
+        addChildNode("from folder", "folder-smiley.png", "mainFolder");
+        addChildNode("from zipped file", "vise-drawer.png", "mainZip");
+        
     }
     
     /**
@@ -69,8 +78,170 @@
      */
     @Override
     public void main(WebRequest request){
+       //request.setPage("spdxDialog.html");
+        String result = "<html>\n" +
+            "<head>\n" +
+            "<style type=\"text/css\">body {font-family:verdana,arial,"
+                + "sans-serif;font-size:10pt;margin:30px;}</style>"
+                + "</head>\n" +
+            "\n" +
+            "<body>"
+                + ""
+                + "Testing stuff!"
+                + ""
+                + "</body>"
+                + "</html>";
+        request.setAnswer(result);
+    }
+
+    
+    public void mainWeb(WebRequest request){
        request.setPage("spdxDialog.html");
     }
+
+    
+    public void mainZip(WebRequest request){
+        //request.setPage("spdxDialog.html");
+        String result = "Hello there Zip!";
+        request.setAnswer(result);
+    }
+
+ 
+    /**
+     * Dialog for creating a new SPDX document from a folder on disk
+     * @param request 
+     */
+    public void mainFolder(WebRequest request){
+        // no support for requests from the browser
+//        if(request.requestOrigin == RequestOrigin.BROWSER){
+//            log.write(is.ERROR, "Support to SPDX creation from folder on disk "
+//                    + "is not yet implemented");
+//            return;
+//        }
+        
+        // get the value used before
+        String selectedFolder = settings.read(LastFolderNewSPDX, "");
+        
+        // if nothign is chosen, just show it as "none"
+        if(selectedFolder.isEmpty()){
+            selectedFolder = "NONE";
+        }
+        
+        String result = 
+                  html.div()
+                + html.h2("Create a new SPDX from folder on disk")
+                + "Use this page to create an SPDX document from a given "
+                + "folder on your disk. "
+                + html.br
+                + html.br
+                + html.h3("Selected Folder")
+                + selectedFolder
+                + html.br
+                
+                + html.br
+                + html.link("Choose a folder", "create?x=folder")
+                
+                + html.br
+                + html.br
+                + html.link("Start", "create?x=foldercreate")
+                
+                
+                + html._div
+                ;
+        
+        request.setAnswer(result);
+    }
+
+    
+    
+    /**
+     * Chooses a folder to be used as source for creating a new SPDX
+     * @param request 
+     */
+    public void foldercreate(WebRequest request){
+        // what should we use as source?
+        String selectedFolder = settings.read(LastFolderNewSPDX);
+        // start our action
+        log.write(is.INFO, "Creating an SPDX document using as source: %1", 
+               selectedFolder );
+        
+        // transform the thing into a file pointer
+        final File source = new File(selectedFolder);
+        
+        if(source.exists() == false){
+            // we have a problem, exit here
+            log.write(is.ERROR, "SPDX create - Source folder doesn't exist: %1",
+                    source.getAbsolutePath());
+            return;
+        }
+        
+        final WebRequest what = request;
+        
+        RunningTask task = new RunningTask(){
+            @Override
+            public void doTask(){
+                setTitle("Creating SPDX from source folder");
+               
+
+               // third step, create the SPDX document from the extracted files
+               String result = createDocument(source, this);
+               
+               // all done here, explain where the SPDX document can be found
+               nextStep = 
+                         html.link("SPDX summary", 
+                        "/spdx/show?x=summary&"
+                        + param.spdx + "=" + result)
+                       + " | " +
+                       html.link("Show full text", 
+                        "/spdx/show?x=full&"
+                        + param.spdx + "=" + result)
+                       ;
+               
+             }
+        };
+        task.launch();
+        
+        
+        //request.setAnswer("Process launched as " + task.getUID());
+        request.setAnswer(utils.html.redirect("/basic/status"
+                + "?ID=" + task.getUID(), 0, ""));
+        
+    }
+
+    
+    
+    /**
+     * Chooses a folder to be used as source for creating a new SPDX
+     * @param request 
+     */
+    public void folder(WebRequest request){
+        // no support for requests from the browser
+        if(request.requestOrigin == RequestOrigin.BROWSER){
+            log.write(is.ERROR, "Support to SPDX creation from folder on disk "
+                    + "is not yet implemented");
+            request.setAnswer("Not supported from browser");
+            return;
+        }
+        
+        // do we want an older located defined?
+        String selectedFolder = settings.read(LastFolderNewSPDX);
+        
+        
+        // show the dialog
+        File result = swingUtils.chooseFolder(new File(selectedFolder));
+        
+        // place the result in our settings
+        if(result != null){
+            settings.write(LastFolderNewSPDX, result.getAbsolutePath());
+        }
+        
+        String output = html.redirect("/spdx/create?x=mainFolder", 2, 
+                       " Returning to previous page..");
+        
+        request.setAnswer(output);
+        
+    }
+  
     
     /**
      * The part where we create the SPDX document