Index: trunk/gli/src/org/greenstone/gatherer/file/RecycleBin.java
===================================================================
--- trunk/gli/src/org/greenstone/gatherer/file/RecycleBin.java	(revision 8041)
+++ trunk/gli/src/org/greenstone/gatherer/file/RecycleBin.java	(revision 8045)
@@ -47,31 +47,21 @@
 import javax.swing.tree.*;
 import org.greenstone.gatherer.Gatherer;
-import org.greenstone.gatherer.file.FileJob;
 import org.greenstone.gatherer.file.FileNode;
-import org.greenstone.gatherer.file.FileQueue;
 import org.greenstone.gatherer.file.FileSystemModel;
-import org.greenstone.gatherer.msm.MetadataXMLFile;
-import org.greenstone.gatherer.msm.Metadata;
 import org.greenstone.gatherer.util.DragComponent;
 import org.greenstone.gatherer.util.DragGroup;
 import org.greenstone.gatherer.util.Utility;
-/** Manages the rather complex task of undoing and redoing actions. It does this by storing two queues, undo and redo, containing undo jobs which encapsulate all the information needed to undo or redo an action. It is also important to note that the manage creates a temporary directory, and then places any deleted files in this directory, and saves their associated metadata with them, for the life of the session. This is to facilitate the restoring of deleted files.
- * @author John Thompson, Greenstone Digital Library, University of Waikato
- * @version 2.3c
- */
+
+
 public class RecycleBin
     extends JButton
