/*
    CommandTemplate

    Note: 
     1. You should include this class "After uninstaller created" on the Custom panel.
     2. You must change this class to do whatever you want it to do. In the original form, it'
        trying to run a program called mySpecialInstallerExecutable. Of course, you'd want to
        rename this to whatever program you want to run and if the program isn't cross platform,
        address that in the section of the code marked by <-------> comment lines.
     3. You're welcome to adapt this class to use with a JExpress Installer or Updater.
     
    Copyright (C) 1998-2012 DeNova
    Last modified: 2012-02-24
*/

import com.denova.runtime.Exec;
import com.denova.ui.Fonts;
import com.denova.ui.Swinger;
import com.denova.util.PropertyList;
import com.denova.JExpress.Installer.CustomInstaller;
import com.denova.JExpress.Installer.InstallPropertyNames;
import com.denova.JExpress.Installer.StatusPanel;
import java.awt.BorderLayout;
import java.io.File;
import javax.swing.JLabel;


public class CommandTemplate
    extends StatusPanel
    implements InstallPropertyNames
{
    // you'd need to include this file in the list on the Files panel in JExpress Developer
    private static final String SpecialInstallerFilename = "mySpecialInstallerExecutable";
    private String progressLabel = "Running " + SpecialInstallerFilename;

    private class CommandSwinger extends Swinger
    {
        public void swingBefore()
        {
            updateProgressBarLabel(progressLabel);
        }
        
        public void workInBackground()
        {
            // change the code from here <------------------>
            String applicationDirectory = getPropertyList ().getProperty ( 
                                                  ApplicationDirectory, 
                                                  "" );
            File f = new File( applicationDirectory, 
                               SpecialInstallerFilename );
    
            if ( f.exists () ) {
    
                try {
    
                    String [] command = { f.getPath (), SpecialInstallerFilename };
                    Exec.runCommand ( command );
                    CustomInstaller.logToInstaller ( SpecialInstallerFilename + " run" );
                }
                catch ( Exception e ) {
                    CustomInstaller.logException ( "Unable to install", 
                                                   e );
                }
            }
            else {
                CustomInstaller.logToInstaller ( "Special installer (" + SpecialInstallerFilename + ") is not located in " + applicationDirectory + "\nUnable to install." );
            }
            // to here <------------------>
        }
        
        public void swingAfter()
        {
            // since there's no user interaction, simply move to the next panel
            showNextPanel ();
        }
    }
    
    
    /**
     * Creates a new CommandTemplate object.
     * 
     * @param properties installer's properties
     */
    public CommandTemplate (PropertyList properties)
    {
        super (properties);
        
        updateProgressBarLabel(progressLabel);
    }

    /** 
     * Enter the panel. Method where the work for the class is done.
     *
     * See RunThirdPartyProgram for a more complete example.
     *
     * Do not call this method; only the wizard should call it.
     */
    public synchronized void enter()
    {
        CommandSwinger swinger = new CommandSwinger();
        swinger.execute();
    }

}