Changeset 37191


Ignore:
Timestamp:
2023-01-28T15:43:52+13:00 (15 months ago)
Author:
kjdon
Message:

added 'new file' into the right click menu in the collection tree. Its handled using replacefile task, but instead of replacing the current file, its using the specified node as the parent, and adding the new file into that folder

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

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionTree.java

    r23455 r37191  
    151151    private JMenuItem metaaudit = null;
    152152    private JMenuItem new_folder = null;
     153    private JMenuItem new_file = null;
    153154    private JMenuItem new_dummy_doc = null;
    154155    private JMenuItem refresh = null; // for refreshing folder view
     
    267268        add(new_folder);
    268269
     270        new_file = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_File"));
     271        new_file.addActionListener(this);
     272        add(new_file);
     273
    269274        new_dummy_doc = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Dummy_Doc"));
    270275        new_dummy_doc.addActionListener(this);
     
    358363        add(new_folder);
    359364
     365       
     366        new_file = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_File"));
     367        new_file.addActionListener(this);
     368        add(new_file);
     369
    360370        new_dummy_doc = new JMenuItem(Dictionary.get("CollectionPopupMenu.New_Dummy_Doc"));
    361371        new_dummy_doc.addActionListener(this);
     
    415425        Gatherer.f_man.newFolder(collection_tree, node);
    416426        }
    417 
     427        else if (source == new_file) {
     428        Gatherer.f_man.newCollectionFile(collection_tree, node);
     429        }
    418430        // New dummy doc
    419431        else if (source == new_dummy_doc) {
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileManager.java

    r36237 r37191  
    6868    public static final int FILE_TYPE = 0;
    6969    public static final int FOLDER_TYPE = 1;
     70
    7071    protected static File startup_directory = null;
    7172
     
    509510    }
    510511
     512    public void newCollectionFile(CollectionTree collection_tree, CollectionTreeNode parent_node)
     513    {
     514    new ReplaceOrNewTask(collection_tree, parent_node, false ).start();
     515    }
     516
    511517    public void replaceCollectionFile(CollectionTree collection_tree, CollectionTreeNode collection_tree_node)
    512518    {
    513519    // This must go in a separate thread because we need the progress bar to work (remote Greenstone server)
    514     new ReplaceTask(collection_tree, collection_tree_node).start();
    515     }
    516 
    517 
    518     private class ReplaceTask
     520    new ReplaceOrNewTask(collection_tree, collection_tree_node, true).start();
     521    }
     522
     523
     524    private class ReplaceOrNewTask
    519525    extends Thread implements FileCopiedSuccessListener
    520526    {
    521527    private CollectionTree collection_tree = null;
    522528    private CollectionTreeNode collection_tree_node = null;
    523 
    524     public ReplaceTask(CollectionTree collection_tree, CollectionTreeNode collection_tree_node)
     529    private boolean replacing = false;
     530
     531    public ReplaceOrNewTask(CollectionTree collection_tree, CollectionTreeNode collection_tree_node, boolean replacing)
    525532    {
    526533        this.collection_tree = collection_tree;
    527         this.collection_tree_node = collection_tree_node;
     534        this.collection_tree_node = collection_tree_node; // either the file to replace, or the folder to go into
     535        this.replacing = replacing;
    528536    }
    529537
     
    531539    {
    532540        JFileChooser file_chooser = new JFileChooser(startup_directory);
    533         file_chooser.setDialogTitle(Dictionary.get("ReplacePrompt.Title"));
     541        if (replacing) {
     542        file_chooser.setDialogTitle(Dictionary.get("ReplacePrompt.Title"));
     543        } else {
     544        file_chooser.setDialogTitle(Dictionary.get("NewPrompt.Title"));
     545        }
    534546        File new_file = null;
    535547        int return_val = file_chooser.showOpenDialog(null);
     
    554566        // or remote file gets updated but file gone missing in client-GLI view until collection reopened.
    555567        boolean isSameLeafName = false;
    556         if(collection_tree_node.getFile().getName().equals(new_file.getName())) {
     568        if(replacing && collection_tree_node.getFile().getName().equals(new_file.getName())) {
    557569        DebugStream.println(" @@@ File Replace: New file has the same name as existing.");
    558570        isSameLeafName = true;
    559571        }
    560572       
    561         File target_directory = collection_tree_node.getFile().getParentFile();
     573        File target_directory;
     574        FileNode parent; // store the original source's parent, need it several times after changing source
     575        if (replacing) {
     576        target_directory = collection_tree_node.getFile().getParentFile();
     577        parent = (FileNode)collection_tree_node.getParent();
     578        } else {
     579        target_directory = collection_tree_node.getFile();
     580        parent = collection_tree_node;
     581        }
    562582        CollectionTreeNode new_collection_tree_node = new CollectionTreeNode(new File(target_directory, new_file.getName()));
    563583       
    564         FileNode parent = (FileNode)collection_tree_node.getParent(); // store the original source's parent, need it several times after changing source
     584        //FileNode parent = (FileNode)collection_tree_node.getParent(); // store the original source's parent, need it several times after changing source
    565585
    566586        if(isSameLeafName) {
     
    585605        // (b) copy the new file in - but don't bring metadata
    586606        file_queue.addJob(System.currentTimeMillis(), Gatherer.g_man.gather_pane.workspace_tree, new FileNode[] { source_node }, collection_tree, parent, FileJob.COPY_FILE_ONLY);
    587        
    588         // (c) final step to finish off: do a replace of old file with new file
    589         file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.REPLACE);
    590         }
     607   
     608        if (replacing) {
     609            // (c) final step to finish off: do a replace of old file with new file
     610            file_queue.addJob(System.currentTimeMillis(), collection_tree, new FileNode[] { collection_tree_node }, collection_tree, new_collection_tree_node, FileJob.REPLACE);
     611        }
     612        }
     613
    591614
    592615
     
    605628       
    606629        if (Gatherer.isGsdlRemote) {
    607         File target_directory = this.collection_tree_node.getFile().getParentFile();
     630        File target_directory;
     631        if (this.replacing) {
     632            target_directory = this.collection_tree_node.getFile().getParentFile();
     633        } else {
     634            target_directory = this.collection_tree_node.getFile();
     635        }
    608636        File collection_tree_node_file = this.collection_tree_node.getFile();
    609637       
    610638        String collection_name = CollectionManager.getLoadedCollectionName();
     639        if (this.replacing) {
    611640        Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection_name, collection_tree_node_file);
     641        }
    612642        Gatherer.remoteGreenstoneServer.uploadFilesIntoCollection(collection_name, new File[] { new_file }, target_directory);
    613643        }
Note: See TracChangeset for help on using the changeset viewer.