PageRenderTime 23ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/search/DirectoryListSet.java

#
Java | 164 lines | 98 code | 18 blank | 48 comment | 3 complexity | d4c09b9eedb50a14da01a8d7c4c01bce MD5 | raw file
  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
 23package org.gjt.sp.jedit.search;
 24
 25//{{{ Imports
 26import javax.swing.SwingUtilities;
 27import java.awt.Component;
 28import java.io.*;
 29import org.gjt.sp.jedit.io.*;
 30import org.gjt.sp.jedit.*;
 31import 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 */
 39public class DirectoryListSet extends BufferListSet
 40{
 41	//{{{ DirectoryListSet constructor
 42	public DirectoryListSet(String directory, String 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 getDirectory()
 55	{
 56		return directory;
 57	} //}}}
 58
 59	//{{{ setDirectory() method
 60	/**
 61	 * @since jEdit 4.2pre1
 62	 */
 63	public void setDirectory(String directory)
 64	{
 65		this.directory = directory;
 66		invalidateCachedList();
 67	} //}}}
 68
 69	//{{{ getFileFilter() method
 70	public String getFileFilter()
 71	{
 72		return glob;
 73	} //}}}
 74
 75	//{{{ setFileFilter() method
 76	/**
 77	 * @since jEdit 4.2pre1
 78	 */
 79	public void setFileFilter(String 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 getCode()
103	{
104		return "new DirectoryListSet(\"" + MiscUtilities.charsToEscapes(directory)
105			+ "\",\"" + MiscUtilities.charsToEscapes(glob) + "\","
106			+ recurse + ")";
107	} //}}}
108
109	//{{{ _getFiles() method
110	protected String[] _getFiles(final Component 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 session;
116		if(SwingUtilities.isEventDispatchThread())
117		{
118			session = vfs.createVFSSession(directory,comp);
119		}
120		else
121		{
122			final Object[] returnValue = new Object[1];
123
124			try
125			{
126				SwingUtilities.invokeAndWait(new Runnable()
127				{
128					public void run()
129					{
130						returnValue[0] = vfs.createVFSSession(directory,comp);
131					}
132				});
133			}
134			catch(Exception 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[]
152				{ io.toString() });
153			return null;
154		}
155	} //}}}
156
157	//{{{ Private members
158	private String directory;
159	private String glob;
160	private boolean recurse;
161	private boolean skipHidden;
162	private boolean skipBinary;
163	//}}}
164}