Changeset 7360


Ignore:
Timestamp:
2004-05-21T10:10:06+12:00 (20 years ago)
Author:
mdewsnip
Message:

Fixed the progress bar so

a) It says "Calculating total size of selecting files" instead of "No action requested" when calculating progress bar size

b) It stays as a "back and forth" (indeterminate) bar right up until it starts copying/moving/deleting. There used to be a gap (quite large on slow machines) where it would look like nothing was happening.

c) You now get a progress bar when deleting!

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  
    4343import org.greenstone.gatherer.file.FileNode;
    4444import org.greenstone.gatherer.file.FileQueue;
     45import org.greenstone.gatherer.gui.LongProgressBar;
    4546import org.greenstone.gatherer.gui.NewFolderPrompt;
    4647import org.greenstone.gatherer.gui.tree.DragTree;
     
    146147    private FileNode[] source_nodes;
    147148    private long id;
     149
    148150    public Task(long id, DragComponent source, FileNode[] source_nodes, DragComponent target, FileNode target_node, byte type) {
    149151        this.id = id;
     
    154156        this.type = type;
    155157    }
    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
    158172        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        }
    162178        }
     179
     180        progress_bar.setIndeterminate(false);
    163181    }
    164182    }
  • trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r6879 r7360  
    7272    private JLabel file_status = null;
    7373    /** A list containing a queue of waiting movement jobs. */
    74     //private LinkedList queue;
    7574    private ArrayList queue;
    7675    /** A progress bar which shows how many bytes, out of the total size of bytes, has been moved. */
     
    8685    public FileQueue(boolean return_immediately) {
    8786    this.return_immediately = return_immediately;
    88     this.queue = new ArrayList();//LinkedList();
     87    this.queue = new ArrayList();
    8988    String args[] = new String[2];
    9089    args[0] = "0";
     
    141140     * @see org.greenstone.gatherer.file.FileManager.Task#run()
    142141     */
    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"));
    145145    progress.setString(Dictionary.get("FileActions.Calculating_Size"));
    146     progress.setIndeterminate(true);
     146
     147    // Calculate the total file size of all the selected file nodes
    147148    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++) {
    149150        remaining.add(files[i]);
    150151    }
    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()) {
    154155        progress.addMaximum(node.getFile().length());
    155156        }
    156157        else {
    157         for(int i = 0; !cancel_action && i < node.getChildCount(); i++) {
     158        for (int i = 0; !cancel_action && i < node.getChildCount(); i++) {
    158159            remaining.add(node.getChildAt(i));
    159160        }
    160161        }
    161162    }
    162     progress.setString(Dictionary.get("FileActions.No_Activity"));
    163     progress.setIndeterminate(false);
     163
    164164    // 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) {
    166166        cancel_action = false; // reset
    167167        return true;
     
    182182
    183183    /** Access to the progress bar. */
    184     public LongProgressBar getProgress() {
     184    public LongProgressBar getProgressBar() {
    185185    return progress;
    186186    }
     
    189189    progress.setIndeterminate(true);
    190190    }
     191
     192
    191193    /** 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.
    192194     * @see org.greenstone.gatherer.Gatherer
     
    199201     * @see org.greenstone.gatherer.util.Utility
    200202     */
    201     public void run() {
     203    public void run()
     204    {
    202205    super.setName("FileQueue");
    203     while(!Gatherer.self.exit) {
     206
     207    while (!Gatherer.self.exit) {
    204208        try {
    205209        // Retrieve the next job
     
    475479            ///atherer.println("Delete/Move: " + origin_node);
    476480            ///atherer.println(queue.size() + " jobs remain in queue");
     481
     482            if (source_file.isFile()) {
     483                progress.addValue(source_file.length());
     484            }
     485
    477486            // If the source is an empty directory or a file. Don't do anything to the root node of a tree.
    478487            File[] child_list = source_file.listFiles();
     
    487496                // update status area
    488497                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) + "";
    491499                args[0] = Utility.formatPath("FileActions.Deleting", source_file.getAbsolutePath(), file_status.getSize().width);
    492500                file_status.setText(Dictionary.get("FileActions.Deleting", args));
     
    510518                File recycled_file = null;
    511519                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 bin
    532                     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                 }
    546520                // delete the source file
    547521                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;
    559522            }
    560523            // Else the source is a directory and it has children remaining
     
    565528                // Don't worry about all this for true file move actions.
    566529                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 again
    584                 completed_folder_mappings.put(origin_node, recycle_folder_record);
    585                 ///ystem.err.println("Added completed directories mapping " + origin_node);
    586                 **/
    587530                   // 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.
    588531                   ///ystem.err.println("Directory has " + origin_node.getChildCount() + " children.");
     
    638581            }
    639582            // Reset status area
    640             //job_status.setText(Dictionary.get("No_Selection"));
    641583            file_status.setText(Dictionary.get("FileActions.No_Activity"));
    642584            progress.reset();
     
    672614    this.stop_button = stop_button;
    673615    }
    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.LongProgressBar
    683      */
    684     /* synchronized private void unpause() {
    685     progress.setIndeterminate(false);
    686     if(previous != null) {
    687         progress.setString(previous);
    688         previous = null;
    689     }
    690     } */
    691616
    692617    /** Called when the user makes some selection in one of the trees we are listening to. From this we update the status details. */
     
    708633        }
    709634        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;
    715635    }
    716636    tree = null;
  • trunk/gli/src/org/greenstone/gatherer/gui/GatherPane.java

    r7163 r7360  
    364364    //JLabel job_status = job_queue.getJobStatus();
    365365
    366     JProgressBar progress = file_queue.getProgress();
     366    JProgressBar progress_bar = file_queue.getProgressBar();
    367367
    368368    JPanel button_pane = new JPanel();
     
    402402    progress_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
    403403    progress_pane.setLayout(new BorderLayout());
    404     progress_pane.add(progress, BorderLayout.CENTER);
     404    progress_pane.add(progress_bar, BorderLayout.CENTER);
    405405
    406406    inner_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10,10,10,10), BorderFactory.createLoweredBevelBorder()));
Note: See TracChangeset for help on using the changeset viewer.