-    implements ActionListener, DragComponent, DropTargetListener {
-    private ArrayList redo_sources;
-    private ArrayList undo_sources;
+    implements DragComponent, DropTargetListener {
+
     private boolean ignore = false;
-    private boolean ignore_next = false;
     /** The group encompasses all of the objects you plan to drag and drop within, and ensures that only one has focus (as clearly identified by the colour of the selection field or, in this particular case, the background) and that actions only occur between components in the same group. */
     private DragGroup group;
     /** In order to make this button a drop target we have to create a DropTarget instance with the button as its target. */
     private DropTarget drop_target;
-    private FileQueue file_queue;
     private FileSystemModel model;
-    private MetadataXMLFile obsolete_metadata;
     /** What sort of action should a drag resemble. Not really used as we override with custom drag icon. */
     private int drag_action = DnDConstants.ACTION_MOVE;
@@ -80,13 +70,9 @@
     /** The area covered by the drag ghost, our custom drag icon. */
     private Rectangle ra_ghost = new Rectangle();
-    private UndoStack redo;
-    private UndoStack undo;
-    static final public int FILE_COPY = 1;
-    static final public int FILE_DELETE = 2;
-    static final public int FILE_MOVE = 3;
 
-    public RecycleBin() {
+
+    public RecycleBin()
+    {
 	super(Utility.getImage("bin.gif"));
-	this.file_queue = Gatherer.f_man.getQueue();
 	this.drop_target = new DropTarget(this, drag_action, this, true);
 
@@ -95,63 +81,7 @@
 	setOpaque(true);
 
-	// Creation
-	File recycle_directory = new File(Utility.RECYCLE);
-	if(!recycle_directory.exists()) {
-	    recycle_directory.mkdirs();
-	    recycle_directory.deleteOnExit();
-	}
-	this.model = new FileSystemModel(new FileNode(recycle_directory, "Undo"));
-	obsolete_metadata = new MetadataXMLFile(); // This GDM is never saved.
-	redo = new UndoStack(false);
-	redo_sources = new ArrayList();
-	undo = new UndoStack(true);
-	undo_sources = new ArrayList();
-	//if(Gatherer.debug != null) {
-	//   showTree();
-	//}
+	this.model = new FileSystemModel(new FileNode(new File(Utility.RECYCLE), "Undo"));
     }
 
-    public void actionPerformed(ActionEvent event) {
-	// Is this an undo event source...
-	if(undo_sources.contains(event.getSource())) {
-	    UndoJob undo_job = undo.pop();
-	    undo_job.action(true, file_queue);
-	    // Now retrieve all other undo jobs with the same job-number and action them
-	    while((undo_job = undo.getJob(undo_job.ID())) != null) {
-		undo_job.action(true, file_queue);
-	    }
-	}
-	// Or a redo one.
-	else if(redo_sources.contains(event.getSource())) {
-	    UndoJob redo_job = redo.pop();
-	    redo_job.action(false, file_queue);
-	    // Now retrieve all other redo jobs with the same job-number and action them
-	    while((redo_job = redo.getJob(redo_job.ID())) != null) {
-		redo_job.action(false, file_queue);
-	    }
-	}
-    }
-
-    public void addMetadata(File file, ArrayList metadatum) {
-	for(int i = 0; metadatum != null && i < metadatum.size(); i++) {
-	    Metadata metadata = (Metadata) metadatum.get(i);
-	    ///ystem.err.println("UndoMetadata: " + file.getAbsolutePath() + " => " + metadata);
-	    String file_path = file.getAbsolutePath().replace('\\', '/');
-	    obsolete_metadata.addMetadata(file_path, metadata, true);
-	}
-    }
-
-    public void addUndo(long id, int type, DragComponent source_model, FileNode source_parent, DragComponent target_model, FileNode record, boolean undo_event) {
-	if(target_model == null) {
-	    target_model = this;
-	}
-	UndoJobAdder job_adder = new UndoJobAdder(id, type, source_model, source_parent, target_model, record, undo_event);
-	SwingUtilities.invokeLater(job_adder);
-    }
-
-    public void clear() {
-	undo.clear();
-	redo.clear();
-    }
 
     /** In order for the appearance to be consistant, given we may be in the situation where the pointer has left our focus but the ghost remains, this method allows other members of the GGroup to tell this component to repair the 'spoilt' region left by its ghost. */
@@ -159,25 +89,7 @@
     }
 
-    public void destroy() {
-	// Remove all references of this as a listener
-	for(int i = 0; i < redo_sources.size(); i++) {
-	    AbstractButton source = (AbstractButton) redo_sources.get(i);
-	    source.removeActionListener(this);
-	}
-	for(int j = 0; j < undo_sources.size(); j++) {
-	    AbstractButton source = (AbstractButton) undo_sources.get(j);
-	    source.removeActionListener(this);
-	}
-	redo_sources = null;
-	undo_sources = null;
-	redo = null;
-	undo = null;
-	obsolete_metadata = null;
-	file_queue = null;
-    }
 
     /** Any implementation of DropTargetListener must include this method so we can be notified when the drag focus enters this component. We want to provide some sort of indication whether the current component is an acceptable drop target as well as indicating focus. */
     public void dragEnter(DropTargetDragEvent event) {
-	//ystem.err.println("Drag entered");
 	group.grabFocus(this);
 	setBackground(Gatherer.config.getColor("coloring.button_selected_background", true));
@@ -187,5 +99,4 @@
     /** Any implementation of DropTargetListener must include this method so we can be notified when the drag focus leaves this component. We need to indicate that we have lost focus. */
     public void dragExit(DropTargetEvent event) {
-	//ystem.err.println("Drag exitted");
 	setBackground(Gatherer.config.getColor("coloring.button_background", true));
 	setForeground(Gatherer.config.getColor("coloring.button_foreground", true));
@@ -224,5 +135,4 @@
 		source_nodes[i] = (FileNode) selection[i].getLastPathComponent();
 	    }
-	    ///ystem.err.println("Dropped files vector contains " + new_files.size() + " files.");
 	    event.acceptDrop(drag_action);
 	    // Action delete
@@ -246,15 +156,10 @@
 
     /** Used to notify this component that it has gained focus by some method other that mouse focus. */
-    public void gainFocus(){
-    }
-
-    public ArrayList getMetadata(File file) {
-	///ystem.err.println("UndoMetadata: " + file.getAbsolutePath());
-	return obsolete_metadata.getMetadata(file.getAbsolutePath(), true, new ArrayList(), file, false);
+    public void gainFocus() {
     }
 
     /** Any implementation of DragComponent must include this method so that a outsider can get at the underlying tree model behind the component. */
     public FileSystemModel getTreeModel(){
-	return (FileSystemModel) model;
+  	return (FileSystemModel) model;
     }
 
@@ -264,19 +169,5 @@
 
     /** This method is used to inform this component when it loses focus by means other than a drag mouse event, and should indicate this somehow. */
-    public void loseFocus(){
-    }
-
-    public void registerRedoSource(AbstractButton source) {
-	if(!redo_sources.contains(source)) {
-	    redo_sources.add(source);
-	    source.addActionListener(this);
-	}
-    }
-
-    public void registerUndoSource(AbstractButton source) {
-	if(!undo_sources.contains(source)) {
-	    undo_sources.add(source);
-	    source.addActionListener(this);
-	}
+    public void loseFocus() {
     }
 
@@ -284,214 +175,3 @@
 	this.group = group;
     }
-
-    public void undoAll() {
-	FileQueue immediate_queue = new FileQueue(true);
-	UndoJob undo_job = null;
-	while((undo_job = undo.pop()) != null) {
-	    undo_job.action(true, immediate_queue);
-	    // Now retrieve all other undo jobs with the same job-number and action them
-	    while((undo_job = undo.getJob(undo_job.ID())) != null) {
-		undo_job.action(true, immediate_queue);
-	    }
-	}
-	immediate_queue.run();
-	// Returns only when all undo actions complete.
-    }
-
-    private void showTree() {
-	JDialog dialog = new JDialog(Gatherer.g_man, "Recycle Bin Model");
-	dialog.setSize(new Dimension(400,300));
-	JPanel content_pane = (JPanel) dialog.getContentPane();
-	JTree tree = new JTree(model);
-	content_pane.setLayout(new BorderLayout());
-	content_pane.add(new JScrollPane(tree), BorderLayout.CENTER);
-	dialog.show();
-    }
-
-    private class UndoJob {
-	private FileNode record = null;
-	private FileNode source_parent = null;
-	private DragComponent source_model = null;
-	private DragComponent target_model = null;
-	private long id = 0;
-	private int type = -1;
-	private TreePath record_path = null;
-	private TreePath source_parent_path = null;
-	/** Undo file action Constructor.
-	 * @param id A unique <i>long</i> id number for all actions associated with a certain gesture.
-	 * @param source_model The source <strong>DragComponent</strong> where the new record originally came from. If this is <i>null</i> then it is assumed you are interested in using the 'recycle' bin model.
-	 * @param source_parent The previous parent <strong>FileNode</strong> of the new record.
-	 * @param target_model The target <strong>DragComponent</strong> where the new record is now.
-	 * @param record The new <strong>FileNode</strong> itself.
-	 * @param type An <i>int</i> indicating the action that has occured, not what undo action is needed.
-	 */
-	public UndoJob(long id, DragComponent source_model, FileNode source_parent, DragComponent target_model, FileNode record, int type) {
-	    this.id = id;
-	    this.record = record;
-	    if(record != null) {
-		this.record_path = new TreePath(record.getPath());
-	    }
-	    this.source_model = source_model;
-	    this.source_parent = source_parent;
-	    if(source_parent != null) {
-		this.source_parent_path = new TreePath(source_parent.getPath());
-	    }
-	    this.target_model = target_model;
-	    this.type = type;
-	}
-
-	public void action(boolean is_undo, FileQueue file_queue) {
-	    // Retrieve the lastest version of each file record
-	    FileNode latest_record = null;
-	    FileNode latest_source_parent = null;
-	    if(target_model != null && record_path != null) {
-		///ystem.err.println("Retrieving latest version of record from " + target_model + ".");
-		latest_record = ((FileSystemModel)target_model.getTreeModel()).getNode(record_path);
-	    }
-	    if(source_model != null && source_parent_path != null) {
-		///ystem.err.println("Retrieving latest version of source parent.");
-		latest_source_parent = ((FileSystemModel)source_model.getTreeModel()).getNode(source_parent_path);
-	    }
-	    // Of course if there are no newer versions, stick to the ones we've already got.
-	    if(latest_record == null) {
-		///ystem.err.println("Using original record.");
-		latest_record = record;
-	    }
-	    if(latest_source_parent == null) {
-		///ystem.err.println("Using original source parent.");
-		latest_source_parent = source_parent;
-	    }
-				// Heres the fraction, too much friction.
-	    switch(type) {
-	    case FILE_COPY:
-		// To undo a file copy we issue a delete file action on the destination file record.
-		file_queue.addJob(id, target_model, latest_record, source_model, latest_source_parent, FileJob.DELETE, !is_undo, true, false);
-		break;
-	    case FILE_DELETE:
-		// To undo a file delete we issue a copy file action from our recycle bin.
-		file_queue.addJob(id, target_model, latest_record, source_model, latest_source_parent, FileJob.MOVE, !is_undo, true, false);
-		break;
-	    case FILE_MOVE:
-		// This may be a legitimate move, or may be a side effect of an undelete. If the formed source model and parent will be non-null.
-		if(source_model != null && source_parent != null) {
-		    // To undo a file move we issue a move file action to return it to where it was.
-		    file_queue.addJob(id, target_model, latest_record, source_model, latest_source_parent, FileJob.MOVE, !is_undo, true, false);
-		}
-		// Otherwise we perform another delete.
-		else {
-		    file_queue.addJob(id, target_model, latest_record, source_model, latest_source_parent, FileJob.DELETE, !is_undo, true, false);
-		}
-		break;
-	    default:
-		///ystem.err.println("Unknown code.");
-	    }
-	}
-
-	public FileNode getRecord() {
-	    return record;
-	}
-
-	public long ID() {
-	    return id;
-	}
-    }
-
-    private class UndoJobAdder
-	implements Runnable {
-	private boolean undo_event;
-	private FileNode record;
-	private FileNode source_parent;
-	private DragComponent source_model;
-	private DragComponent target_model;
-	private int type;
-	private long id;
-	public UndoJobAdder(long id, int type, DragComponent source_model, FileNode source_parent, DragComponent target_model, FileNode record, boolean undo_event) {
-	    this.id = id;
-	    this.record = record;
-	    this.source_model = source_model;
-	    this.source_parent = source_parent;
-	    this.target_model = target_model;
-	    this.type = type;
-	    this.undo_event = undo_event;
-	}
-	public void run() {
-	    UndoJob job = new UndoJob(id, source_model, source_parent, target_model, record, type);
-	    if(undo_event) {
-		undo.push(job);
-	    }
-	    else {
-		redo.push(job);
-	    }
-	}
-    }
-
-    private class UndoStack
-	extends LinkedList {
-	private boolean enabled = false;
-	private boolean undo;
-	private int pos = 0;
-	public UndoStack(boolean undo) {
-	    this.undo = undo;
-	}
-	public void clear() {
-	    super.clear();
-	    pos = 0;
-	    if(enabled) {
-		setEnabled(false);
-	    }
-	}
-	public UndoJob getJob(long id) {
-	    UndoJob job = null;
-	    while(job == null && pos < size()) {
-		UndoJob temp = (UndoJob) get(pos);
-		if(temp.ID() == id) {
-		    job = temp;
-		    remove(temp);
-		}
-		else {
-		    pos++;
-		}
-	    }
-	    if(size() == 0) {
-		setEnabled(false);
-		pos = 0;
-	    }
-	    return job;
-	}
-	public void push(UndoJob job) {
-	    addFirst(job);
-	    pos = 0;
-	    if(!enabled) {
-		setEnabled(true);
-	    }
-	}
-	public UndoJob pop() {
-	    UndoJob job = null;
-	    if(size() > 0) {
-		job = (UndoJob) removeFirst();
-		if(size() == 0 && enabled) {
-		    setEnabled(false);
-		    pos = 0;
-		}
-	    }
-	    return job;
-	}
-	public void reset() {
-	    pos = 0;
-	}
-	private void setEnabled(boolean state) {
-	    ArrayList sources;
-	    if(undo) {
-		sources = undo_sources;
-	    }
-	    else {
-		sources = redo_sources;
-	    }
-	    for(int i = 0; i < sources.size(); i++) {
-		AbstractButton source = (AbstractButton) sources.get(i);
-		source.setEnabled(state);
-	    }
-	    enabled = state;
-	}
-    }
 }
