PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/browser/BrowserIORequest.java

#
Java | 322 lines | 231 code | 30 blank | 61 comment | 7 complexity | dd2365a97bef57ffa395c2c5ba324d1c 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. * BrowserIORequest.java - VFS browser I/O request
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000 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.browser;
  23. //{{{ Imports
  24. import javax.swing.tree.DefaultMutableTreeNode;
  25. import java.io.*;
  26. import org.gjt.sp.jedit.io.*;
  27. import org.gjt.sp.jedit.jEdit;
  28. import org.gjt.sp.jedit.MiscUtilities;
  29. import org.gjt.sp.util.WorkRequest;
  30. import org.gjt.sp.util.WorkThread;
  31. //}}}
  32. /**
  33. * A browser I/O request.
  34. * @author Slava Pestov
  35. * @version $Id: BrowserIORequest.java 3998 2002-01-28 04:20:54Z spestov $
  36. */
  37. public class BrowserIORequest extends WorkRequest
  38. {
  39. //{{{ Request types
  40. /**
  41. * Directory listing I/O request.
  42. */
  43. public static final int LIST_DIRECTORY = 0;
  44. /**
  45. * Delete file I/O request.
  46. */
  47. public static final int DELETE = 1;
  48. /**
  49. * Rename file I/O request.
  50. */
  51. public static final int RENAME = 2;
  52. /**
  53. * Make directory I/O request.
  54. */
  55. public static final int MKDIR = 3;
  56. //}}}
  57. //{{{ BrowserIORequest constructor
  58. /**
  59. * Creates a new browser I/O request.
  60. * @param type The request type
  61. * @param browser The VFS browser instance
  62. * @param path1 The first path name to operate on
  63. * @param path2 The second path name to operate on
  64. * @param node Only used for type == LIST_DIRECTORY
  65. */
  66. public BrowserIORequest(int type, VFSBrowser browser,
  67. Object session, VFS vfs, String path1, String path2,
  68. DefaultMutableTreeNode node)
  69. {
  70. this.type = type;
  71. this.browser = browser;
  72. this.session = session;
  73. this.vfs = vfs;
  74. this.path1 = path1;
  75. this.path2 = path2;
  76. this.node = node;
  77. } //}}}
  78. //{{{ run() method
  79. public void run()
  80. {
  81. switch(type)
  82. {
  83. case LIST_DIRECTORY:
  84. listDirectory();
  85. break;
  86. case DELETE:
  87. delete();
  88. break;
  89. case RENAME:
  90. rename();
  91. break;
  92. case MKDIR:
  93. mkdir();
  94. break;
  95. }
  96. if(type != LIST_DIRECTORY)
  97. browser.endRequest();
  98. } //}}}
  99. //{{{ toString() method
  100. public String toString()
  101. {
  102. String typeString;
  103. switch(type)
  104. {
  105. case LIST_DIRECTORY:
  106. typeString = "LIST_DIRECTORY";
  107. break;
  108. case DELETE:
  109. typeString = "DELETE";
  110. break;
  111. case RENAME:
  112. typeString = "RENAME";
  113. break;
  114. case MKDIR:
  115. typeString = "MKDIR";
  116. break;
  117. default:
  118. typeString = "UNKNOWN!!!";
  119. break;
  120. }
  121. return getClass().getName() + "[type=" + typeString
  122. + ",vfs=" + vfs + ",path1=" + path1
  123. + ",path2=" + path2 + "]";
  124. } //}}}
  125. //{{{ Private members
  126. //{{{ Instance variables
  127. private int type;
  128. private VFSBrowser browser;
  129. private Object session;
  130. private VFS vfs;
  131. private String path1;
  132. private String path2;
  133. private DefaultMutableTreeNode node;
  134. //}}}
  135. //{{{ listDirectory() method
  136. private void listDirectory()
  137. {
  138. VFS.DirectoryEntry[] directory = null;
  139. String[] args = { path1 };
  140. setStatus(jEdit.getProperty("vfs.status.listing-directory",args));
  141. String canonPath = null;
  142. try
  143. {
  144. setAbortable(true);
  145. canonPath = vfs._canonPath(session,path1,browser);
  146. directory = vfs._listDirectory(session,canonPath,browser);
  147. }
  148. catch(IOException io)
  149. {
  150. setAbortable(false);
  151. String[] pp = { io.toString() };
  152. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  153. }
  154. catch(WorkThread.Abort a)
  155. {
  156. }
  157. finally
  158. {
  159. try
  160. {
  161. vfs._endVFSSession(session,browser);
  162. }
  163. catch(IOException io)
  164. {
  165. setAbortable(false);
  166. String[] pp = { io.toString() };
  167. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  168. }
  169. }
  170. setAbortable(false);
  171. browser.directoryLoaded(node,canonPath,directory);
  172. } //}}}
  173. //{{{ delete() method
  174. private void delete()
  175. {
  176. try
  177. {
  178. setAbortable(true);
  179. String[] args = { path1 };
  180. setStatus(jEdit.getProperty("vfs.status.deleting",args));
  181. try
  182. {
  183. path1 = vfs._canonPath(session,path1,browser);
  184. if(!vfs._delete(session,path1,browser))
  185. VFSManager.error(browser,path1,"ioerror.delete-error",null);
  186. }
  187. catch(IOException io)
  188. {
  189. String[] pp = { io.toString() };
  190. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  191. }
  192. }
  193. catch(WorkThread.Abort a)
  194. {
  195. }
  196. finally
  197. {
  198. try
  199. {
  200. vfs._endVFSSession(session,browser);
  201. }
  202. catch(IOException io)
  203. {
  204. String[] pp = { io.toString() };
  205. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  206. }
  207. }
  208. } //}}}
  209. //{{{ rename() method
  210. private void rename()
  211. {
  212. try
  213. {
  214. setAbortable(true);
  215. String[] args = { path1, path2 };
  216. setStatus(jEdit.getProperty("vfs.status.renaming",args));
  217. try
  218. {
  219. path1 = vfs._canonPath(session,path1,browser);
  220. path2 = vfs._canonPath(session,path2,browser);
  221. VFS.DirectoryEntry file = vfs._getDirectoryEntry(
  222. session,path2,browser);
  223. if(file != null)
  224. VFSManager.error(browser,path1,"ioerror.rename-exists",
  225. new String[] { path2 });
  226. else
  227. {
  228. if(!vfs._rename(session,path1,path2,browser))
  229. VFSManager.error(browser,path1,"ioerror.rename-error",
  230. new String[] { path2 });
  231. }
  232. }
  233. catch(IOException io)
  234. {
  235. String[] pp = { io.toString() };
  236. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  237. }
  238. }
  239. catch(WorkThread.Abort a)
  240. {
  241. }
  242. finally
  243. {
  244. try
  245. {
  246. vfs._endVFSSession(session,browser);
  247. }
  248. catch(IOException io)
  249. {
  250. String[] pp = { io.toString() };
  251. VFSManager.error(browser,path1,"ioerror.directory-error",pp);
  252. }
  253. }
  254. } //}}}
  255. //{{{ mkdir() method
  256. private void mkdir()
  257. {
  258. try
  259. {
  260. setAbortable(true);
  261. String[] args = { path1 };
  262. setStatus(jEdit.getProperty("vfs.status.mkdir",args));
  263. try
  264. {
  265. path1 = vfs._canonPath(session,path1,browser);
  266. if(!vfs._mkdir(session,path1,browser))
  267. VFSManager.error(browser,path1,"ioerror.mkdir-error",null);
  268. }
  269. catch(IOException io)
  270. {
  271. args[0] = io.toString();
  272. VFSManager.error(browser,path1,"ioerror",args);
  273. }
  274. }
  275. catch(WorkThread.Abort a)
  276. {
  277. }
  278. finally
  279. {
  280. try
  281. {
  282. vfs._endVFSSession(session,browser);
  283. }
  284. catch(IOException io)
  285. {
  286. String[] args = { io.toString() };
  287. VFSManager.error(browser,path1,"ioerror",args);
  288. }
  289. }
  290. } //}}}
  291. //}}}
  292. }