PageRenderTime 231ms CodeModel.GetById 218ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/search/DirectoryListSet.java

#
Java | 156 lines | 92 code | 16 blank | 48 comment | 3 complexity | 6fae425537c9538950e6a2362e166db6 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 4563 2003-03-22 22:52:09Z spestov $
 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	} //}}}
 48
 49	//{{{ getDirectory() method
 50	public String getDirectory()
 51	{
 52		return directory;
 53	} //}}}
 54
 55	//{{{ setDirectory() method
 56	/**
 57	 * @since jEdit 4.2pre1
 58	 */
 59	public void setDirectory(String directory)
 60	{
 61		this.directory = directory;
 62		invalidateCachedList();
 63	} //}}}
 64
 65	//{{{ getFileFilter() method
 66	public String getFileFilter()
 67	{
 68		return glob;
 69	} //}}}
 70
 71	//{{{ setFileFilter() method
 72	/**
 73	 * @since jEdit 4.2pre1
 74	 */
 75	public void setFileFilter(String glob)
 76	{
 77		this.glob = glob;
 78		invalidateCachedList();
 79	} //}}}
 80
 81	//{{{ isRecursive() method
 82	public boolean isRecursive()
 83	{
 84		return recurse;
 85	} //}}}
 86
 87	//{{{ setRecursive() method
 88	/**
 89	 * @since jEdit 4.2pre1
 90	 */
 91	public void setRecursive(boolean recurse)
 92	{
 93		this.recurse = recurse;
 94		invalidateCachedList();
 95	} //}}}
 96
 97	//{{{ getCode() method
 98	public String getCode()
 99	{
100		return "new DirectoryListSet(\"" + MiscUtilities.charsToEscapes(directory)
101			+ "\",\"" + MiscUtilities.charsToEscapes(glob) + "\","
102			+ recurse + ")";
103	} //}}}
104
105	//{{{ _getFiles() method
106	protected String[] _getFiles(final Component comp)
107	{
108		final VFS vfs = VFSManager.getVFSForPath(directory);
109		Object session;
110		if(SwingUtilities.isEventDispatchThread())
111		{
112			session = vfs.createVFSSession(directory,comp);
113		}
114		else
115		{
116			final Object[] returnValue = new Object[1];
117
118			try
119			{
120				SwingUtilities.invokeAndWait(new Runnable()
121				{
122					public void run()
123					{
124						returnValue[0] = vfs.createVFSSession(directory,comp);
125					}
126				});
127			}
128			catch(Exception e)
129			{
130				Log.log(Log.ERROR,this,e);
131			}
132
133			session = returnValue[0];
134		}
135
136		if(session == null)
137			return null;
138
139		try
140		{
141			return vfs._listDirectory(session,directory,glob,recurse,comp);
142		}
143		catch(IOException io)
144		{
145			VFSManager.error(comp,directory,"ioerror",new String[]
146				{ io.toString() });
147			return null;
148		}
149	} //}}}
150
151	//{{{ Private members
152	private String directory;
153	private String glob;
154	private boolean recurse;
155	//}}}
156}