Changeset 37700


Ignore:
Timestamp:
2023-04-21T21:24:08+12:00 (12 months ago)
Author:
anupama
Message:

Implemented 2nd of Dr Bainbridge's request: GLI collection tree should have rightclick > unzip option. This context menu is now available on single or multiple selection of only zip files, but not for remote GS. UnzipTools.unzip() is no longer a void function but returns boolean, so I can test which files have been unzipped successfully and can be deleted thereafter. Decompressed files were showing by calling refresh on the collection tree, but I couldn't initially get the deleted source zip files to disappear. And if I didn't call refresh, the deletes would show (but not the decompressed files). I couldn't work out what caused the tree to refresh on delete context menu or rubbish bin click, nor where (if anywhere) an event was fired to indicate deletion had completed and caused a refresh. Instead, I found that a commented out call to g_man.refreshCollectionTree in FileQueue::run() did the job of showing both decompressed files and not showing the deleted source zip files. The question remains: why was the refreshCollectionTree() call in FileQueue::run() commented out in the first place? It fixes things for my work here, but will it break something somewhere else?

Location:
main/trunk/gli
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/classes/dictionary.properties

    r37698 r37700  
    399399CollectionPopupMenu.Rename:Rename
    400400CollectionPopupMenu.Replace:Replace...
     401CollectionPopupMenu.Unzip:Unzip
    401402#*******************************
    402403#
  • main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionTree.java

    r37191 r37700  
    3030import java.awt.dnd.DropTargetDropEvent;
    3131import java.awt.event.*;
     32import java.io.File;
     33import java.util.Vector;
    3234import javax.swing.*;
    3335import javax.swing.tree.*;
     
    3739import org.greenstone.gatherer.gui.tree.DragTree;
    3840import org.greenstone.gatherer.gui.tree.DragTreeCellRenderer;
     41import org.greenstone.gatherer.util.UnzipTools;
    3942
    4043
     
    148151    private JMenuItem explode_metadata_database = null;
    149152    private JMenuItem replace_srcdoc_with_html = null;
     153    private JMenuItem unzip_file = null;
    150154    private JMenuItem delete = null;
    151155    private JMenuItem metaaudit = null;
     
    287291        }
    288292
    289         // Meta-audit and delete options
     293        // Meta-audit, delete and unzip options
    290294        metaaudit = new JMenuItem(Dictionary.get("Menu.Metadata_View", collection_tree.getSelectionDetails()), KeyEvent.VK_A);
    291295        metaaudit.addActionListener(this);
     
    309313        }
    310314        }
    311        
    312         // Only meta-audit and delete (and possibly replace_srcdoc) are available if multiple items are selected...
     315       
     316        // Unzip menu option is available if not remote GS
     317        // and when all selected files are of .zip extension
     318        if(!Gatherer.isGsdlRemote && firstSelectedNode.isZipFile()) { // test 1st selected node
     319        unzip_file = new JMenuItem(Dictionary.get("CollectionPopupMenu.Unzip"), KeyEvent.VK_U);
     320        unzip_file.addActionListener(this);     
     321        add(unzip_file);
     322       
     323        // Now the menu is there, grey it out if not all the files are of the same type
     324        if(!selectedFilesOfSameType(selection_paths)) {
     325            unzip_file.setEnabled(false);
     326        }
     327        }
     328       
     329        // Only meta-audit and delete (and possibly replace_srcdoc and unzip_file)
     330        // are available if multiple items are selected...
    313331        if (selection_paths.length > 1) {
    314332        return;
     
    397415        // Replace source document with generated html (works with replace_srcdoc_with_html.pl)
    398416        else if (source == replace_srcdoc_with_html) {
    399         java.io.File[] source_files = new java.io.File[selection_paths.length];
     417        File[] source_files = new File[selection_paths.length];
    400418        for (int i = 0; i < selection_paths.length; i++) {
    401419            CollectionTreeNode node = (CollectionTreeNode) selection_paths[i].getLastPathComponent();
     
    405423        }
    406424
     425        else if (source == unzip_file) {
     426        Vector<CollectionTreeNode> sourceNodes = new Vector(selection_paths.length);
     427        // all selected shall be zip files at this stage
     428        for (int i = 0; i < selection_paths.length; i++) {
     429            CollectionTreeNode node = (CollectionTreeNode) selection_paths[i].getLastPathComponent();
     430            //System.err.println("Away to unzip file" + node.getFile().getPath());
     431           
     432            // unzip the zip file into its parent directory
     433            // and maintain list of successfully unzipped files to delete
     434            if(UnzipTools.unzipFile(node.getFile().getPath(), node.getFile().getParent()+File.separator)) {
     435            sourceNodes.add(node);
     436            }           
     437        }
     438
     439        // refresh collection view - now done in file/FileQueue::run() in synchronized(this)
     440        //Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED);
     441       
     442        // for all zips that were successfully unzipped, delete the zip file itself
     443        CollectionTreeNode[] unzippedNodes = new CollectionTreeNode[sourceNodes.size()];
     444        unzippedNodes = sourceNodes.toArray(unzippedNodes);
     445        // Fire a delete action - refreshes collection tree on its own iff refresh not
     446        // called on the tree before or after. But then the unzipped files didn't show.
     447        // So now refresh collection tree done in file/FileQueue::run() in synchronized(this)
     448        Gatherer.f_man.action(collection_tree, unzippedNodes, Gatherer.recycle_bin, null);
     449        }
     450       
    407451        // Delete
    408452        else if (source == delete) {
  • main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionTreeNode.java

    r23433 r37700  
    8484    }
    8585
     86    public boolean isZipFile() {
     87    if(this.file != null) {
     88        if(file.getPath().endsWith(".zip")) {
     89        return true;
     90        }
     91    }
     92
     93    return false;
     94    }
     95   
    8696    /** This method returns a string representation of the filenodes in the
    8797    * <i>Collection</i> Tree, that can then be displayed in the tree. If the
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r34289 r37700  
    704704            if (Gatherer.g_man != null && Gatherer.c_man.ready()) {
    705705            Gatherer.g_man.refreshWorkspaceTree(DragTree.COLLECTION_CONTENTS_CHANGED);
    706             // Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED);
     706            // Need this next line back in to refresh the collection tree after
     707            // rightclick>Unzip has finished unzipping and deleting the original zip file
     708            // TODO: But why was it commented out originally? Should it not be active?
     709             Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED);
    707710            }
    708711
  • main/trunk/gli/src/org/greenstone/gatherer/util/UnzipTools.java

    r19736 r37700  
    3535public class UnzipTools
    3636{
    37     static public void unzipFile(String zip_file_path, String base_directory_path)
     37    static public boolean unzipFile(String zip_file_path, String base_directory_path)
    3838    {
     39    boolean success = true;
    3940    try {
    4041        ZipFile zip_file = new ZipFile(new File(zip_file_path), ZipFile.OPEN_READ);
     
    5152            if (!zip_entry_file.exists() && !zip_entry_file.mkdirs()) {
    5253            System.err.println("Error: unable to create directory " + zip_entry_file);
     54            success = false;
    5355            }
    5456        }
     
    9496    catch (Exception exception) {
    9597        exception.printStackTrace();
     98        success = false;
    9699    }
     100
     101    return success;
    97102    }
    98103}
Note: See TracChangeset for help on using the changeset viewer.