- Timestamp:
- 2003-10-03T14:07:35+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java
r5536 r5564 32 32 import javax.swing.event.*; 33 33 import javax.swing.tree.*; 34 import org.greenstone.gatherer.Dictionary; 34 35 import org.greenstone.gatherer.Gatherer; 35 36 import org.greenstone.gatherer.file.FileJob; 36 37 import org.greenstone.gatherer.file.FileNode; 37 38 import org.greenstone.gatherer.gui.LongProgressBar; 38 import org.greenstone.gatherer.gui.SmudgyLabel;39 39 import org.greenstone.gatherer.gui.tree.DragTree; 40 40 import org.greenstone.gatherer.msm.GDMManager; … … 44 44 import org.greenstone.gatherer.util.SynchronizedTreeModelTools; 45 45 import org.greenstone.gatherer.util.Utility; 46 46 47 /** A threaded object which processes a queue of file actions such as copying and movement. It also handles updating the various trees involved so they are an accurate representation of the file system they are meant to match. 47 48 * @author John Thompson, Greenstone Digital Library, University of Waikato … … 64 65 private HashMap recycle_folder_mappings = new HashMap(); 65 66 /** A label explaining the current moving files status. */ 66 private JLabel file_status = null; // was a SmudgyLabel 67 /** A label explaining the status of this job. */ 68 //private JLabel job_status = null; // no longer used 67 private JLabel file_status = null; 69 68 /** A list containing a queue of waiting movement jobs. */ 70 69 //private LinkedList queue; … … 75 74 private String previous = null; 76 75 /** Constructor. 77 78 79 80 81 76 * @param return_immediately true to cause this file queue to return from run() as soon as there are no jobs left on the queue. 77 * @see org.greenstone.gatherer.Configuration 78 * @see org.greenstone.gatherer.gui.Coloring 79 * @see org.greenstone.gatherer.gui.LongProgressBar 80 */ 82 81 public FileQueue(boolean return_immediately) { 83 82 this.return_immediately = return_immediately; … … 86 85 args[0] = "0"; 87 86 args[1] = "0"; 88 file_status = new JLabel( get("FileActions.Selected", args)); //new SmudgyLabel(get("Selected", args));89 //job_status = new JLabel(get("No_Activity"));87 file_status = new JLabel(); 88 Dictionary.setText(file_status, "FileActions.Selected", args); 90 89 progress = new LongProgressBar(); 91 90 progress.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false)); 92 91 progress.setForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false)); 93 progress.setString( get("FileActions.No_Activity"));92 progress.setString(Dictionary.newget("FileActions.No_Activity")); 94 93 progress.setStringPainted(true); 95 94 args = null; … … 106 105 107 106 /** Add a new job to the queue, specifiying as many arguments as is necessary to complete this type of job (ie delete needs no target information). 108 109 110 111 112 113 114 115 116 107 * @param id A long id unique to all jobs created by a single action. 108 * @param source The DragComponent source of this file, most likely a DragTree. 109 * @param child The FileNode you wish to mode. 110 * @param target The DragComponent to move the file to, again most likely a DragTree. 111 * @param parent The files new FileNode parent within the target. 112 * @param type The type of this movement as an int, either COPY or DELETE. 113 * @param undo true if this job should generate undo jobs, false for redo ones. 114 * @param undoable true if this job can generate undo or redo jobs at all, false otherwise. 115 */ 117 116 public void addJob(long id, DragComponent source, FileNode child, DragComponent target, FileNode parent, byte type, boolean undo, boolean undoable, boolean folder_level) { 118 117 addJob(id, source, child, target, parent, type, undo, undoable, folder_level, -1); 119 118 } 119 120 120 synchronized public void addJob(long id, DragComponent source, FileNode child, DragComponent target, FileNode parent, byte type, boolean undo, boolean undoable, boolean folder_level, int position) { 121 121 FileJob job = new FileJob(id, source, child, target, parent, type, undo, undoable); … … 131 131 } 132 132 133 134 135 136 137 133 /** Calculates the total deep file size of the selected file nodes. 134 * @param files a FileNode[] of selected files 135 * @return true if a cancel was signalled, false otherwise 136 * @see org.greenstone.gatherer.file.FileManager.Task#run() 137 */ 138 138 public boolean calculateSize(FileNode[] files) { 139 139 progress.reset(); 140 progress.setString( get("FileActions.Calculating_Size"));140 progress.setString(Dictionary.newget("FileActions.Calculating_Size")); 141 141 progress.setIndeterminate(true); 142 142 Vector remaining = new Vector(); … … 155 155 } 156 156 } 157 progress.setString( get("FileActions.No_Activity"));157 progress.setString(Dictionary.newget("FileActions.No_Activity")); 158 158 progress.setIndeterminate(false); 159 159 // Now we return if calculation was cancelled so that the FileManagers Task can skip the addJob phase correctly. 160 160 if(cancel_action) { 161 162 161 cancel_action = false; // reset 162 return true; 163 163 } 164 164 else { 165 165 return false; 166 166 } 167 167 } … … 188 188 } 189 189 /** The run method exists in every thread, and here it is used to work its way through the queue of Jobs. If no jobs are waiting and it cans, it waits until a job arrives. If a job is present then it is either COPIED or DELETED, with the records being copied or removed as necessary, and directories being recursed through. Finally the user can press cancel to cause the loop to prematurely dump the job queue then wait. 190 191 192 193 194 195 196 197 198 190 * @see org.greenstone.gatherer.Gatherer 191 * @see org.greenstone.gatherer.collection.CollectionManager 192 * @see org.greenstone.gatherer.file.FileJob 193 * @see org.greenstone.gatherer.file.FileNode 194 * @see org.greenstone.gatherer.gui.LongProgressBar 195 * @see org.greenstone.gatherer.msm.MetadataSetManager 196 * @see org.greenstone.gatherer.undo.UndoManager 197 * @see org.greenstone.gatherer.util.Utility 198 */ 199 199 public void run() { 200 200 super.setName("FileQueue"); … … 239 239 else { 240 240 ///atherer.println("Opps! This filename already exists. Give the user some options."); 241 Object[] options = { get("General.Yes"), get("FileActions.Yes_To_All"), get("General.No"),get("General.Cancel") };242 int result = JOptionPane.showOptionDialog(Gatherer.g_man, get("FileActions.File_Exists", target_file.getName()),get("General.Warning"), JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);241 Object[] options = { Dictionary.newget("General.Yes"), Dictionary.newget("FileActions.Yes_To_All"), Dictionary.newget("General.No"), Dictionary.newget("General.Cancel") }; 242 int result = JOptionPane.showOptionDialog(Gatherer.g_man, Dictionary.newget("FileActions.File_Exists", target_file.getName()), Dictionary.newget("General.Warning"), JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]); 243 243 switch(result) { 244 244 case 1: // Yes To All … … 271 271 String args[] = new String[1]; 272 272 args[0] = "" + (queue.size() + 1) + ""; 273 //job_status.setText(get("Jobs", args));274 273 if(job.type == FileJob.COPY) { 275 274 args[0] = Utility.formatPath("FileActions.Copying", source_file.getAbsolutePath(), file_status.getSize().width); 276 file_status.setText( get("FileActions.Copying", args));275 file_status.setText(Dictionary.newget("FileActions.Copying", args)); 277 276 } 278 277 else { 279 278 args[0] = Utility.formatPath("FileActions.Moving", source_file.getAbsolutePath(), file_status.getSize().width); 280 file_status.setText( get("FileActions.Moving", args));279 file_status.setText(Dictionary.newget("FileActions.Moving", args)); 281 280 } 282 281 args = null; … … 293 292 cancel_action = true; 294 293 // Show warning. 295 JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.File_Not_Found_Message", source_file.getName()),get("FileActions.File_Not_Found_Title"), JOptionPane.ERROR_MESSAGE);294 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.File_Not_Found_Message", source_file.getName()), Dictionary.newget("FileActions.File_Not_Found_Title"), JOptionPane.ERROR_MESSAGE); 296 295 // Force refresh of source folder. 297 296 source_model.refresh(new TreePath(((FileNode)origin_node.getParent()).getPath())); … … 301 300 cancel_action = true; 302 301 // Show warning. 303 JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.File_Already_Exists_Message", target_file.getName()),get("FileActions.File_Already_Exists_Title"), JOptionPane.ERROR_MESSAGE);302 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.File_Already_Exists_Message", target_file.getName()), Dictionary.newget("FileActions.File_Already_Exists_Title"), JOptionPane.ERROR_MESSAGE); 304 303 // Nothing else can be done by the Gatherer. 305 304 } … … 308 307 cancel_action = true; 309 308 // Show warning. The message body of the expection explains how much more space is required for this file copy. 310 JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.Insufficient_Space_Message", is_exception.getMessage()),get("FileActions.Insufficient_Space_Title"), JOptionPane.ERROR_MESSAGE);309 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.Insufficient_Space_Message", is_exception.getMessage()), Dictionary.newget("FileActions.Insufficient_Space_Title"), JOptionPane.ERROR_MESSAGE); 311 310 // Nothing else can be done by the Gatherer. In fact if we are really out of space I'm not even sure we can quit safely. 312 311 } … … 315 314 cancel_action = true; 316 315 // Show warning 317 JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.Unknown_File_Error_Message"),get("FileActions.Unknown_File_Error_Title"), JOptionPane.ERROR_MESSAGE);316 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.Unknown_File_Error_Message"), Dictionary.newget("FileActions.Unknown_File_Error_Title"), JOptionPane.ERROR_MESSAGE); 318 317 // Nothing else we can do. 319 318 } … … 322 321 cancel_action = true; 323 322 // Show warning 324 JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.Write_Not_Permitted_Message", target_file.getAbsolutePath()),get("FileActions.Write_Not_Permitted_Title"), JOptionPane.ERROR_MESSAGE);323 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.Write_Not_Permitted_Message", target_file.getAbsolutePath()), Dictionary.newget("FileActions.Write_Not_Permitted_Title"), JOptionPane.ERROR_MESSAGE); 325 324 // Nothing else we can do. 326 325 } … … 378 377 // Else inform the users that a directory already exists and files will be copied into it 379 378 //else { 380 // JOptionPane.showMessageDialog(null, get("Directory_Exists", target_file.toString()),get("General.Warning"), JOptionPane.WARNING_MESSAGE);379 // JOptionPane.showMessageDialog(null, Dictionary.newget("Directory_Exists", target_file.toString()), Dictionary.newget("General.Warning"), JOptionPane.WARNING_MESSAGE); 381 380 //} 382 381 // Queue non-filtered child files for copying. If this directory already existed, the child records will have to generate the undo jobs, as we don't want to entirely delete this directory if it already existed. … … 401 400 cancel_action = true; 402 401 // Show warning. 403 JOptionPane.showMessageDialog(Gatherer.g_man, get("FileActions.File_Not_Found_Message", source_file.getName()),get("FileActions.File_Not_Found_Title"), JOptionPane.ERROR_MESSAGE);402 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.newget("FileActions.File_Not_Found_Message", source_file.getName()), Dictionary.newget("FileActions.File_Not_Found_Title"), JOptionPane.ERROR_MESSAGE); 404 403 // Force refresh of source folder. 405 404 source_model.refresh(new TreePath(((FileNode)origin_node.getParent()).getPath())); … … 457 456 String args[] = new String[1]; 458 457 args[0] = "" + (queue.size() + 1) + ""; 459 //job_status.setText( get("Jobs", args));458 //job_status.setText(Dictionary.newget("Jobs", args)); 460 459 args[0] = Utility.formatPath("FileActions.Deleting", source_file.getAbsolutePath(), file_status.getSize().width); 461 file_status.setText( get("FileActions.Deleting", args));460 file_status.setText(Dictionary.newget("FileActions.Deleting", args)); 462 461 args = null; 463 462 … … 593 592 } 594 593 // Reset status area 595 //job_status.setText( get("No_Selection"));596 file_status.setText( get("FileActions.No_Activity"));594 //job_status.setText(Dictionary.newget("No_Selection")); 595 file_status.setText(Dictionary.newget("FileActions.No_Activity")); 597 596 progress.reset(); 598 progress.setString( get("FileActions.No_Activity"));597 progress.setString(Dictionary.newget("FileActions.No_Activity")); 599 598 yes_to_all = false; 600 599 completed_folder_mappings.clear(); … … 615 614 } 616 615 /** A second lock is necessary to prevent the thread waiting, because its notify occured momentarily before it waited. If the flag is set then the thread can't wait, but loops around. This may chew processor time so should only be used if you are certain files are about to be placed on the queue. 617 618 616 * @param wait_allowed The new state of the wait_allowed flag, as a boolean. 617 */ 619 618 public void setWaitAllowed(boolean wait_allowed) { 620 619 this.wait_allowed = wait_allowed; 621 620 } 622 621 /** Restore the progress bar so that it updates normally. 623 624 622 * @see org.greenstone.gatherer.gui.LongProgressBar 623 */ 625 624 synchronized public void unpause() { 626 625 progress.setIndeterminate(false); … … 730 729 } 731 730 } 732 /** Retrieve a phrase from the dictionary based on the key. 733 * @param key The key index as a String. 734 * @return The desired phrase also as a String. 735 */ 736 private String get(String key) { 737 return get(key, (String[])null); 738 } 739 /** Retrieve a phrase from the dictionary based on the key, and taking into account the given argument. 740 * @param key The key index as a String. 741 * @param args A String which is the argument to be added to the phrase. 742 * @return The desired phrase also as a String. 743 */ 744 private String get(String key, String arg) { 745 String args[] = new String[1]; 746 args[0] = arg; 747 return get(key, args); 748 } 749 /** Retrieve a phrase from the dictionary based on the key, and taking into account the given arguments. 750 * @param key The key index as a String. 751 * @param args A String[] of arguments to be added to the phrase. 752 * @return The desired phrase also as a String. 753 * @see org.greenstone.gatherer.Dictionary 754 * @see org.greenstone.gatherer.Gatherer 755 */ 756 private String get(String key, String args[]) { 757 if(key.indexOf('.') == -1) { 758 key = "FileActions." + key; 759 } 760 return Gatherer.dictionary.get(key, args); 761 } 731 762 732 763 733 private FileJob removeJob(int position) {
Note:
See TracChangeset
for help on using the changeset viewer.