PageRenderTime 118ms CodeModel.GetById 98ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 1ms

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