Changeset 15107 for gli


Ignore:
Timestamp:
03/20/08 20:19:09 (13 years ago)
Author:
ak19
Message:

Added Refresh on rightclick AND now allows multiple selected documents to be replaced with GS-generated html versions (works with replace_srcdoc_with_html.pl)

File:
1 edited

Legend:

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

    r13604 r15107  
    9999        JLabel tree_cell = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    100100
    101         // Mark explodable files with a different icon
    102         if (value instanceof CollectionTreeNode && ((CollectionTreeNode) value).isExplodable()) {
    103         tree_cell.setIcon(CollectionTreeNode.GREEN_FILE_ICON);
    104         }
    105 
     101        // Mark explodable files and SrcReplaceable files with a different icon (Green file icon)
     102        if(value instanceof CollectionTreeNode) {
     103        if(((CollectionTreeNode) value).isExplodable() || ((CollectionTreeNode) value).isSrcReplaceable()) {
     104            tree_cell.setIcon(CollectionTreeNode.GREEN_FILE_ICON);
     105        }
     106        }
     107           
    106108        return tree_cell;
    107109    }
     
    125127    private JMenuItem expand_folder = null;
    126128    private JMenuItem explode_metadata_database = null;
     129    private JMenuItem replace_srcdoc_with_html = null;
    127130    private JMenuItem delete = null;
    128131    private JMenuItem metaaudit = null;
    129132    private JMenuItem new_folder = null;
    130133    private JMenuItem new_dummy_doc = null;
     134    private JMenuItem refresh = null; // for refreshing folder view
    131135    private JMenuItem open_externally = null;
    132136    private JMenuItem rename = null;
     
    202206    }
    203207
     208    /** Checks whether the files selected are of the same filetype (have the same extension).
     209     * @param selectedFilePaths - the full file paths to the treenodes selected in the
     210     * collection fileview.
     211     * @return true if the file extensions of all the selected files are the same. False is
     212     * returned if the file extension of any selected file is different (this means that if
     213     * a folder was selected, false would be returned). False is also returned if nothing was
     214     * selected.
     215     * For use with replace_srcdoc_with_html.pl
     216    */
     217    private boolean selectedFilesOfSameType(TreePath[] selectedFilePaths) {
     218        if(selectedFilePaths == null || selectedFilePaths.length <= 0)
     219        return false;
     220
     221        boolean sameExtension = true;
     222
     223        // get just the filename from the path and extract its extension
     224        String firstFile = selectedFilePaths[0].getLastPathComponent().toString();
     225        int period = firstFile.lastIndexOf('.');
     226        if(period == -1) { // someone could have selected a folder
     227        return false;
     228        }
     229        String extension = firstFile.substring(period); // includes period
     230
     231        // compare with the other selected files' extensions:
     232        for(int i = 1; i < selectedFilePaths.length && sameExtension; i++) {
     233        String otherFile = selectedFilePaths[i].getLastPathComponent().toString();
     234        String otherFileExt = otherFile.substring(otherFile.lastIndexOf('.'));
     235        if(!extension.equals(otherFileExt))
     236            sameExtension = false;
     237        }
     238        return sameExtension;
     239    }
    204240
    205241    private void buildContextMenu(TreePath[] selection_paths)
     
    215251        add(new_dummy_doc);
    216252
     253        refresh = new JMenuItem(Dictionary.get("CollectionPopupMenu.Refresh"));
     254        refresh.addActionListener(this);
     255        add(refresh);
     256
    217257        node = (CollectionTreeNode) collection_tree.getModel().getRoot();
    218258        return;
     
    228268        add(delete);
    229269
    230         // Only meta-audit and delete are available if multiple items are selected...
     270        // The src doc replaceable (with html file) option is only available when all files selected are of the
     271        // same type (same extension). For srcreplaceable files only. Works with replace_srcdoc_with_html.pl
     272        CollectionTreeNode firstSelectedNode = (CollectionTreeNode)selection_paths[0].getLastPathComponent();
     273        if(firstSelectedNode.isSrcReplaceable()) { // test the first selected node
     274        replace_srcdoc_with_html = new JMenuItem(Dictionary.get("Menu.Replace_SrcDoc_With_HTML"), KeyEvent.VK_H);
     275        replace_srcdoc_with_html.addActionListener(this);       
     276        add(replace_srcdoc_with_html);
     277       
     278        // Now the menu is there, grey it out if not all the files are of the same type
     279        if(!selectedFilesOfSameType(selection_paths)) {
     280            replace_srcdoc_with_html.setEnabled(false);
     281        }
     282        }
     283       
     284        // Only meta-audit and delete (and possibly replace_srcdoc) are available if multiple items are selected...
    231285        if (selection_paths.length > 1) {
    232286        return;
     
    249303            add(explode_metadata_database);
    250304        }
    251 
     305   
    252306        // Replace file
    253307        // !! TO DO: Remote building
     
    294348    /** Called whenever one of the menu items is clicked, this method then causes the appropriate effect. */
    295349    public void actionPerformed(ActionEvent event)
    296     {
    297         Object source = event.getSource();
     350    {   
     351        Object source = event.getSource();
    298352
    299353        // Collapse folder
     
    310364        else if (source == explode_metadata_database) {
    311365        Gatherer.f_man.explodeMetadataDatabase(node.getFile());
     366        }
     367       
     368        // Replace source document with generated html (works with replace_srcdoc_with_html.pl)
     369        else if (source == replace_srcdoc_with_html) {
     370        java.io.File[] source_files = new java.io.File[selection_paths.length];
     371        for (int i = 0; i < selection_paths.length; i++) {
     372            CollectionTreeNode node = (CollectionTreeNode) selection_paths[i].getLastPathComponent();
     373            source_files[i] = node.getFile();
     374        }
     375        Gatherer.f_man.replaceSrcDocWithHtml(source_files); // passing the selected files
    312376        }
    313377
     
    338402        }
    339403
     404        // Refresh action to reload folder view
     405        else if (source == refresh) { // Refresh collection tree
     406        Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED);
     407        }
     408
    340409        // Open in external program
    341410        else if (source == open_externally) {
Note: See TracChangeset for help on using the changeset viewer.