Changeset 11314


Ignore:
Timestamp:
2006-03-08T17:17:07+13:00 (18 years ago)
Author:
kjdon
Message:

added in COPY_FILE_ONLY and REPLACE jobs. the first copies a file in without bringing metadata (the first step in a replace) and the second 'replaces' a file with another (already in the collection) by moving the metadata over and deleting the first

Location:
trunk/gli/src/org/greenstone/gatherer/file
Files:
2 edited

Legend:

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

    r11246 r11314  
    5151import org.greenstone.gatherer.util.Utility;
    5252
    53 
    5453/** Manages the moving of files within a separate thread.
    5554 * @author John Thompson, NZDL Project, University of Waikato
     
    368367    }
    369368    }
     369
     370    public void replaceCollectionFile(CollectionTree collection_tree, CollectionTreeNode collection_tree_node)
     371    {
     372    // This must go in a separate thread because we need the progress bar to work (remote Greenstone server)
     373    new ReplaceTask(collection_tree, collection_tree_node).start();
     374    }
     375
     376
     377    private class ReplaceTask
     378    extends Thread
     379    {
     380    private CollectionTree collection_tree = null;
     381    private CollectionTreeNode collection_tree_node = null;
     382
     383    public ReplaceTask(CollectionTree collection_tree, CollectionTreeNode collection_tree_node)
     384    {
     385        this.collection_tree = collection_tree;
     386        this.collection_tree_node = collection_tree_node;
     387    }
     388
     389    public void run()
     390    {
     391        JFileChooser file_chooser = new JFileChooser();
     392        file_chooser.setDialogTitle(Dictionary.get("ReplacePrompt.Title"));
     393        File new_file = null;
     394        int return_val = file_chooser.showOpenDialog(null);
     395        if(return_val == JFileChooser.APPROVE_OPTION) {
     396        new_file = file_chooser.getSelectedFile();
     397        }
     398       
     399        if (new_file == null) {
     400        return;
     401        }
     402       
     403        // make up a node for the file to bring in
     404        WorkspaceTreeNode source_node = new WorkspaceTreeNode(new_file);
     405
     406        File target_directory = collection_tree_node.getFile().getParentFile();
     407        CollectionTreeNode new_collection_tree_node = new CollectionTreeNode(new File(target_directory, new_file.getName()));
     408        // copy the new file in - but don't bring metadata
     409        file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, (FileNode)collection_tree_node.getParent(),  FileJob.COPY_FILE_ONLY);
     410        // do a replace of old file with new file
     411        file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.REPLACE);
     412
     413    }
     414    }
     415   
    370416}
     417
     418
     419
     420
  • trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r11242 r11314  
    479479
    480480    // Copy the non-folder level metadata assigned to the original file to the new file
    481     ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedDirectlyToExternalFile(source_file);
    482     MetadataXMLFileManager.addMetadata((CollectionTreeNode) new_target_node, assigned_metadata);
     481    if (file_job.type == FileJob.COPY) {
     482        // do metadata too
     483        ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedDirectlyToExternalFile(source_file);
     484        MetadataXMLFileManager.addMetadata((CollectionTreeNode) new_target_node, assigned_metadata);
     485    }
    483486    }
    484487
     
    536539    MetadataXMLFileManager.addMetadata((CollectionTreeNode) new_target_node, assigned_metadata);
    537540    }
    538 
     541   
     542    /** all this does is move the metadata, and delete the source */
     543    private void doFileReplace(FileJob file_job) {
     544    FileNode source_node = file_job.getOrigin();
     545    FileNode target_node = file_job.getDestination();
     546
     547    File source_file = source_node.getFile();
     548    File target_file = target_node.getFile();
     549    // Move the non-folder level metadata assigned to the original file to the new file
     550    CollectionTreeNode new_target_node = new CollectionTreeNode(target_file);
     551    ArrayList assigned_metadata = MetadataXMLFileManager.getMetadataAssignedDirectlyToFile(source_file);
     552    MetadataXMLFileManager.removeMetadata((CollectionTreeNode) source_node, assigned_metadata);
     553    MetadataXMLFileManager.addMetadata((CollectionTreeNode) new_target_node, assigned_metadata);
     554
     555    // now delete the original
     556    doFileDelete(file_job);
     557    }
    539558
    540559    private void processFileJob(FileJob file_job)
     
    562581        file_status.setText(Dictionary.get("FileActions.Deleting", formatPath("FileActions.Deleting", source_file.getAbsolutePath(), file_status.getSize().width)));
    563582        doEmptyDirectoryDelete(file_job);
     583        return;
    564584    }
    565585
     
    575595        doDirectoryDelete(file_job);
    576596        }
     597        return;
    577598    }
    578599
    579600    // Copy job
    580     if (file_job.type == FileJob.COPY) {
     601    if (file_job.type == FileJob.COPY || file_job.type == FileJob.COPY_FILE_ONLY) {
    581602        file_status.setText(Dictionary.get("FileActions.Copying", formatPath("FileActions.Copying", source_file.getAbsolutePath(), file_status.getSize().width)));
    582603        if (source_file.isFile()) {
     
    588609        doDirectoryCopy(file_job);
    589610        }
     611        return;
    590612    }
    591613
     
    601623        doDirectoryMove(file_job);
    602624        }
    603     }
     625        return;
     626    }
     627    // Replace job
     628    if (file_job.type == FileJob.REPLACE) {
     629        file_status.setText(Dictionary.get("FileActions.Replacing", formatPath("FileActions.Replacing", source_file.getAbsolutePath(), file_status.getSize().width)));
     630        doFileReplace(file_job);
     631        return;
     632    }
     633   
     634       
     635       
     636       
    604637    }
    605638
Note: See TracChangeset for help on using the changeset viewer.