Changeset 7360
- Timestamp:
- 2004-05-21T10:10:06+12:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/file/FileManager.java
r6539 r7360 43 43 import org.greenstone.gatherer.file.FileNode; 44 44 import org.greenstone.gatherer.file.FileQueue; 45 import org.greenstone.gatherer.gui.LongProgressBar; 45 46 import org.greenstone.gatherer.gui.NewFolderPrompt; 46 47 import org.greenstone.gatherer.gui.tree.DragTree; … … 146 147 private FileNode[] source_nodes; 147 148 private long id; 149 148 150 public Task(long id, DragComponent source, FileNode[] source_nodes, DragComponent target, FileNode target_node, byte type) { 149 151 this.id = id; … … 154 156 this.type = type; 155 157 } 156 public void run() { 157 // Reset, and calculate progress bar size. 158 159 public void run() 160 { 161 // Check there is something to do 162 if (source_nodes == null) { 163 return; 164 } 165 166 // Reset the progress bar and set it to indeterminate while calculating its size 167 LongProgressBar progress_bar = queue.getProgressBar(); 168 progress_bar.reset(); 169 progress_bar.setIndeterminate(true); 170 171 // Calculate the progress bar size 158 172 boolean cancelled = queue.calculateSize(source_nodes); 159 // Now we queue the job(s). Note that this may fail if a read only file is encountered and we have been asked to delete. 160 for(int i = 0; !cancelled && source_nodes != null && i < source_nodes.length; i++) { 161 queue.addJob(id, source, source_nodes[i], target, target_node, type, true, true, true); 173 if (!cancelled) { 174 // Queue the job(s) (this may fail if we are asked to delete a read only file) 175 for (int i = 0; i < source_nodes.length; i++) { 176 queue.addJob(id, source, source_nodes[i], target, target_node, type, true, true, true); 177 } 162 178 } 179 180 progress_bar.setIndeterminate(false); 163 181 } 164 182 } -
trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java
r6879 r7360 72 72 private JLabel file_status = null; 73 73 /** A list containing a queue of waiting movement jobs. */ 74 //private LinkedList queue;75 74 private ArrayList queue; 76 75 /** A progress bar which shows how many bytes, out of the total size of bytes, has been moved. */ … … 86 85 public FileQueue(boolean return_immediately) { 87 86 this.return_immediately = return_immediately; 88 this.queue = new ArrayList(); //LinkedList();87 this.queue = new ArrayList(); 89 88 String args[] = new String[2]; 90 89 args[0] = "0"; … … 141 140 * @see org.greenstone.gatherer.file.FileManager.Task#run() 142 141 */ 143 public boolean calculateSize(FileNode[] files) { 144 progress.reset(); 142 public boolean calculateSize(FileNode[] files) 143 { 144 file_status.setText(Dictionary.get("FileActions.Calculating_Size")); 145 145 progress.setString(Dictionary.get("FileActions.Calculating_Size")); 146 progress.setIndeterminate(true); 146 147 // Calculate the total file size of all the selected file nodes 147 148 Vector remaining = new Vector(); 148 for (int i = 0; !cancel_action && i < files.length; i++) {149 for (int i = 0; !cancel_action && i < files.length; i++) { 149 150 remaining.add(files[i]); 150 151 } 151 while (!cancel_action && remaining.size() > 0) {152 FileNode node = (FileNode) remaining.remove(0);153 if (node.isLeaf()) {152 while (!cancel_action && remaining.size() > 0) { 153 FileNode node = (FileNode) remaining.remove(0); 154 if (node.isLeaf()) { 154 155 progress.addMaximum(node.getFile().length()); 155 156 } 156 157 else { 157 for (int i = 0; !cancel_action && i < node.getChildCount(); i++) {158 for (int i = 0; !cancel_action && i < node.getChildCount(); i++) { 158 159 remaining.add(node.getChildAt(i)); 159 160 } 160 161 } 161 162 } 162 progress.setString(Dictionary.get("FileActions.No_Activity")); 163 progress.setIndeterminate(false); 163 164 164 // Now we return if calculation was cancelled so that the FileManagers Task can skip the addJob phase correctly. 165 if (cancel_action) {165 if (cancel_action) { 166 166 cancel_action = false; // reset 167 167 return true; … … 182 182 183 183 /** Access to the progress bar. */ 184 public LongProgressBar getProgress () {184 public LongProgressBar getProgressBar() { 185 185 return progress; 186 186 } … … 189 189 progress.setIndeterminate(true); 190 190 } 191 192 191 193 /** 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. 192 194 * @see org.greenstone.gatherer.Gatherer … … 199 201 * @see org.greenstone.gatherer.util.Utility 200 202 */ 201 public void run() { 203 public void run() 204 { 202 205 super.setName("FileQueue"); 203 while(!Gatherer.self.exit) { 206 207 while (!Gatherer.self.exit) { 204 208 try { 205 209 // Retrieve the next job … … 475 479 ///atherer.println("Delete/Move: " + origin_node); 476 480 ///atherer.println(queue.size() + " jobs remain in queue"); 481 482 if (source_file.isFile()) { 483 progress.addValue(source_file.length()); 484 } 485 477 486 // If the source is an empty directory or a file. Don't do anything to the root node of a tree. 478 487 File[] child_list = source_file.listFiles(); … … 487 496 // update status area 488 497 String args[] = new String[1]; 489 args[0] = "" + (queue.size() + 1) + ""; 490 //job_status.setText(Dictionary.get("FileActions.Jobs", args)); 498 // args[0] = "" + (queue.size() + 1) + ""; 491 499 args[0] = Utility.formatPath("FileActions.Deleting", source_file.getAbsolutePath(), file_status.getSize().width); 492 500 file_status.setText(Dictionary.get("FileActions.Deleting", args)); … … 510 518 File recycled_file = null; 511 519 FileNode recycled_parent = null; 512 if(job.type == FileJob.DELETE) {513 514 /** If we ever decide to reenable undo then this code will have to be seriously improved.515 // See if this record already has a previous recycle folder noted in the recycle folder mappings.516 recycled_parent = (FileNode) recycle_folder_mappings.get(origin_node);517 if(recycled_parent != null) {518 recycle_folder_mappings.remove(origin_node);519 }520 else {521 recycled_parent = (FileNode) Gatherer.c_man.undo.getTreeModel().getRoot();522 }523 // This may be a directory which we have already added previously.524 if(completed_folder_mappings.containsKey(origin_node)) {525 FileNode recycled_record = (FileNode) completed_folder_mappings.get(origin_node);526 // Replace the temporary directory record in the undo tree with this one.527 SynchronizedTreeModelTools.replaceNode(Gatherer.c_man.undo.getTreeModel(), recycled_record, origin_node);528 origin_node.setFile(recycled_record.getFile());529 }530 else {531 // copy the file to the recycle bin532 recycled_file = new File(recycled_parent.getFile(), origin_node.toString());533 // If the file already exists, delete it.534 if(recycled_file.exists()) {535 recycled_file.delete();536 }537 recycled_file.deleteOnExit();538 copyFile(source_file, recycled_file, progress);539 origin_node.setFile(recycled_file);540 // Add the node to the appropriate place in the UndoManagers tree model. Unfortunately this one does have the possibility of altering the GUI (if the removeNodeFromParent above hasn't occured yet), so we must put it on the queue.541 SynchronizedTreeModelTools.insertNodeInto(Gatherer.c_man.undo.getTreeModel(), recycled_parent, origin_node);542 }543 Gatherer.c_man.undo.addMetadata(source_file, metadatum);544 **/545 }546 520 // delete the source file 547 521 Utility.delete(source_file); 548 /**549 // create undo job as necessary. File move would have been handled above.550 if(job.undoable) {551 job.undoable = false;552 // The target is null, indicating that we moved this file to the recycle bin. The UndoManager will replace null with 'this'.553 Gatherer.c_man.undo.addUndo(job.ID(), UndoManager.FILE_DELETE, job.source, parent_record, null, origin_node, job.undo);554 }555 recycled_parent = null;556 recycled_file = null;557 **/558 //metadatum = null;559 522 } 560 523 // Else the source is a directory and it has children remaining … … 565 528 // Don't worry about all this for true file move actions. 566 529 if(job.type == FileJob.DELETE) { 567 /** Again, if we reenable undo then this code must be debugged.568 // See if this record already has a previous recycle folder noted in the recycle folder mappings.569 FileNode parent = (FileNode) recycle_folder_mappings.get(origin_node);570 if(parent != null) {571 recycle_folder_mappings.remove(origin_node);572 }573 else {574 parent = (FileNode) Gatherer.c_man.undo.getTreeModel().getRoot();575 }576 // We must add the folder node to our undo manager tree now, so we'll have something to add children to. We use a copy of the directory file record.577 File recycle_folder = new File(parent.getFile(), origin_node.toString());578 recycle_folder.deleteOnExit();579 recycle_folder.mkdirs();580 recycle_folder_record = new FileNode(recycle_folder);581 // Add this node to the undo tree model.582 SynchronizedTreeModelTools.insertNodeInto(Gatherer.c_man.undo.getTreeModel(), parent, recycle_folder_record);583 // We add an entry to the complete mappings to ensure this directory isn't added again584 completed_folder_mappings.put(origin_node, recycle_folder_record);585 ///ystem.err.println("Added completed directories mapping " + origin_node);586 **/587 530 // queue all of its children, (both filtered and non-filtered), but for deleting only. Don't queue jobs for a current move event, as they would be queued as part of copying. I have no idea way, per sec, however the children within the origin node are always invalid during deletion (there are several copies of some nodes?!?). I'll check that each child is only added once. 588 531 ///ystem.err.println("Directory has " + origin_node.getChildCount() + " children."); … … 638 581 } 639 582 // Reset status area 640 //job_status.setText(Dictionary.get("No_Selection"));641 583 file_status.setText(Dictionary.get("FileActions.No_Activity")); 642 584 progress.reset(); … … 672 614 this.stop_button = stop_button; 673 615 } 674 675 /** 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.676 * @param wait_allowed The new state of the wait_allowed flag, as a boolean.677 */678 /* private void setWaitAllowed(boolean wait_allowed) {679 this.wait_allowed = wait_allowed;680 } */681 /** Restore the progress bar so that it updates normally.682 * @see org.greenstone.gatherer.gui.LongProgressBar683 */684 /* synchronized private void unpause() {685 progress.setIndeterminate(false);686 if(previous != null) {687 progress.setString(previous);688 previous = null;689 }690 } */691 616 692 617 /** Called when the user makes some selection in one of the trees we are listening to. From this we update the status details. */ … … 708 633 } 709 634 selection = null; 710 // String args[] = new String[2];711 // args[0] = "" + file_count + "";712 // args[1] = "" + dir_count + "";713 // job_status.setText(get("Selected", args));714 // args = null;715 635 } 716 636 tree = null; -
trunk/gli/src/org/greenstone/gatherer/gui/GatherPane.java
r7163 r7360 364 364 //JLabel job_status = job_queue.getJobStatus(); 365 365 366 JProgressBar progress = file_queue.getProgress();366 JProgressBar progress_bar = file_queue.getProgressBar(); 367 367 368 368 JPanel button_pane = new JPanel(); … … 402 402 progress_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); 403 403 progress_pane.setLayout(new BorderLayout()); 404 progress_pane.add(progress , BorderLayout.CENTER);404 progress_pane.add(progress_bar, BorderLayout.CENTER); 405 405 406 406 inner_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10,10,10,10), BorderFactory.createLoweredBevelBorder()));
Note:
See TracChangeset
for help on using the changeset viewer.