/*
    MoveTomCat.java
    Move files from the installation directory to another directory
      -- currently configured to move the "tomcat" subdirectory to 
      C:\Tomcat on Windows

    Notes: 
     1. Currently, configured to move the "tomcat" subdirectory to C:\Tomcat on Windows.
     2. You must include the "tomcat" subdirectory in the Files panel; the files must be
        in the root of the installation directory, not in a subdirectory
     3. You must include this class file "After uninstaller created" in the Customs panel
     4. If you want to adapt this class to move other files to a different 
        destination, then change the destinationDir and the files that you want moved
     5. You are welcome to adapt this to meet your needs as long as you 
        only use it with the JExpress product

    Copyright 2013 DeNova
    
*/
import java.awt.BorderLayout;


import java.io.File;
import com.denova.ui.Swinger;
import com.denova.util.PropertyList;
import com.denova.JExpress.Installer.CustomInstaller;
import com.denova.JExpress.Installer.CustomUninstaller;
import com.denova.JExpress.Installer.InstallPropertyNames;
import com.denova.JExpress.Installer.StatusPanel;

public class MoveTomCat extends StatusPanel
                       implements InstallPropertyNames {

    private String progressLabel = "Copying files";
    private boolean panelActivated = false;
    
    
    private class TomCatSwinger extends Swinger
    {
        public void swingBefore()
        {
            updateProgressBarLabel(progressLabel);
        }
        
        public void workInBackground()
        {
            File appDir = new File(getPropertyList ().getProperty(ApplicationDirectory, ""));
        
            // setup to add commands to the uninstaller to remove the files we move
            CustomUninstaller customUninstaller = new CustomUninstaller();
            
            File fromFile = new File(appDir, "tomcat");
            File toFile = new File ("C:\tomcat");
                            
            try {
                // the destination directory must exist before the copy
                toFile.mkdirs();
                com.denova.io.FileSystem.copyDirectory(fromFile, toFile);

                // remove the directory when we delete the app
                customUninstaller.deleteDirTree(toFile.getPath());
            }
    
            catch ( Exception e ) {
                CustomInstaller. logException ( "Unable to copy directory",
                                                e );
            }
            
            customUninstaller.append(appDir. getPath ());
        }
        
        public void swingAfter()
        {
            panelActivated = true;
            
            // since there's no user interaction, simply move to the next panel
            showNextPanel ();
        }
    }
    
    
    public MoveTomCat(PropertyList properties) {

        super(properties);
        
        updateProgressBarLabel(progressLabel);
    }

    /** 
     * Enter the panel. 
     *
     * Do not call this method; only the wizard should call it.
     */
     public synchronized void enter()
     {
        if (!isWindows() || panelActivated)
        {
            showNextPanel();
        }
        
        else
        {
            TomCatSwinger swinger = new TomCatSwinger();
            swinger.execute();
        }
    }

}