PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

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