Changeset 34288

Show
Ignore:
Timestamp:
24.07.2020 15:54:07 (11 days ago)
Author:
ak19
Message:

Further fix to client-GLI > Rightclick Doc > Replace: if the replacement file is identically named to the original one being replaced, then GLI warns the user of this and the user can cancel out. Prior to this fix, even if the user cancelled out the file would still get uploaded to the remote server, replacing the original one there even though the local one would not get replaced and leaving remote and local collection out of sync. And it's the remote version that gets built, moreover. Adding listeners and firing changed events on successful copy, in order to now only do the replacement file upload to remote GS3 server iff the local copy took place successfully (and wasn't cancelled or went wrong).

Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileManager.java

    r34261 r34288  
    517517 
    518518    private class ReplaceTask 
    519     extends Thread 
     519    extends Thread implements FileCopiedSuccessListener 
    520520    { 
    521521    private CollectionTree collection_tree = null; 
     
    563563         
    564564        FileNode parent = (FileNode)collection_tree_node.getParent(); // store the original source's parent, need it several times after changing source 
    565         
    566         if(!isSameLeafName) { 
    567         // If the file name of the replacing file is NOT the same as the one being replaced 
    568         // copy the new file in - but don't bring metadata 
    569         file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, parent, FileJob.COPY_FILE_ONLY); 
    570         } 
    571          
    572         if (Gatherer.isGsdlRemote) { 
    573         String collection_name = CollectionManager.getLoadedCollectionName(); 
    574         Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection_name, collection_tree_node.getFile()); 
    575         Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, new File[] { new_file }, target_directory); 
    576         } 
    577565 
    578566        if(isSameLeafName) { 
    579567        // If the file name of the replacing file IS the same as the one being replaced 
    580         // perform a COPY operation, which will copy across metadata too, after confirming whether the user really wants to replace the source with identically named targed 
     568        // perform a COPY operation, which will copy across metadata too, after confirming whether the user really wants to replace the source with identically named target 
     569 
     570        // (a) First, this instance of ReplaceTask and no other starts listening to whether the user 
     571        // DIDN'T CANCEL out of an identical filename copy operation and if this local file copy 
     572        // was a success. If so, on successful file copy event fired (only then), the source file 
     573        // from the workspace tree will also be uploaded to the remote GS3  
     574        file_queue.addFileCopiedSuccessListener(this);  
     575 
     576        // (b) Now can finally add the COPY job to the queue 
    581577        file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, parent, FileJob.COPY); 
     578         
    582579        } else { 
    583         // If the file name of the replacing file is NOT the same as the one being replaced, final step to finish off: 
    584         // do a replace of old file with new file 
     580        // If the file name of the replacing file is NOT the same as the one being replaced 
     581        // (a) copy the new file in - but don't bring metadata 
     582        file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, parent, FileJob.COPY_FILE_ONLY); 
     583         
     584        // (b) final step to finish off: do a replace of old file with new file 
    585585        file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.REPLACE); 
    586586        } 
    587587 
     588 
    588589        //DebugStream.setDebugging(false, "FileManager.ReplaceTask"); 
    589  
     590    } 
     591     
     592     
     593    /** In order to detect that the user cancelled out of replacing an identically named target file,  
     594     * we now listen to events fired that the file was successfully copied across. Only then do we 
     595     * bother transferring the source file (from the workspace) into the target location in the 
     596     * collection on the remote file system. We don't do this if the user cancelled. 
     597     */ 
     598    public void fileCopiedSuccessfully(File new_file) {      
     599         
     600        //DebugStream.setDebugging(true, "FileManager.ReplaceTask.fileCopiedSuccessfully"); 
     601         
     602        if (Gatherer.isGsdlRemote) { 
     603        File target_directory = this.collection_tree_node.getFile().getParentFile(); 
     604        File collection_tree_node_file = this.collection_tree_node.getFile(); 
     605         
     606        String collection_name = CollectionManager.getLoadedCollectionName(); 
     607        Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection_name, collection_tree_node_file); 
     608        Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, new File[] { new_file }, target_directory); 
     609        } 
     610 
     611        // stop listening to further events fired now that we've handled this event successfully 
     612        file_queue.removeFileCopiedSuccessListener(this); 
     613        //DebugStream.setDebugging(false, "FileManager.ReplaceTask.fileCopiedSuccessfully"); 
    590614    } 
    591615    } 
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r31293 r34288  
    6969    private GProgressBar progress = null; 
    7070 
    71  
     71    /** The objects listening for FileCopiedSuccess events. */ 
     72    private ArrayList file_copied_success_listeners = new ArrayList(); 
     73     
    7274    /** Constructor. 
    7375     */ 
     
    8385    } 
    8486 
    85  
     87    public void fireFileCopiedSuccessfully(File new_file) { 
     88    // Send the event off to all the matching Listeners 
     89    for (int i = 0; i < file_copied_success_listeners.size(); i++) { 
     90        ((FileCopiedSuccessListener) file_copied_success_listeners.get(i)).fileCopiedSuccessfully(new_file); 
     91    } 
     92    } 
     93    public void addFileCopiedSuccessListener(FileCopiedSuccessListener listener) { 
     94    file_copied_success_listeners.add(listener); 
     95    } 
     96 
     97    public void removeFileCopiedSuccessListener(FileCopiedSuccessListener listener) 
     98    { 
     99    file_copied_success_listeners.remove(listener); 
     100    } 
     101     
    86102    /** 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). 
    87103     * @param id A long id unique to all jobs created by a single action. 
     
    410426    try { 
    411427        copyFile(source_file, target_file, true); 
     428        fireFileCopiedSuccessfully(source_file); 
    412429    } 
    413430    catch (FileAlreadyExistsException exception) { 
  • main/trunk/gli/src/org/greenstone/gatherer/gui/ConfigFileEditor.java

    r34266 r34288  
    383383        ElementOption elementToAdd = (ElementOption)chooseElementComboBox.getSelectedItem(); 
    384384        addElementToConfigFile(elementToAdd); 
    385          
     385        //editor.setCaretPosition(0); 
    386386    } 
    387387    }