KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > nodes > InstallMultipleFile


1 /* $Id$
2  *
3  * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  */

15
16 //
17
// DESCRIPTION
18
//
19
// Peter Pilgrim
20
// Wed Jan 20 00:29:21 GMT 1999
21
//
22
// RCS HEADER ``InstallMultipleFile.java''
23
//
24
// $Author$
25
// $Date$
26
// $Source$
27
// $Revision$ $State$ $Locker$
28
//
29

30 package ixenon.free.nodes;
31
32 import java.io.*;
33 import java.util.*;
34 import java.awt.*;
35 import java.awt.event.*;
36
37 import javax.swing.*; // for JTree
38
import javax.swing.event.*; // for events
39
import javax.swing.tree.*; // MutableTreeNode
40

41 import ixenon.free.swing.*; // for `ResetProgressBar' & `UpdateProgressBar'
42
import ixenon.free.install.*; // for FreeInstallerApplication
43

44 /**
45 import ixenon.free.uninstall.*; // for Uninstallable
46  * An <code>Installable</code> node that knows how install
47  * a large number of files by copying.
48  */

49 public class InstallMultipleFile extends AbstractInstallable
50 implements Installable
51 {
52     public final static int SLEEP_TIME=50; // Sleep time
53

54     protected File sourceDirectory;
55     protected File targetDirectory;
56     protected int perms;
57     protected Vector fileList; // list of filenames to install
58

59     /**
60      * Construct a multiple installable
61      *
62      * @param nodeName the name of the installable node
63      * @param sourceDir the source file directory
64      * @param destDir the target file directory
65      * @param filename single filename
66      * @param perms the installation permissions
67      */

68     public InstallMultipleFile( String JavaDoc nodeName,
69                 int perms,
70                 String JavaDoc srcDir,
71                 String JavaDoc destDir,
72                 String JavaDoc filename )
73     {
74     this( nodeName, perms, new File(srcDir), new File(destDir),
75           new String JavaDoc [] { filename } );
76     }
77
78     /**
79      * Construct a multiple installable
80      * Construct a installable
81      *
82      * @param nodeName the name of the installable node
83      * @param sourceDir the source file directory
84      * @param destDir the target file directory
85      * @param filename single filename
86      * @param perms the installation permissions
87      *
88      * @see InstallUtilities#setFilePermissions
89      */

90     public InstallMultipleFile( String JavaDoc nodeName,
91                 int perms,
92                 File srcDir,
93                 File destDir,
94                 String JavaDoc filename )
95     {
96     this( nodeName, perms, srcDir, destDir, new String JavaDoc [] { filename } );
97     }
98
99
100     /**
101      * Construct a multiple installable
102      *
103      * @param nodeName the name of the installable node
104      * @param sourceDir the source file directory
105      * @param destDir the target file directory
106      * @param filenames array of filename strings
107      * @param perms the installation permissions
108      *
109      * @see InstallUtilities#setFilePermissions
110      */

111     public InstallMultipleFile( String JavaDoc nodeName,
112                 int perms,
113                 String JavaDoc srcDir,
114                 String JavaDoc destDir,
115                 String JavaDoc [] filenames )
116     {
117     this( nodeName, perms, new File(srcDir), new File(destDir), filenames );
118     }
119     
120     /**
121      * Construct a multiple installable
122      *
123      * @param nodeName the name of the installable node
124      * @param sourceDir the source file directory
125      * @param destDir the target file directory
126      * @param filename array of filename strings
127      * @param perms the installation permissions
128      *
129      * @see InstallUtilities#setFilePermissions
130      */

131     public InstallMultipleFile( String JavaDoc nodeName,
132                 int perms,
133                 File sourceDir,
134                 File targetDir,
135                 String JavaDoc [] filenames )
136     {
137     super( nodeName, null, true /*allowsChildren*/ );
138     this.nodeName = nodeName;
139     this.perms = perms;
140     sourceDirectory = sourceDir;
141     targetDirectory = targetDir;
142     fileList = new Vector();
143     for (int j=0; j<filenames.length; ++j)
144         if ( filenames[j] != null )
145         fileList.addElement( filenames[j] );
146     }
147     
148     /**
149      * create or retrieve the visual component of the installable
150      * if one exists. Otherwise return null.
151      */

152     public Component getVisualComponent()
153     {
154     return (null);
155     }
156     
157     /**
158      * create or retrieve the configurable component of the installable
159      * if one exists. Otherwise return null object.
160      */

161     public Component getConfigurableComponent()
162     {
163     return (null);
164     }
165
166     /**
167      * method to install by copying files from the source
168      * directory to target directory
169      *
170      * @exception <code>InstallException</code> if there is an
171      * problem trying to install the entity.
172      */

173     public void install() throws InstallException
174     {
175     FreeInstallerApplication theApp =
176         FreeInstallerApplication.getInstance();
177
178     if ( !sourceDirectory.isDirectory() )
179         throw new InstallException("no such source directory:`"+sourceDirectory.getAbsolutePath()+"'" );
180
181     if ( !targetDirectory.exists() )
182         targetDirectory.mkdirs();
183
184     if ( !targetDirectory.isDirectory() )
185         throw new InstallException(
186         "no such target directory:`"+targetDirectory.getAbsolutePath()+"'" );
187
188     // Add target directory to the uninstallable
189
uninstallable.addFile( targetDirectory );
190
191     // Install multiple regular files
192
JProgressBar pbar = theApp.getProgressFrame().getProgressBarNode();
193     JProgressBar pbarFile = theApp.getProgressFrame().getProgressBarFile();
194     int numFiles = fileList.size();
195
196     // // OLD CODE: Not Swing/Thread safe!
197
// pbar.setMinimum(0);
198
// pbar.setMaximum(numFiles);
199
// theApp.getProgressFrame().setStatusText( getNodeName() );
200
SwingUtilities.invokeLater( new ResetProgressBar( pbar, 0, numFiles, 0 ) );
201
202     for (int j=0; j<fileList.size(); ++j) {
203         // OLD CODE: pbar.setValue(j+1);
204
SwingUtilities.invokeLater( new UpdateProgressBar( pbar, j+1 ) );
205         
206         try { Thread.sleep(SLEEP_TIME); } catch (InterruptedException JavaDoc ie) { ; }
207
208         String JavaDoc filename = (String JavaDoc)fileList.elementAt(j);
209         File srcFile = new File( sourceDirectory, filename );
210         if ( !srcFile.exists() ) {
211         if (pedantic)
212             throw new InstallException(
213             "["+j+"] no such explicit file:`" + srcFile.getPath() +"'");
214         else
215             theApp.printWarning( "["+j+"] no such explicit file:`" + srcFile.getPath() +"'" );
216         continue;
217         }
218         if ( srcFile.isFile() ) {
219         // Only copy normal files
220
File dstFile = new File( targetDirectory, filename );
221         theApp.printInfo( "["+j+"] explicit copying: `" + srcFile.getPath() + "' to `" + dstFile.getPath()+"'" );
222         InstallUtilities.copyFile( pbarFile, srcFile, dstFile, true );
223         InstallUtilities.setFilePermissions( dstFile, perms );
224         uninstallable.addFile( dstFile );
225         }
226     }
227     }
228
229     /**
230      * method to perform the cleanup of content if cancelled, or aborted
231      */

232     public void cleanup() throws InstallException
233     {
234     // empty
235
}
236 }
237
238 // fini
239
Popular Tags