KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > plugin > massivecompiler > FindThread


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * FindThread.java
28  *
29  * Created on 19 maggio 2004, 19.52
30  *
31  */

32
33 package it.businesslogic.ireport.plugin.massivecompiler;
34
35 import javax.swing.table.*;
36 import java.io.*;
37 /**
38  *
39  * @author Administrator
40  */

41 public class FindThread implements Runnable JavaDoc {
42     
43     private MassiveCompilerFrame massiveCompilerFrame = null;
44     private boolean stop = false;
45     private Thread JavaDoc thread = null;
46     
47     public FindThread(MassiveCompilerFrame mcf)
48     {
49         this.massiveCompilerFrame = mcf;
50         thread = new Thread JavaDoc(this);
51     }
52     
53     public void stop()
54     {
55         stop = true;
56     }
57     
58     public void start()
59     {
60         thread.start();
61     }
62     
63     public void run() {
64         if (massiveCompilerFrame == null)
65         {
66             return;
67         }
68         
69         // Prepare the file search....
70

71         DefaultTableModel dtm = (DefaultTableModel)massiveCompilerFrame.getFileTable().getModel();
72         
73         dtm.setRowCount(0);
74         massiveCompilerFrame.getFileTable().updateUI();
75         
76         // Path
77
File path = new File(massiveCompilerFrame.getFindDirectory());
78         
79         if (path == null || !path.exists() || path.isFile())
80         {
81             // Invalid conditions to search...
82
return;
83         }
84         
85         if (!stop) findFiles(path, massiveCompilerFrame.isSearchSubDirectory(),dtm);
86         
87         massiveCompilerFrame.finishedFind();
88         return;
89     }
90     
91     private int findFiles(File path, boolean recursive, DefaultTableModel tmodel)
92     {
93         if (stop) return 0;
94         int count = 0;
95         File[] files = path.listFiles();
96         for (int i=0; i<files.length; ++i)
97         {
98             if (stop) return 0;
99             if (files[i].isDirectory() && recursive)
100             {
101                 count += findFiles( files[i], recursive,tmodel);
102             }
103             else
104             {
105                 // Is the file a JasperReports source?
106
if (files[i].getName().toLowerCase().endsWith(".xml") ||
107                     files[i].getName().toLowerCase().endsWith(".jrxml"))
108                 {
109                     // Ok, for me is a good file, get it !
110
FileEntry fe = new FileEntry();
111                     fe.setFile( files[i] );
112                     
113                     // Looking for compiled and compilation version...
114

115                     
116                     // ....
117
fe.setStatus( fe.STATUS_NOT_COMPILED );
118                     tmodel.addRow( new Object JavaDoc[]{fe,fe,fe.decodeStatus(fe.getStatus())});
119                     
120                 }
121             }
122         }
123         
124         return count;
125     }
126     
127 }
128
Popular Tags