PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 156 lines | 92 code | 16 blank | 48 comment | 3 complexity | 6fae425537c9538950e6a2362e166db6 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package org.gjt.sp.jedit.search;
  23. //{{{ Imports
  24. import javax.swing.SwingUtilities;
  25. import java.awt.Component;
  26. import java.io.*;
  27. import org.gjt.sp.jedit.io.*;
  28. import org.gjt.sp.jedit.*;
  29. import org.gjt.sp.util.Log;
  30. //}}}
  31. /**
  32. * Recursive directory search.
  33. * @author Slava Pestov
  34. * @version $Id: DirectoryListSet.java 4563 2003-03-22 22:52:09Z spestov $
  35. */
  36. public class DirectoryListSet extends BufferListSet
  37. {
  38. //{{{ DirectoryListSet constructor
  39. public DirectoryListSet(String directory, String glob, boolean recurse)
  40. {
  41. this.directory = directory;
  42. this.glob = glob;
  43. this.recurse = recurse;
  44. } //}}}
  45. //{{{ getDirectory() method
  46. public String getDirectory()
  47. {
  48. return directory;
  49. } //}}}
  50. //{{{ setDirectory() method
  51. /**
  52. * @since jEdit 4.2pre1
  53. */
  54. public void setDirectory(String directory)
  55. {
  56. this.directory = directory;
  57. invalidateCachedList();
  58. } //}}}
  59. //{{{ getFileFilter() method
  60. public String getFileFilter()
  61. {
  62. return glob;
  63. } //}}}
  64. //{{{ setFileFilter() method
  65. /**
  66. * @since jEdit 4.2pre1
  67. */
  68. public void setFileFilter(String glob)
  69. {
  70. this.glob = glob;
  71. invalidateCachedList();
  72. } //}}}
  73. //{{{ isRecursive() method
  74. public boolean isRecursive()
  75. {
  76. return recurse;
  77. } //}}}
  78. //{{{ setRecursive() method
  79. /**
  80. * @since jEdit 4.2pre1
  81. */
  82. public void setRecursive(boolean recurse)
  83. {
  84. this.recurse = recurse;
  85. invalidateCachedList();
  86. } //}}}
  87. //{{{ getCode() method
  88. public String getCode()
  89. {
  90. return "new DirectoryListSet(\"" + MiscUtilities.charsToEscapes(directory)
  91. + "\",\"" + MiscUtilities.charsToEscapes(glob) + "\","
  92. + recurse + ")";
  93. } //}}}
  94. //{{{ _getFiles() method
  95. protected String[] _getFiles(final Component comp)
  96. {
  97. final VFS vfs = VFSManager.getVFSForPath(directory);
  98. Object session;
  99. if(SwingUtilities.isEventDispatchThread())
  100. {
  101. session = vfs.createVFSSession(directory,comp);
  102. }
  103. else
  104. {
  105. final Object[] returnValue = new Object[1];
  106. try
  107. {
  108. SwingUtilities.invokeAndWait(new Runnable()
  109. {
  110. public void run()
  111. {
  112. returnValue[0] = vfs.createVFSSession(directory,comp);
  113. }
  114. });
  115. }
  116. catch(Exception e)
  117. {
  118. Log.log(Log.ERROR,this,e);
  119. }
  120. session = returnValue[0];
  121. }
  122. if(session == null)
  123. return null;
  124. try
  125. {
  126. return vfs._listDirectory(session,directory,glob,recurse,comp);
  127. }
  128. catch(IOException io)
  129. {
  130. VFSManager.error(comp,directory,"ioerror",new String[]
  131. { io.toString() });
  132. return null;
  133. }
  134. } //}}}
  135. //{{{ Private members
  136. private String directory;
  137. private String glob;
  138. private boolean recurse;
  139. //}}}
  140. }