001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * FindThread.java
028: *
029: * Created on 19 maggio 2004, 19.52
030: *
031: */
032:
033: package it.businesslogic.ireport.plugin.massivecompiler;
034:
035: import javax.swing.table.*;
036: import java.io.*;
037:
038: /**
039: *
040: * @author Administrator
041: */
042: public class FindThread implements Runnable {
043:
044: private MassiveCompilerFrame massiveCompilerFrame = null;
045: private boolean stop = false;
046: private Thread thread = null;
047:
048: public FindThread(MassiveCompilerFrame mcf) {
049: this .massiveCompilerFrame = mcf;
050: thread = new Thread(this );
051: }
052:
053: public void stop() {
054: stop = true;
055: }
056:
057: public void start() {
058: thread.start();
059: }
060:
061: public void run() {
062: if (massiveCompilerFrame == null) {
063: return;
064: }
065:
066: // Prepare the file search....
067:
068: DefaultTableModel dtm = (DefaultTableModel) massiveCompilerFrame
069: .getFileTable().getModel();
070:
071: dtm.setRowCount(0);
072: massiveCompilerFrame.getFileTable().updateUI();
073:
074: // Path
075: File path = new File(massiveCompilerFrame.getFindDirectory());
076:
077: if (path == null || !path.exists() || path.isFile()) {
078: // Invalid conditions to search...
079: return;
080: }
081:
082: if (!stop)
083: findFiles(path,
084: massiveCompilerFrame.isSearchSubDirectory(), dtm);
085:
086: massiveCompilerFrame.finishedFind();
087: return;
088: }
089:
090: private int findFiles(File path, boolean recursive,
091: DefaultTableModel tmodel) {
092: if (stop)
093: return 0;
094: int count = 0;
095: File[] files = path.listFiles();
096: for (int i = 0; i < files.length; ++i) {
097: if (stop)
098: return 0;
099: if (files[i].isDirectory() && recursive) {
100: count += findFiles(files[i], recursive, tmodel);
101: } else {
102: // Is the file a JasperReports source?
103: if (files[i].getName().toLowerCase().endsWith(".xml")
104: || files[i].getName().toLowerCase().endsWith(
105: ".jrxml")) {
106: // Ok, for me is a good file, get it !
107: FileEntry fe = new FileEntry();
108: fe.setFile(files[i]);
109:
110: // Looking for compiled and compilation version...
111:
112: // ....
113: fe.setStatus(fe.STATUS_NOT_COMPILED);
114: tmodel.addRow(new Object[] { fe, fe,
115: fe.decodeStatus(fe.getStatus()) });
116:
117: }
118: }
119: }
120:
121: return count;
122: }
123:
124: }
|