PageRenderTime 41ms CodeModel.GetById 35ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 128 lines | 79 code | 13 blank | 36 comment | 3 complexity | a956190348629bd081601c5cad1291a2 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 gnu.regexp.RE;
 27import javax.swing.SwingUtilities;
 28import java.awt.Component;
 29import java.io.*;
 30import java.util.Vector;
 31import org.gjt.sp.jedit.io.*;
 32import org.gjt.sp.jedit.*;
 33import org.gjt.sp.util.Log;
 34//}}}
 35
 36/**
 37 * Recursive directory search.
 38 * @author Slava Pestov
 39 * @version $Id: DirectoryListSet.java 4261 2002-06-18 02:44:52Z spestov $
 40 */
 41public class DirectoryListSet extends BufferListSet
 42{
 43	//{{{ DirectoryListSet constructor
 44	public DirectoryListSet(String directory, String glob, boolean recurse)
 45	{
 46		this.directory = directory;
 47		this.glob = glob;
 48		this.recurse = recurse;
 49	} //}}}
 50
 51	//{{{ getDirectory() method
 52	public String getDirectory()
 53	{
 54		return directory;
 55	} //}}}
 56
 57	//{{{ getFileFilter() method
 58	public String getFileFilter()
 59	{
 60		return glob;
 61	} //}}}
 62
 63	//{{{ isRecursive() method
 64	public boolean isRecursive()
 65	{
 66		return recurse;
 67	} //}}}
 68
 69	//{{{ getCode() method
 70	public String getCode()
 71	{
 72		return "new DirectoryListSet(\"" + MiscUtilities.charsToEscapes(directory)
 73			+ "\",\"" + MiscUtilities.charsToEscapes(glob) + "\","
 74			+ recurse + ")";
 75	} //}}}
 76
 77	//{{{ _getFiles() method
 78	protected String[] _getFiles(final Component comp)
 79	{
 80		final VFS vfs = VFSManager.getVFSForPath(directory);
 81		Object session;
 82		if(SwingUtilities.isEventDispatchThread())
 83		{
 84			session = vfs.createVFSSession(directory,comp);
 85		}
 86		else
 87		{
 88			final Object[] returnValue = new Object[1];
 89
 90			try
 91			{
 92				SwingUtilities.invokeAndWait(new Runnable()
 93				{
 94					public void run()
 95					{
 96						returnValue[0] = vfs.createVFSSession(directory,comp);
 97					}
 98				});
 99			}
100			catch(Exception e)
101			{
102				Log.log(Log.ERROR,this,e);
103			}
104
105			session = returnValue[0];
106		}
107
108		if(session == null)
109			return null;
110
111		try
112		{
113			return vfs._listDirectory(session,directory,glob,recurse,comp);
114		}
115		catch(IOException io)
116		{
117			VFSManager.error(comp,directory,"ioerror",new String[]
118				{ io.toString() });
119			return null;
120		}
121	} //}}}
122
123	//{{{ Private members
124	private String directory;
125	private String glob;
126	private boolean recurse;
127	//}}}
128}