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