KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > search > DirectoryListSet


1 /*
2  * DirectoryListSet.java - Directory list matcher
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 1999, 2000, 2001 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22
23 package org.gjt.sp.jedit.search;
24
25 //{{{ Imports
26
import javax.swing.SwingUtilities JavaDoc;
27 import java.awt.Component JavaDoc;
28 import java.io.*;
29 import org.gjt.sp.jedit.io.*;
30 import org.gjt.sp.jedit.*;
31 import org.gjt.sp.util.Log;
32 //}}}
33

34 /**
35  * Recursive directory search.
36  * @author Slava Pestov
37  * @version $Id: DirectoryListSet.java 5427 2006-05-27 08:14:07Z kpouer $
38  */

39 public class DirectoryListSet extends BufferListSet
40 {
41     //{{{ DirectoryListSet constructor
42
public DirectoryListSet(String JavaDoc directory, String JavaDoc glob, boolean recurse)
43     {
44         this.directory = directory;
45         this.glob = glob;
46         this.recurse = recurse;
47         this.skipBinary = jEdit.getBooleanProperty("search.skipBinary.toggle");
48         this.skipHidden = jEdit.getBooleanProperty("search.skipHidden.toggle");
49     } //}}}
50

51
52
53     //{{{ getDirectory() method
54
public String JavaDoc getDirectory()
55     {
56         return directory;
57     } //}}}
58

59     //{{{ setDirectory() method
60
/**
61      * @since jEdit 4.2pre1
62      */

63     public void setDirectory(String JavaDoc directory)
64     {
65         this.directory = directory;
66         invalidateCachedList();
67     } //}}}
68

69     //{{{ getFileFilter() method
70
public String JavaDoc getFileFilter()
71     {
72         return glob;
73     } //}}}
74

75     //{{{ setFileFilter() method
76
/**
77      * @since jEdit 4.2pre1
78      */

79     public void setFileFilter(String JavaDoc glob)
80     {
81         this.glob = glob;
82         invalidateCachedList();
83     } //}}}
84

85     //{{{ isRecursive() method
86
public boolean isRecursive()
87     {
88         return recurse;
89     } //}}}
90

91     //{{{ setRecursive() method
92
/**
93      * @since jEdit 4.2pre1
94      */

95     public void setRecursive(boolean recurse)
96     {
97         this.recurse = recurse;
98         invalidateCachedList();
99     } //}}}
100

101     //{{{ getCode() method
102
public String JavaDoc getCode()
103     {
104         return "new DirectoryListSet(\"" + MiscUtilities.charsToEscapes(directory)
105             + "\",\"" + MiscUtilities.charsToEscapes(glob) + "\","
106             + recurse + ")";
107     } //}}}
108

109     //{{{ _getFiles() method
110
protected String JavaDoc[] _getFiles(final Component JavaDoc comp)
111     {
112         this.skipBinary = jEdit.getBooleanProperty("search.skipBinary.toggle");
113         this.skipHidden = jEdit.getBooleanProperty("search.skipHidden.toggle");
114         final VFS vfs = VFSManager.getVFSForPath(directory);
115         Object JavaDoc session;
116         if(SwingUtilities.isEventDispatchThread())
117         {
118             session = vfs.createVFSSession(directory,comp);
119         }
120         else
121         {
122             final Object JavaDoc[] returnValue = new Object JavaDoc[1];
123
124             try
125             {
126                 SwingUtilities.invokeAndWait(new Runnable JavaDoc()
127                 {
128                     public void run()
129                     {
130                         returnValue[0] = vfs.createVFSSession(directory,comp);
131                     }
132                 });
133             }
134             catch(Exception JavaDoc e)
135             {
136                 Log.log(Log.ERROR,this,e);
137             }
138
139             session = returnValue[0];
140         }
141
142         if(session == null)
143             return null;
144
145         try
146         {
147             return vfs._listDirectory(session,directory,glob,recurse,comp, skipBinary, skipHidden);
148         }
149         catch(IOException io)
150         {
151             VFSManager.error(comp,directory,"ioerror",new String JavaDoc[]
152                 { io.toString() });
153             return null;
154         }
155     } //}}}
156

157     //{{{ Private members
158
private String JavaDoc directory;
159     private String JavaDoc glob;
160     private boolean recurse;
161     private boolean skipHidden;
162     private boolean skipBinary;
163     //}}}
164
}
165
Popular Tags