PageRenderTime 135ms CodeModel.GetById 125ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/browser/RenameBrowserTask.java

#
Java | 131 lines | 80 code | 10 blank | 41 comment | 6 complexity | e814e38db4014a72669621dbb98ef973 MD5 | raw file
  1/*
  2 * jEdit - Programmer's Text Editor
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright Š 2011 Matthieu Casanova
  7 * Portions Copyright (C) 2000, 2003 Slava Pestov
  8 *
  9 * This program is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU General Public License
 11 * as published by the Free Software Foundation; either version 2
 12 * of the License, or any later version.
 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 org.gjt.sp.jedit.OperatingSystem;
 27import org.gjt.sp.jedit.io.FavoritesVFS;
 28import org.gjt.sp.jedit.io.VFS;
 29import org.gjt.sp.jedit.io.VFSFile;
 30import org.gjt.sp.jedit.io.VFSManager;
 31import org.gjt.sp.jedit.jEdit;
 32import org.gjt.sp.util.Log;
 33
 34import java.io.IOException;
 35//}}}
 36
 37/**
 38 * @author Matthieu Casanova
 39 * @version $Id: ListDirectoryBrowserTask.java 19692 2011-07-22 15:27:56Z kpouer $
 40 */
 41class RenameBrowserTask extends AbstractBrowserTask
 42{
 43	//{{{ BrowserIORequest constructor
 44	/**
 45	 * Creates a new browser I/O request.
 46	 *
 47	 * @param browser  The VFS browser instance
 48	 * @param path1    The first path name to operate on
 49	 * @param path2    The second path name to operate on
 50	 */
 51	RenameBrowserTask(VFSBrowser browser,
 52			  Object session, VFS vfs, String path1, String path2,
 53			 Runnable awtRunnable)
 54	{
 55		super(browser, session, vfs, path1, awtRunnable);
 56		this.path2 = path2;
 57	} //}}}
 58
 59	//{{{ _run() method
 60	@Override
 61	public void _run()
 62	{
 63		try
 64		{
 65			setCancellable(true);
 66			String[] args = {path, path2};
 67			setStatus(jEdit.getProperty("vfs.status.renaming", args));
 68
 69			path = vfs._canonPath(session, path, browser);
 70			path2 = vfs._canonPath(session, path2, browser);
 71
 72			if (!(vfs instanceof FavoritesVFS))
 73			{
 74				VFSFile file = vfs._getFile(session, path2, browser);
 75				if (file != null)
 76				{
 77					if ((OperatingSystem.isCaseInsensitiveFS())
 78							&& path.equalsIgnoreCase(path2))
 79					{
 80						// allow user to change name
 81						// case
 82					}
 83					else
 84					{
 85						VFSManager.error(browser, path,
 86								"ioerror.rename-exists",
 87								new String[]{path2});
 88						return;
 89					}
 90				}
 91			}
 92
 93			if (!vfs._rename(session, path, path2, browser))
 94				VFSManager.error(browser, path, "ioerror.rename-error",
 95				    new String[]{path2});
 96		}
 97		catch (IOException io)
 98		{
 99			setCancellable(false);
100			Log.log(Log.ERROR, this, io);
101			String[] pp = {io.toString()};
102			VFSManager.error(browser, path, "ioerror.directory-error", pp);
103		}
104		finally
105		{
106			try
107			{
108				vfs._endVFSSession(session, browser);
109			}
110			catch (IOException io)
111			{
112				setCancellable(false);
113				Log.log(Log.ERROR, this, io);
114				String[] pp = {io.toString()};
115				VFSManager.error(browser, path, "ioerror.directory-error", pp);
116			}
117		}
118	} //}}}
119
120	//{{{ toString() method
121	public String toString()
122	{
123		return getClass().getName() + "[type=RENAME"
124		    + ",vfs=" + vfs + ",path=" + path
125		    + ",path2=" + path2 + ']';
126	} //}}}
127
128	//{{{ Private members
129	private String path2;
130	//}}}
131}