Index: trunk/gli/src/org/greenstone/gatherer/file/FileManager.java
===================================================================
--- trunk/gli/src/org/greenstone/gatherer/file/FileManager.java	(revision 10244)
+++ trunk/gli/src/org/greenstone/gatherer/file/FileManager.java	(revision 10245)
@@ -8,9 +8,9 @@
  * <BR><BR>
  *
- * Author: John Thompson, Greenstone Digital Library, University of Waikato
- *
- * <BR><BR>
- *
- * Copyright (C) 1999 New Zealand Digital Library Project
+ * Author: John Thompson, NZDL Project, University of Waikato
+ *
+ * <BR><BR>
+ *
+ * Copyright (C) 2005 New Zealand Digital Library Project
  *
  * <BR><BR>
@@ -48,83 +48,133 @@
 import org.greenstone.gatherer.util.Utility;
 
+
 /** Manages the moving of files within a separate thread.
- * @author John Thompson, Greenstone Digital Library, University of Waikato
- * @version 2.3
+ * @author John Thompson, NZDL Project, University of Waikato
  */
-public class FileManager {
+public class FileManager
+{
+    /** Not only the queue of files to be moved, but also the object that moves them. */
+    static private FileQueue file_queue = null;
 
     public static int FILE_TYPE = 0;
     public static int FOLDER_TYPE = 1;
 
-    static public int countFolderDepth(File file) {
-	int count = 0;
-	while(file != null) {
-	    count++;
-	    file = file.getParentFile();
-	}
-	return count;
-    }
-
-    /** Not only the queue of files to be moved, but also the object that moves them. */
-    private FileQueue queue = null;
+
     /** Constructor.
      * @see org.greenstone.gatherer.file.FileQueue
      */
-    public FileManager() {
-	queue = new FileQueue();
-	queue.start();
-    }
-
-    /** Given the arguments, determine what action should be carried out by the file queue, and add all of the necessary file jobs. */
-    public void action(DragComponent source, FileNode[] source_nodes, DragComponent target, FileNode target_node) {
-	byte type = 0;
-	// If source and target are the same we are moving
-	if(source == target) {
-	    type = FileJob.MOVE;
-	}
-	// If source and target are different
-	else {
-	    // If target is the RecycleBin, we're deleting
-	    if (target instanceof RecycleBin) {
-		// The workspace tree is read only.
-		// ... except for files from the "Downloaded Files" folder
-		boolean from_downloaded_files_folder = false;
-		if (source_nodes != null) {
-		    for (int i = 0; i < source_nodes.length; i++) {
-			if (source_nodes[i].getFile() != null) {
-			    if (source_nodes[i].getFile().getAbsolutePath().startsWith(Utility.getCacheDir().getAbsolutePath())) {
-				from_downloaded_files_folder = true;
-			    }
-			}
+    public FileManager()
+    {
+	file_queue = new FileQueue();
+	file_queue.start();
+    }
+
+
+    /** Determine what action should be carried out by the file queue, and add all of the necessary file jobs. */
+    public void action(DragComponent source, FileNode[] source_nodes, DragComponent target, FileNode target_node)
+    {
+	long id = System.currentTimeMillis();
+
+	// If source and target are the same we're moving
+	if (source == target) {
+	    // Start a new move FileTask and we're done
+	    (new FileTask(id, source, source_nodes, target, target_node, FileJob.MOVE)).start();
+	    return;
+	}
+
+	// If target isn't the RecycleBin, we're copying
+	if (!(target instanceof RecycleBin)) {
+	    // Start a new copy FileTask and we're done
+	    (new FileTask(id, source, source_nodes, target, target_node, FileJob.COPY)).start();
+	    return;
+	}
+
+	// We're deleting... but first make sure source isn't read-only
+	boolean read_only_source = false;
+
+	// The workspace tree is read-only...
+	if (source.toString().equals("Workspace")) {
+	    read_only_source = true;
+
+	    // ...except for files from the "Downloaded Files" folder
+	    String downloaded_files_folder_path = Utility.getCacheDir().getAbsolutePath();
+	    for (int i = 0; i < source_nodes.length; i++) {
+		// Is this the "Downloaded Files" folder?
+		if (source_nodes[i].getFile().getAbsolutePath().startsWith(downloaded_files_folder_path)) {
+		    // Can only delete from the "Downloaded Files" folder if a collection is open
+		    if (Gatherer.c_man.ready() == false) {
+			return;
 		    }
-		}
-
-		// Can only delete from the "Downloaded Files" folder if a collection is open
-		if (from_downloaded_files_folder && Gatherer.c_man.ready() == false) {
-		    return;
-		}
-
-		if (source.toString().equals("Workspace") && !from_downloaded_files_folder) {
-		    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.Read_Only"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
-		    return;
-		}
-		// Normal delete. Go ahead.
-		else {
-		    type = FileJob.DELETE;
-		}
-	    }
-	    // Otherwise we are copying
-	    else {
-		type = FileJob.COPY;
-	    }
-	}
-	Task task = new Task(System.currentTimeMillis(), source, source_nodes, target, target_node, type);
-	task.start();
-    }
+		    read_only_source = false;
+		}
+	    }
+	}
+
+	// The source is read-only, so tell the user and abort
+	if (read_only_source) {
+	    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("FileActions.Read_Only"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
+	    return;
+	}
+
+	// Start a new delete FileTask and we're done
+	(new FileTask(id, source, source_nodes, target, target_node, FileJob.DELETE)).start();
+    }
+
 
     /** Retrieves the file queue object. */
-    public FileQueue getQueue() {
-	return queue;
-    }
+    public FileQueue getQueue()
+    {
+	return file_queue;
+    }
+
+
+    private class FileTask
+	extends Thread
+    {
+	private long id;
+	private DragComponent source;
+	private FileNode[] source_nodes;
+	private DragComponent target;
+	private FileNode target_node;
+	private byte type;
+
+
+	public FileTask(long id, DragComponent source, FileNode[] source_nodes, DragComponent target, FileNode target_node, byte type)
+	{
+	    this.id = id;
+	    this.source = source;
+	    this.source_nodes = source_nodes;
+	    this.target = target;
+	    this.target_node = target_node;
+	    this.type = type;
+	}
+
+
+	public void run()
+	{
+	    // Check there is something to do
+	    if (source_nodes == null) {
+		return;
+	    }
+
+	    // Reset the progress bar and set it to indeterminate while calculating its size
+	    LongProgressBar progress_bar = file_queue.getProgressBar();
+	    progress_bar.reset();
+	    progress_bar.setIndeterminate(true);
+
+	    // Calculate the progress bar size
+	    boolean cancelled = file_queue.calculateSize(source_nodes);
+	    if (!cancelled) {
+		// Queue the job(s) (this may fail if we are asked to delete a read only file)
+		for (int i = 0; i < source_nodes.length; i++) {
+		    file_queue.addJob(id, source, source_nodes[i], target, target_node, type, true);
+		}
+	    }
+
+	    progress_bar.setIndeterminate(false);
+	    progress_bar.clear();
+	}
+    }
+
 
     public void newDummyDoc(DragTree tree, CollectionTreeNode parent_node){
@@ -132,7 +182,10 @@
     }
 
+
     public void newFolder(DragTree tree, CollectionTreeNode parent_node) {
 	newFolderOrDummyDoc(tree, parent_node, FOLDER_TYPE);
     }
+
+
     protected void newFolderOrDummyDoc(DragTree tree, CollectionTreeNode parent_node, int type) {
 	// Ask the user for the directories name.
@@ -184,47 +237,3 @@
 	name = null;
     }
-
-    private class Task
-	extends Thread {
-	private byte type;
-	private DragComponent source;
-	private DragComponent target;
-	private FileNode target_node;
-	private FileNode[] source_nodes;
-	private long id;
-
-	public Task(long id, DragComponent source, FileNode[] source_nodes, DragComponent target, FileNode target_node, byte type) {
-	    this.id = id;
-	    this.source = source;
-	    this.source_nodes = source_nodes;
-	    this.target = target;
-	    this.target_node = target_node;
-	    this.type = type;
-	}
-
-	public void run()
-	{
-	    // Check there is something to do
-	    if (source_nodes == null) {
-		return;
-	    }
-
-	    // Reset the progress bar and set it to indeterminate while calculating its size
-	    LongProgressBar progress_bar = queue.getProgressBar();
-	    progress_bar.reset();
-	    progress_bar.setIndeterminate(true);
-
-	    // Calculate the progress bar size
-	    boolean cancelled = queue.calculateSize(source_nodes);
-	    if (!cancelled) {
-		// Queue the job(s) (this may fail if we are asked to delete a read only file)
-		for (int i = 0; i < source_nodes.length; i++) {
-		    queue.addJob(id, source, source_nodes[i], target, target_node, type, true);
-		}
-	    }
-
-	    progress_bar.setIndeterminate(false);
-	    progress_bar.clear();
-	}
-    }
 }
Index: trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java
===================================================================
--- trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java	(revision 10244)
+++ trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java	(revision 10245)
@@ -158,4 +158,15 @@
 
 
+    private int countFolderDepth(File file)
+    {
+	int depth = 0;
+	while (file != null) {
+	    depth++;
+	    file = file.getParentFile();
+	}
+	return depth;
+    }
+
+
     /** Format the given filename path string so that it is no longer than the given width. If it is wider replace starting directories with ...
      * @param key The key <strong>String</Strong> used to retrieve a phrase from the dictionary for this item.
@@ -241,5 +252,5 @@
 			int max_folder_depth = Configuration.getInt("general.max_folder_depth", Configuration.COLLECTION_SPECIFIC);
 			boolean continue_over_depth = false;
-			if(FileManager.countFolderDepth(source_file) > max_folder_depth) {
+			if (countFolderDepth(source_file) > max_folder_depth) {
 			    Object[] options = { Dictionary.get("General.Yes"), Dictionary.get("General.No"), Dictionary.get("FileActions.Increase_Depth") };
 			    String args[] = { String.valueOf(max_folder_depth), source_file.getAbsolutePath() };
