Changeset 22605

Show
Ignore:
Timestamp:
11.08.2010 21:28:34 (9 years ago)
Author:
ak19
Message:

Ticket #152: Allowing different paths to collect dir so that GLI can work with collect dirs on pen drives. NONE OF THESE CHANGES ARE FOR Client-GLI AS YET. 1. Preferences (Connection tab), Open and New Collection dialogs allow one to change the current collect directory containing the collections to select from. 2. New Collection dialog allows one to base a new collection on an existing collection in a collect dir other than the current collect dir. 3. Collections in the Documents in Greenstone Collections Workspace Tree Node now have two additional rightclick options: to move and copy these collections to another location.

Location:
main/trunk/gli
Files:
1 added
11 modified

Legend:

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

    r22341 r22605  
    526526#***** FileActions ***** 
    527527FileActions.Calculating_Size:Calculating total size of selected files 
     528FileActions.ChooseDestinationDirectory:Choose destination directory 
    528529FileActions.Copying:Copying {0} 
    529530FileActions.Could_Not_Delete:Could not delete {0} 
     
    615616General.Cancel:Cancel 
    616617General.Cancel_Tooltip:Cancel the changes (will not undo any that have been applied already) 
     618General.CD:Change Dir... 
     619General.CD_Tooltip:Browse to a different collect directory 
     620General.ChooseCollectDirectory:Choose your collect directory... 
    617621General.Close:Close 
    618622General.Close_Tooltip:Close this dialog box 
     
    735739#***** Menu Options ***** 
    736740Menu.Collapse:Close Folder 
     741Menu.Copy_Collection:Copy this collection to... 
    737742Menu.Edit:Edit 
    738743Menu.Edit_Copy:Copy (ctrl-c) 
     
    756761Menu.Help_About:About... 
    757762Menu.Metadata_View:Assigned Metadata for the {0} 
     763Menu.Move_Collection:Move this collection to... 
    758764Menu.Open_Externally:Open in external program 
    759765#******************** 
     
    861867NewCollectionPrompt.Base_Collection:Base this collection on: 
    862868NewCollectionPrompt.Base_Collection_Tooltip:Select an existing collection to base the new collection on 
     869NewCollectionPrompt.ChooseACollection:Choose a collection 
    863870NewCollectionPrompt.Collection_Description:Description of content: 
    864871NewCollectionPrompt.Collection_Name:Collection folder: 
     
    870877NewCollectionPrompt.Instructions:To create a new collection fill out the fields below. 
    871878NewCollectionPrompt.NewCollection:-- New Collection -- 
     879NewCollectionPrompt.OtherCollections:-- Other Collections... -- 
     880NewCollectionPrompt.Select:Select 
    872881NewCollectionPrompt.Title:Create a new Collection. 
    873882NewCollectionPrompt.Title_Clash:The title you have chosen for your collection is already in use. Continue? 
     
    918927Preferences.Connection.Library_Path_Tooltip_GS3:The URL of the Greenstone web-server 
    919928Preferences.Connection.Library_Path_Connection_Failure:Failed to connect. Check that the Greenstone server at {0} is running. 
     929Preferences.Connection.CollectDirectory:Collect Directory: 
     930Preferences.Connection.CollectDirectory_Tooltip:The path to the collect directory you want to work with. 
    920931Preferences.Connection.ProgramCommand:Preview Command: 
    921932Preferences.Connection.ProgramCommand_Tooltip:The launch command for the program used to view the collection preview. Remember to use %1 as the placeholder for the collection address, and to use speechmarks where necessary. 
  • main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r21965 r22605  
    497497        if (no_load || open_collection_file_path.equals("")) { 
    498498        open_collection_file_path = null; 
    499         } 
     499        //      collectDirectoryHasChanged(); // make sure gsdlsite.cfg's collecthome defaults to GS' collect 
     500        } 
     501 
     502        // If opening a collection outside the standard GS collect folder, need 
     503        // to open the non-standard collect folder that the collection resides in 
     504        if (open_collection_file_path != null &&  
     505        !open_collection_file_path.startsWith(getCollectDirectoryPath())) { 
     506        File collectFolder = null; 
     507        if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder 
     508            collectFolder = new File(open_collection_file_path); 
     509        } else { 
     510            // the filepath is a gli.col file. To get the collect folder: the 1st level 
     511            // up is collection folder, 2 two levels up is the containing collect folder 
     512            collectFolder = new File(open_collection_file_path).getParentFile().getParentFile(); 
     513        } 
     514 
     515        // Need to deal with colgroups as well: while there's an etc/collect.cfg in the current 
     516        // collectFolder, move one level up 
     517        String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE; 
     518        if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup 
     519            collectFolder = collectFolder.getParentFile(); 
     520             
     521        } 
     522        setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder 
     523        } 
     524         
    500525    } 
    501526    catch (Exception exception) { 
     
    761786        System.err.println("Error: Unable to make directory: " + gli_user_directory); 
    762787    } 
     788    } 
     789 
     790 
     791    public static void collectDirectoryHasChanged(String oldCollectPath, String newCollectPath) {  
     792    if(oldCollectPath.equals(newCollectPath)) { 
     793        return; // nothing to be done 
     794    } 
     795 
     796    // first save any open collection in the *old* location 
     797    if(Gatherer.c_man.getCollection() != null) { 
     798        Gatherer.setCollectDirectoryPath(oldCollectPath); // go back to current collection's location 
     799        Gatherer.g_man.saveThenCloseCurrentCollection(); // close the current collection first 
     800    } 
     801     
     802    // change to new collect path 
     803    Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),  
     804                true, newCollectPath); 
     805    Gatherer.setCollectDirectoryPath(newCollectPath); 
     806     
     807 
     808    // refresh the Documents in Greenstone Collections 
     809    //WorkspaceTreeModel.refreshGreenstoneCollectionsNode(); 
     810    Gatherer.g_man.refreshWorkspaceTreeGreenstoneCollections(); 
     811     
     812    // The web server needs to be told where a new (non-standard) collecthome home is. 
     813    // The web server reads collecthome from cgi-bin/gsdlsite.cfg, where the property 
     814    // collecthome can be specified if a non-standard collecthome is to be used. If no  
     815    // such property is specified in the file, then it assumes the standard GS collecthome. 
     816    // This method does nothing for a remote Greenstone.     
     817    if(Gatherer.isGsdlRemote) { 
     818        return; 
     819    }    
     820 
     821    String gsdlsitecfg = ""; 
     822    if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg 
     823        gsdlsitecfg = Configuration.gsdl3_path + File.separator + "WEB-INF"  
     824        + File.separator + "cgi" + File.separator + "gsdl3site.cfg"; 
     825    } else { // cgi-bin/gsdlsite.cfg 
     826        gsdlsitecfg = Configuration.gsdl_path + File.separator  
     827        + "cgi-bin" + File.separator + "gsdlsite.cfg"; 
     828    } 
     829 
     830    // non-destructive update of gsdl(3)site.cfg (comments preserved) 
     831    Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", Gatherer.getCollectDirectoryPath()); 
    763832    } 
    764833 
  • main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r22467 r22605  
    402402     */ 
    403403    public void closeCollection() { 
     404    if (collection == null) { 
     405        return; 
     406    } 
    404407    DebugStream.println("Close collection: " + collection.getName()); 
    405408 
     
    11541157    public void loadCollection(String collection_file_path) 
    11551158    { 
     1159    if(new File(collection_file_path).isDirectory()) { // collect folder instead of previously-opened collection 
     1160        Gatherer.setMenuBarEnabled(true); 
     1161        return; // nothing else to be done, no collection to open 
     1162    } 
     1163 
    11561164    // Display a modal progress popup to indicate that the collection is being loaded 
    11571165    ModalProgressPopup load_collection_progress_popup = new ModalProgressPopup(Dictionary.get("CollectionManager.Loading_Collection"), Dictionary.get("CollectionManager.Loading_Collection_Please_Wait")); 
     
    15521560      // If there was an open collection last session, reopen it 
    15531561      if (Gatherer.open_collection_file_path != null) { 
    1554         // Load the collection now 
    1555         loadCollection(Gatherer.open_collection_file_path); 
     1562    // Load the collection now 
     1563    loadCollection(Gatherer.open_collection_file_path); 
    15561564      }  
    15571565 
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileManager.java

    r22410 r22605  
    6262    static private FileQueue file_queue = null; 
    6363 
    64     public static int FILE_TYPE = 0; 
    65     public static int FOLDER_TYPE = 1; 
     64    public static final int COPY = 0; 
     65    public static final int MOVE = 1; 
     66 
     67    public static final int FILE_TYPE = 0; 
     68    public static final int FOLDER_TYPE = 1; 
    6669    protected static File startup_directory = null; 
    6770 
     
    129132    } 
    130133 
     134    /** For moving and copying of folders. */ 
     135    public void action(File sourceFolder, File targetFolder, int operation) { 
     136    (new SimpleFileTask(sourceFolder, targetFolder, operation)).start(); 
     137    } 
     138     
    131139 
    132140    /** Retrieves the file queue object. */ 
     
    136144    } 
    137145 
     146    /** Performs the simple file task of moving or copying folders. */ 
     147    private class SimpleFileTask 
     148    extends Thread 
     149    { 
     150    private File sourceFolder; 
     151    private File targetFolder; 
     152    int operation; // MOVE or COPY 
     153 
     154    public SimpleFileTask(File sourceFolder, File targetFolder, int operation) 
     155    { 
     156        this.sourceFolder = sourceFolder;        
     157        this.targetFolder = targetFolder; 
     158        this.operation = operation; 
     159    } 
     160 
     161 
     162    public void run() 
     163    { 
     164        // check if we're moving or overwriting the current collection 
     165        String currentColPath = Gatherer.getCollectDirectoryPath()+CollectionManager.getLoadedCollectionName(); 
     166        if(currentColPath.equals(sourceFolder.getAbsolutePath())  
     167           || currentColPath.equals(targetFolder.getAbsolutePath())) { 
     168        Gatherer.g_man.saveThenCloseCurrentCollection(); 
     169        } 
     170         
     171        // if moving, try a simple move operation (if it works, it 
     172        // shouldn't take long at all and doesn't need a progress bar) 
     173        if(operation == MOVE && sourceFolder.renameTo(targetFolder)) { 
     174        //System.err.println("**** A simple renameTo() worked."); 
     175        WorkspaceTreeModel.refreshGreenstoneCollectionsNode(); 
     176        return; 
     177        } 
     178 
     179        // Reset the progress bar and set it to indeterminate while calculating its size 
     180        GProgressBar progress_bar = file_queue.getProgressBar(); 
     181        progress_bar.reset(); 
     182        progress_bar.setIndeterminate(true); 
     183 
     184        String status = "FileActions.Moving"; 
     185        if(operation == COPY) { 
     186        status = "FileActions.Copying";      
     187        } 
     188        progress_bar.setString(Dictionary.get(status)); 
     189        file_queue.getFileStatus().setText(Dictionary.get(status, 
     190                                  file_queue.formatPath(status, 
     191                                     sourceFolder.getAbsolutePath(),  
     192                                     file_queue.getFileStatus().getSize().width))); 
     193 
     194        // do the move or copy operation 
     195        try { 
     196        //System.err.println("**** Copying " + sourceFolder + " to: " + targetFolder); 
     197        file_queue.copyDirectoryContents(sourceFolder, targetFolder);        
     198        } catch(Exception e) { 
     199        JOptionPane.showMessageDialog(Gatherer.g_man, e.getMessage(),  
     200                          "Can't perform file operation", JOptionPane.ERROR_MESSAGE); 
     201 
     202        progress_bar.setIndeterminate(false); 
     203        progress_bar.clear(); 
     204        return; 
     205        } 
     206         
     207        // if moving, delete the original source folder and 
     208        // update the docs in GS collections node in the workspace tree 
     209         
     210        if(operation == MOVE) { 
     211        Utility.delete(sourceFolder); 
     212        WorkspaceTreeModel.refreshGreenstoneCollectionsNode(); 
     213        } 
     214 
     215 
     216        progress_bar.setIndeterminate(false); 
     217        progress_bar.clear(); 
     218        file_queue.getFileStatus().setText(Dictionary.get("FileActions.No_Activity")); 
     219        progress_bar.setString(Dictionary.get("FileActions.No_Activity")); 
     220    } 
     221    } 
    138222 
    139223    private class FileTask 
  • main/trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r12115 r22605  
    162162     * @return A path <strong>String</strong> no longer than width. 
    163163     */ 
    164     private String formatPath(String key, String raw, int width) 
     164    String formatPath(String key, String raw, int width) // package access 
    165165    { 
    166166    JLabel label = new JLabel(Dictionary.get(key, raw)); 
  • main/trunk/gli/src/org/greenstone/gatherer/file/WorkspaceTree.java

    r22410 r22605  
    3939import org.greenstone.gatherer.gui.CreateShortcutPrompt; 
    4040import org.greenstone.gatherer.gui.tree.DragTree; 
     41import org.greenstone.gatherer.util.Utility; 
    4142 
    4243 
     
    217218    private JMenuItem rename = null; 
    218219    private JMenuItem replace = null; 
     220    private JMenuItem copy_collection = null; 
     221    private JMenuItem move_collection = null; 
    219222 
    220223 
     
    343346        // Or map any other level directories 
    344347        else { 
     348            // --- Options for Documents In Greenstone Collections (greenstone_collections_node) --- 
     349            // all subfolder of Documents In Greenstone Collections can be copied and moved 
     350            WorkspaceTreeNode secondLevelNode = (WorkspaceTreeNode) path.getPathComponent(1); 
     351 
     352            if (secondLevelNode.toString().equals(Dictionary.get("Tree.World"))) { 
     353            // Can move and copy the collection folders across 
     354            copy_collection = new JMenuItem(Dictionary.get("Menu.Copy_Collection"), KeyEvent.VK_P); 
     355            copy_collection.addActionListener(this); 
     356            add(copy_collection); 
     357             
     358            move_collection = new JMenuItem(Dictionary.get("Menu.Move_Collection"), KeyEvent.VK_M); 
     359            move_collection.addActionListener(this); 
     360            add(move_collection);            
     361            } 
     362 
    345363            create_shortcut = new JMenuItem(Dictionary.get("MappingPrompt.Map"), KeyEvent.VK_S); 
    346364            create_shortcut.addActionListener(this); 
     
    386404        Gatherer.f_man.openFileInExternalApplication(node.getFile()); 
    387405        } 
     406         
     407        // Copy or move a collection from Documents in Greenstone Collections 
     408        else if (source == move_collection || source == copy_collection) { 
     409 
     410        JFileChooser chooser = new JFileChooser(Gatherer.getCollectDirectoryPath()); 
     411        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);         
     412        chooser.setDialogTitle(Dictionary.get("FileActions.ChooseDestinationDirectory")); 
     413        int returnVal = chooser.showOpenDialog(Gatherer.g_man.gather_pane); 
     414 
     415        if(returnVal == JFileChooser.APPROVE_OPTION) {           
     416 
     417            // the node that the user rightclicked on ends up 
     418            // being the col's import folder 
     419            File sourceFolder = node.getFile();  
     420            if(sourceFolder.getName().equals("import")) {  
     421            sourceFolder = sourceFolder.getParentFile(); 
     422            } 
     423            String target = chooser.getSelectedFile().getAbsolutePath(); 
     424            File targetFolder = new File(target+File.separator+sourceFolder.getName()); 
     425             
     426            // some sanity checks 
     427            if(targetFolder.equals(sourceFolder)) { // directory has not changed. No copy/move performed 
     428            JOptionPane.showMessageDialog(Gatherer.g_man,  
     429                              "Can't move " + sourceFolder + " " + "to itself\n(" + targetFolder + ").",  
     430                              "Source and destination directories are the same",  
     431                              JOptionPane.ERROR_MESSAGE); 
     432            return; 
     433            } else if(targetFolder.exists()) { // option to overwrite or not 
     434            if(JOptionPane.showConfirmDialog(Gatherer.g_man,  
     435                             "Directory " + targetFolder + " already exists. Overwrite?",  
     436                             "Destination directory already exists",  
     437                             JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) { 
     438                return; 
     439            } 
     440            // else can overwrite: delete the existing targetfolder before copying/moving 
     441            Utility.delete(targetFolder); 
     442            }  
     443             
     444            int operation = (source == move_collection) ? FileManager.MOVE : FileManager.COPY; 
     445            Gatherer.f_man.action(sourceFolder, targetFolder, operation); 
     446        } 
     447        } 
    388448    } 
    389449    } 
  • main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java

    r19438 r22605  
    506506    } 
    507507    else { 
    508         Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, null); 
     508        // if there was no open collection, then write out the collect dir path for next time 
     509        Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),  
     510                    true, Gatherer.getCollectDirectoryPath()); // null 
    509511    } 
    510512 
     
    646648    } 
    647649 
     650    public void refreshWorkspaceTreeGreenstoneCollections() 
     651    { 
     652    refreshWorkspaceTree(WorkspaceTree.LIBRARY_CONTENTS_CHANGED); 
     653    } 
    648654 
    649655    /** Specifies whether a certain tab is enabled or not. */ 
  • main/trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionDetailsPrompt.java

    r18947 r22605  
    3434import javax.swing.event.*; 
    3535import javax.swing.text.*; 
     36import javax.swing.filechooser.FileFilter; 
     37import javax.swing.filechooser.FileView; 
    3638import org.greenstone.gatherer.Configuration; 
    3739import org.greenstone.gatherer.Dictionary; 
     
    3941import org.greenstone.gatherer.collection.BasicCollectionConfiguration; 
    4042import org.greenstone.gatherer.remote.RemoteGreenstoneServer; 
     43import org.greenstone.gatherer.util.JarTools; 
    4144import org.greenstone.gatherer.util.StaticStrings; 
    4245import org.greenstone.gatherer.util.Utility; 
     
    4548    extends ModalDialog { 
    4649 
    47       
    48      
    49     static public boolean titleClashes(String title, File current_config_file) { 
     50     
     51    static public boolean titleClashes(String collectDir, String title, File current_config_file) { 
    5052    // An empty collection title never clashes with anything. It may look ugly in the final collection but there is nothing wrong with having no title for a particular language. 
    5153    if(title == null || title.length() == 0) { 
    5254        return false; 
    5355    } 
    54     File collect_directory = new File(Gatherer.getCollectDirectoryPath()); 
     56    File collect_directory = new File(collectDir); 
    5557    String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE; 
    5658    File children[] = collect_directory.listFiles(); 
     
    7274 
    7375    private boolean cancelled; 
     76    private boolean collectDirChanged; 
    7477    private File base_final; 
     78    private JButton chdir_button; 
    7579    private JButton create_button; 
    7680    private JComboBox base_collection; 
     
    7983    private JTextArea description; 
    8084    private JTextField title; 
     85    private String collectBasePath; 
     86    private String newCollectPath; 
    8187    private String description_final; 
    8288    private String title_final=""; 
     89 
    8390    static private Dimension COMPONENT_SIZE = new Dimension(230, 25); 
    8491    /** The size of this new collection dialog box. */ 
     
    94101        this.setComponentOrientation(Dictionary.getOrientation()); 
    95102    this.self = this; 
     103    newCollectPath = Gatherer.getCollectDirectoryPath(); 
     104    collectBasePath = null; 
     105    collectDirChanged = false; 
     106 
    96107    // Setup 
    97108    setJMenuBar(new SimpleMenuBar("creatingacollection")); 
     
    101112    // Model building. Build a model of all of the collections in the gsdl collect directory with the appropriate directories. 
    102113    Vector base_collection_model = new Vector(); 
    103     // need to modify this to base a coll on any collection from any site 
    104     if (Gatherer.GS3 && !Gatherer.isGsdlRemote) { 
    105         File sites_dir = new File(Gatherer.getSitesDirectoryPath()); 
    106         File [] sites = sites_dir.listFiles(); 
    107         for (int i=0; i<sites.length; i++) { 
    108         File collect_directory = new File(sites_dir + File.separator + sites[i].getName() + File.separator + "collect"); 
    109         if (collect_directory.exists()) { 
    110             addCollectionsToModel(base_collection_model, collect_directory, sites[i].getName()); 
    111         } 
    112         } 
    113     } else { 
    114        File collect_directory = new File(Gatherer.getCollectDirectoryPath()); 
    115        addCollectionsToModel(base_collection_model, collect_directory, null); 
    116     } 
    117  
    118     // Sort the result. 
    119     Collections.sort(base_collection_model); 
    120     base_collection_model.add(0, new Item(null, Dictionary.get("NewCollectionPrompt.NewCollection"))); 
     114    setupBaseCollections(base_collection_model, null); // if no collect directory passed in: use default collect directory 
     115 
    121116 
    122117    // Creation 
     
    190185        button_pane.setComponentOrientation(Dictionary.getOrientation()); 
    191186    create_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip")); 
     187    chdir_button = new GLIButton(Dictionary.get("General.CD"), Dictionary.get("General.CD_Tooltip")); 
    192188    JButton cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip")); 
    193189 
    194190    // Connection 
     191    chdir_button.addActionListener(new ChangeDirListener()); 
     192    if(Gatherer.isGsdlRemote) { // for client GLI disable changing directories 
     193        chdir_button.setEnabled(false);      
     194    } else { // can't base collections on any in OTHER collect dirs in client GLI 
     195        base_collection.addActionListener(new OtherCollectionsListener()); 
     196    } 
    195197    cancel_button.addActionListener(new CancelListener()); 
    196198    create_button.addActionListener(new CreateListener()); 
     
    238240 
    239241    button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); 
    240     button_pane.setLayout(new GridLayout(1,2)); 
     242    button_pane.setLayout(new GridLayout(1,3)); 
     243    button_pane.add(chdir_button); 
    241244    button_pane.add(create_button); 
    242245    button_pane.add(cancel_button); 
     
    327330    public String getTitle() { 
    328331    return title_final; 
     332    } 
     333 
     334    private void setupBaseCollections(Vector base_collection_model, String collectDirectory) { 
     335 
     336    File collect_directory = null; 
     337    if(collectDirectory != null) { 
     338        collect_directory = new File(collectDirectory); 
     339    } 
     340 
     341    // need to modify this to base a coll on any collection from any site 
     342    if (Gatherer.GS3 && !Gatherer.isGsdlRemote) { 
     343        File sites_dir = new File(Gatherer.getSitesDirectoryPath()); 
     344        File [] sites = sites_dir.listFiles(); 
     345        for (int i=0; i<sites.length; i++) {         
     346        if(collect_directory == null) { 
     347            collect_directory = new File(sites_dir + File.separator + sites[i].getName() + File.separator + "collect"); 
     348        }  
     349        if (collect_directory.exists()) { 
     350            addCollectionsToModel(base_collection_model, collect_directory, sites[i].getName()); 
     351        } 
     352        } 
     353    } else { 
     354        if(collect_directory == null) { // if no collect directory passed in: use default collect directory 
     355        collect_directory = new File(Gatherer.getCollectDirectoryPath()); 
     356        } 
     357       addCollectionsToModel(base_collection_model, collect_directory, null); 
     358    } 
     359 
     360    // Sort the result. 
     361    Collections.sort(base_collection_model); 
     362    base_collection_model.add(0, new Item(null, Dictionary.get("NewCollectionPrompt.NewCollection"))); 
     363     
     364    // last item allows one to open up collections from other collect folders to base the new one on 
     365    if(!Gatherer.isGsdlRemote) { // Not yet implemented for client GLI 
     366        base_collection_model.add(new Item(null, Dictionary.get("NewCollectionPrompt.OtherCollections"))); 
     367    } 
    329368    } 
    330369 
     
    363402    } 
    364403 
     404    private class OtherCollectionsListener implements ActionListener { 
     405 
     406    // the JComboBox listener will receive an ActionEvent  
     407    // when a selection has been made 
     408 
     409    public void actionPerformed(ActionEvent event) { 
     410 
     411        // If the Other Collections item was selected (which is the last one in the list) 
     412        if(base_collection.getSelectedIndex() == base_collection.getItemCount()-1) { 
     413 
     414        // open a filechooser in whatever is the current collect directory 
     415        // within the NewCollectionDetailsPrompt's settings 
     416        if(collectBasePath == null) { 
     417            collectBasePath = newCollectPath; 
     418        } 
     419 
     420        JFileChooser chooser = new JFileChooser(collectBasePath); 
     421        chooser.setFileView(new CollectionFileView()); 
     422        chooser.setDialogTitle(Dictionary.get("NewCollectionPrompt.ChooseACollection")); 
     423        chooser.setApproveButtonText(Dictionary.get("NewCollectionPrompt.Select")); 
     424         
     425        // to prevent the user from traversing into collection folders, 
     426        // need to: 
     427        // - NOT set the filechooser to Directories only, but files and directories 
     428        // (so that they can still select directories) 
     429        // - add a filefilter that accepts only directories (i.e. rejects files) 
     430        // - remove the accept all filter 
     431        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 
     432        //chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 
     433        chooser.setFileFilter(new CollectionFileFilter()); 
     434        chooser.setAcceptAllFileFilterUsed(false); 
     435 
     436        int returnVal = chooser.showOpenDialog(NewCollectionDetailsPrompt.this); 
     437        if(returnVal == JFileChooser.APPROVE_OPTION) { 
     438 
     439            File selectedFile = chooser.getSelectedFile();  
     440             
     441            // don't bother reloading if nothing has changed 
     442            if(collectBasePath.equals(selectedFile.getAbsolutePath() + File.separator)) {  
     443            // don't want Other Collections... selected 
     444            base_collection.setSelectedIndex(0); 
     445            } else { 
     446 
     447            // If the selected directory is a collection folder get its collect dir, 
     448            // make collectBasePath the collect dir, and select the collection itself 
     449            String cfg = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE; 
     450            boolean isCollection = false; 
     451            while(new File(selectedFile, cfg).exists()) { // while loop handles collectgroup 
     452                selectedFile = selectedFile.getParentFile(); 
     453                isCollection = true; 
     454            } // else may be a collect dir, in which case leave it as it is again 
     455 
     456            // found collect directory for base collections 
     457            collectBasePath = selectedFile.getAbsolutePath()+File.separator;  
     458 
     459            // change the available collections to base this collection on 
     460            base_collection.removeAllItems(); 
     461            Vector base_collection_model = new Vector(); 
     462            setupBaseCollections(base_collection_model, collectBasePath); 
     463            for(int i = 0; i < base_collection_model.size(); i++) { 
     464                Item item = (Item)base_collection_model.get(i); 
     465                base_collection.addItem(item); 
     466 
     467                // select the originally chosen collection, if any, in the combobox 
     468                if(isCollection && chooser.getSelectedFile().equals(item.getFile())) { 
     469                base_collection.setSelectedIndex(i); 
     470                } 
     471            } 
     472             
     473            // But if the user selected a collect group, set combobox to New Collection 
     474            if(!isCollection) { 
     475                // if it was a collectgroup, nothing new would be selected, set to New Coll              
     476                if(base_collection.getSelectedIndex() == base_collection.getItemCount()-1) { 
     477                base_collection.setSelectedIndex(0); 
     478                } 
     479            } 
     480 
     481            }  
     482 
     483        } else { // cancelled out of dialog, so jump to New Collection 
     484            base_collection.setSelectedIndex(0); 
     485        }        
     486        } 
     487    } 
     488    } 
     489 
     490    private class ChangeDirListener implements ActionListener { 
     491    public void actionPerformed(ActionEvent event) { 
     492        String oldCollectPath = newCollectPath; 
     493        JFileChooser chooser = new JFileChooser(newCollectPath); 
     494        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 
     495        chooser.setDialogTitle(Dictionary.get("General.ChooseCollectDirectory")); 
     496 
     497        int returnVal = chooser.showOpenDialog(NewCollectionDetailsPrompt.this); 
     498        if(returnVal == JFileChooser.APPROVE_OPTION) { 
     499        newCollectPath = chooser.getSelectedFile().getAbsolutePath() + File.separator; 
     500 
     501        // Must NOT change the available collections to base this collection on here. 
     502        // It will change any collection the user previously chose to base the newcoll on. 
     503 
     504        // will be used to test for duplicate collection names in current collect dir 
     505        collectDirChanged = newCollectPath.equals(oldCollectPath) ? false : true; 
     506        } 
     507    } 
     508    } 
     509 
    365510    private class CancelListener 
    366511    implements ActionListener { 
     
    387532        // We must ensure that the collection title is unique. This is a pain in the nether regions as we are forced to load the collect.cfg of each other collection in turn looking for a conflicting title 
    388533        else { 
    389         if(titleClashes(title_final, null)) { 
     534        String collectDir = collectDirChanged ? newCollectPath : Gatherer.getCollectDirectoryPath(); 
     535        if(titleClashes(collectDir, title_final, null)) { 
    390536            JOptionPane jOptionPane=new JOptionPane(); 
    391537                    jOptionPane.setComponentOrientation(Dictionary.getOrientation()); 
     
    395541            } 
    396542        } 
     543        } 
     544 
     545        // going through with collection creation 
     546        if(collectDirChanged) {      
     547        Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(), newCollectPath);  
     548        // will tell the server that the collect directory has changed and that 
     549        // the workspace needs to be refreshed (Documents in Greenstone Collections) 
    397550        } 
    398551 
     
    435588    } 
    436589    public int compareTo(Object other) { 
    437         return toString().toLowerCase().compareTo(other.toString().toLowerCase()); 
     590        if(this == null && other == null) { 
     591        return 0; 
     592        } 
     593        else if(other == null) {  
     594        return 1;  
     595        } 
     596        else if(this == null) { 
     597        return -1; 
     598        }  
     599        else { 
     600        return toString().toLowerCase().compareTo(other.toString().toLowerCase()); 
     601        } 
    438602    } 
    439603    public boolean equals(Object other) { 
     
    450614    } 
    451615    } 
     616 
     617    /** FileFilter for the Filechooser to choose the collection to base the new one on:  
     618     * Only displays directories. */ 
     619    private class CollectionFileFilter extends FileFilter {  
     620    public boolean accept(File f) { 
     621        return f.isDirectory(); 
     622    } 
     623    public String getDescription() { 
     624        return "greenstone collection view"; //return "directories only"; 
     625    } 
     626    } 
     627 
     628    /** Folders that can be used as a base collection have a special icon */ 
     629    private class CollectionFileView extends FileView { 
     630    final String configfile_name;    
     631    final ImageIcon COLLECTION_ICON = JarTools.getImage("gsCollection.gif", true); 
     632     
     633    private File previous = null; 
     634    private boolean previousWasCollection = false; 
     635 
     636    public CollectionFileView() { 
     637        configfile_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE; 
     638    } 
     639 
     640    // A human readable description of the file. 
     641    public String getDescription(File f) { 
     642        if(!f.equals(previous)) { 
     643        previous = f; 
     644        // no idea if it's a collection or not, calculate this next time 
     645        previousWasCollection = false;  
     646        } 
     647        return null; // FilewView superclass will handle it 
     648    } 
     649         
     650    // The icon that represents this file in the JFileChooser. 
     651    public Icon getIcon(File f) { 
     652         
     653        if(f.equals(previous) && previousWasCollection) { 
     654        return COLLECTION_ICON; 
     655        }  
     656         
     657        if(isCollectionBase(f)) { 
     658        return COLLECTION_ICON; 
     659        }        
     660         
     661        return null; // FileView superclass will do the default 
     662    } 
     663         
     664    // The name of the file. 
     665    public String getName(File f) {  
     666        if(!f.equals(previous)) { 
     667        previous = f; 
     668        // no idea if it's a collection or not, calculate this next time 
     669        previousWasCollection = false;  
     670        } 
     671        return f.getName();  
     672    } 
     673 
     674    // A human readable description of the type of the file. 
     675    public String getTypeDescription(File f) { 
     676        if(f.equals(previous) && previousWasCollection) { 
     677        return "collection"; 
     678        }  
     679        if(isCollectionBase(f)) { 
     680        return "collection"; 
     681        } 
     682        // else 
     683        return "not a collection"; 
     684    } 
     685 
     686    // Whether the directory is traversable or not. 
     687    public Boolean isTraversable(File f) { 
     688        if(f.equals(previous) && previousWasCollection) { 
     689        return Boolean.FALSE; 
     690        }        
     691         
     692        if(isCollectionBase(f)) { 
     693        return Boolean.FALSE; 
     694        } 
     695 
     696        if(f.isFile()) { // not traversable 
     697        return Boolean.FALSE; 
     698        } 
     699        // any other kind of directory is traversable 
     700        return Boolean.TRUE;         
     701    } 
     702 
     703     
     704    /** returns false for collect groups and collect dirs. */ 
     705    private boolean isCollectionBase(File f) {       
     706        previous = f; 
     707        previousWasCollection = false; 
     708 
     709        if(!f.isFile()) { 
     710        // If the directory has a etc/collect.cfg file then it looks like a collection 
     711        File collect_cfg_file = new File(f, configfile_name); 
     712        if (collect_cfg_file.exists()) { 
     713            // Check for group coll: Check the collect.cfg for collectgroup=true 
     714            BasicCollectionConfiguration config = new BasicCollectionConfiguration(collect_cfg_file); 
     715            if (!config.getCollectGroup().equals("true")) { 
     716            previousWasCollection = true; 
     717            }        
     718        } 
     719        } 
     720        return previousWasCollection; 
     721    } 
     722 
     723    } 
    452724} 
    453725 
  • main/trunk/gli/src/org/greenstone/gatherer/gui/OpenCollectionDialog.java

    r22357 r22605  
    5858    private int result; 
    5959    private JButton cancel_button; 
     60    private JButton chdir_button; 
    6061    private JButton open_button; 
    6162    private JList collection_list; 
     
    6364    private JPanel description_pane; 
    6465    private String filename; 
     66    private String newCollectPath; 
    6567 
    6668    public OpenCollectionDialog() { 
     
    7072    setSize(SIZE); 
    7173    setTitle(Dictionary.get("OpenCollectionDialog.Title")); 
    72      
     74    newCollectPath = Gatherer.getCollectDirectoryPath(); 
     75 
    7376    // Creation 
    7477    JPanel content_pane = (JPanel) getContentPane(); 
     
    103106    open_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Open"), Dictionary.get("OpenCollectionDialog.Open_Tooltip")); 
    104107    open_button.setEnabled(false); 
    105      
     108    chdir_button = new GLIButton(Dictionary.get("General.CD"), Dictionary.get("General.CD_Tooltip")); 
    106109    cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip")); 
    107110     
    108111    // Connection 
     112    chdir_button.addActionListener(new ChangeDirListener()); 
     113    if(Gatherer.isGsdlRemote) { // disable changing directories for client GLI 
     114        chdir_button.setEnabled(false); 
     115    } 
    109116    cancel_button.addActionListener(new CancelListener()); 
    110117    open_button.addActionListener(new OpenListener()); 
     
    137144    center_pane.add(description_pane); 
    138145 
    139     button_pane.setLayout(new GridLayout(1,4)); 
    140         JPanel tmp =new JPanel(); 
    141         tmp.setComponentOrientation(Dictionary.getOrientation()); 
    142     button_pane.add(tmp); 
     146    button_pane.setLayout(new GridLayout(1,3)); 
     147        button_pane.add(chdir_button); 
    143148    button_pane.add(open_button); 
    144149    button_pane.add(cancel_button); 
     
    164169    public String getFileName() { 
    165170    return this.filename; 
     171    } 
     172 
     173    private class ChangeDirListener implements ActionListener { 
     174    public void actionPerformed(ActionEvent event) { 
     175        JFileChooser chooser = new JFileChooser(newCollectPath); 
     176        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 
     177        chooser.setDialogTitle(Dictionary.get("General.ChooseCollectDirectory")); 
     178        int returnVal = chooser.showOpenDialog(OpenCollectionDialog.this); 
     179        if(returnVal == JFileChooser.APPROVE_OPTION) { 
     180        String oldCollectPath = newCollectPath; 
     181        newCollectPath = chooser.getSelectedFile().getAbsolutePath() + File.separator; 
     182         
     183        if(!newCollectPath.equals(oldCollectPath)) { 
     184            // reload the list of available collections using this new path 
     185            CollectionListModel listModel = (CollectionListModel)collection_list.getModel(); 
     186            listModel.reload(newCollectPath); 
     187            collection_list.repaint(); 
     188        } 
     189        }  
     190    } 
    166191    } 
    167192 
     
    268293    public CollectionListModel() { 
    269294        data = new TreeSet(); 
    270         File collect_directory = new File(Gatherer.getCollectDirectoryPath()); 
     295        reload(Gatherer.getCollectDirectoryPath()); 
     296    } 
     297 
     298    // to be called when the collection directory has changed 
     299    public void reload(String collectDirectoryPath) { 
     300        data.clear(); 
     301        File collect_directory = new File(collectDirectoryPath); 
    271302        if (!collect_directory.exists()) { 
    272303        collect_directory = null; 
     
    276307        load_collection_configs(data,collect_directory); 
    277308 
     309        // list size/contents has changed, this listmodel must notify the  
     310        // encapsulating JList, else it won't be able to display longer lists 
     311        fireContentsChanged(this, 0, data.size());  
    278312    } 
    279313 
     
    389423        OpenCollectionDialog.this.dispose(); 
    390424        } 
     425 
     426        Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(), newCollectPath);  
     427            // will tell the server that the collect directory has changed and that 
     428        // the workspace needs to be refreshed (Documents in Greenstone Collections) 
    391429    } 
    392430    } 
  • main/trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java

    r20961 r22605  
    6868    private JButton apply_button; 
    6969    private JButton cancel_button; 
     70    private JButton chdir_button; 
    7071    private JButton ok_button; 
    7172    private JCheckBox show_file_size_checkbox; 
     
    9293    private JTextField program_field; 
    9394    private JTextField proxy_host_field; 
     95    private JTextField collect_dir_field; 
     96 
    9497    private Preferences self; 
    9598 
     
    298301        } 
    299302    } 
     303 
     304    JPanel collect_dir_pane = new JPanel(); 
     305        collect_dir_pane.setComponentOrientation(Dictionary.getOrientation()); 
     306    collect_dir_pane.setPreferredSize(ROW_SIZE); 
     307    JLabel collect_dir_label = new JLabel(Dictionary.get("Preferences.Connection.CollectDirectory")); 
     308    collect_dir_label.setPreferredSize(LABEL_SIZE); 
     309    collect_dir_label.setComponentOrientation(Dictionary.getOrientation()); 
     310    collect_dir_field = new JTextField(Gatherer.getCollectDirectoryPath()); 
     311    //collect_dir_field = new JTextField(Configuration.getString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true)); 
     312    collect_dir_field.setCaretPosition(0); 
     313    collect_dir_field.setToolTipText(Dictionary.get("Preferences.Connection.CollectDirectory_Tooltip")); 
     314    collect_dir_field.setEditable(false); 
     315    JButton chdir_button = new GLIButton(Dictionary.get("General.CD"), Dictionary.get("General.CD_Tooltip")); 
     316    chdir_button.addActionListener(new ChangeDirListener()); 
     317    if(Gatherer.isGsdlRemote) { // disable changing directories for client GLI 
     318        chdir_button.setEnabled(false); 
     319    } 
    300320     
    301321    boolean currently_enabled = Configuration.get("general.use_proxy", true); 
     
    370390    } 
    371391 
     392    collect_dir_pane.setLayout(new BorderLayout()); 
     393    collect_dir_pane.add(collect_dir_label, BorderLayout.LINE_START); 
     394    collect_dir_pane.add(collect_dir_field, BorderLayout.CENTER); 
     395    collect_dir_pane.add(chdir_button, BorderLayout.LINE_END); 
     396 
    372397    proxy_host_pane.setLayout(new BorderLayout()); 
    373398    proxy_host_pane.add(proxy_host_label, BorderLayout.LINE_START); 
     
    389414        connection_pane.add(servlet_pane); 
    390415    } 
     416    connection_pane.add(collect_dir_pane); 
     417 
    391418    connection_pane.add(use_proxy_checkbox); 
    392419    connection_pane.add(proxy_host_pane); 
     
    731758    } 
    732759 
     760    private class ChangeDirListener implements ActionListener { 
     761    public void actionPerformed(ActionEvent event) { 
     762        JFileChooser chooser = new JFileChooser(collect_dir_field.getText()); 
     763        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 
     764        int returnVal = chooser.showOpenDialog(Preferences.this); 
     765        if(returnVal == JFileChooser.APPROVE_OPTION) { 
     766        collect_dir_field.setText(chooser.getSelectedFile().getAbsolutePath() + File.separator); 
     767        } // else collect_dir_field text remains as it is 
     768    } 
     769    } 
    733770 
    734771    private class OKButtonListener 
     
    826863        Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem()); 
    827864        } 
     865 
     866        // collect directory change 
     867        String newCollectPath = collect_dir_field.getText(); 
     868        if(!newCollectPath.endsWith(File.separator)) { 
     869        newCollectPath += File.separator; 
     870        } 
     871        Gatherer.collectDirectoryHasChanged(Gatherer.getCollectDirectoryPath(), newCollectPath); 
     872        // will tell the server that the collect directory has changed and that 
     873        // the workspace needs to be refreshed (Documents in Greenstone Collections) 
     874 
    828875        
    829876        Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected()); 
  • main/trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r20446 r22605  
    459459    return new_name; 
    460460  } 
     461 
     462     
     463    /** Write out a property line--a (property, value) pair--to the gsdl(3)site.cfg file. 
     464     * If the file already contains the line as-is, it is not re-written.    
     465     * If the file doesn't contain the line, it is appended. 
     466     * If the file contained a different value for the property, the line is corrected 
     467     * and the file is written out. 
     468     * Not using the Properties class, as we want to keep the file's contents in the  
     469     * same order and preserve all the comments in as they're meant to help the user. 
     470     */ 
     471    public static void updatePropertyConfigFile(String filename, String propertyName, String propertyValue) { 
     472    BufferedReader fin = null; 
     473    BufferedWriter fout = null; 
     474    StringBuffer contents = new StringBuffer(); 
     475    String insertLine = propertyName+"\t"+propertyValue+"\n"; // new line after every propertyLine 
     476    boolean found = false; 
     477    try { 
     478        fin = new BufferedReader(new FileReader(filename)); 
     479        String line = ""; 
     480        while((line = fin.readLine()) != null) { 
     481        if(line.startsWith(propertyName)) { // won't match comment 
     482            found = true; 
     483            if(line.equals(insertLine)) { // file is already correct, nothing to do 
     484            fin.close(); 
     485            fin = null; 
     486            break; 
     487            } else { 
     488            contents.append(insertLine); 
     489            } 
     490 
     491        } else { // any other line 
     492            contents.append(line);           
     493            contents.append("\n"); // ensures the required new line at end of file 
     494        } 
     495        } 
     496 
     497        if(fin != null) { // need to write something out to the file 
     498        fin.close(); 
     499        fin = null; 
     500 
     501        // if collecthome wasn't already specified in the file, append it 
     502        if(!found) {  
     503            fout = new BufferedWriter(new FileWriter(filename, true)); // append mode 
     504            fout.write(insertLine, 0, insertLine.length()); 
     505        } else { 
     506             
     507            fout = new BufferedWriter(new FileWriter(filename)); // hopefully this will overwrite 
     508            fout.write(contents.toString(), 0, contents.length()); 
     509        } 
     510 
     511        fout.close(); 
     512        fout = null; 
     513        } // else the file is fine 
     514    } catch(IOException e) { 
     515        System.err.println("*** Could not update file: " + filename);  
     516        System.err.println("with the " + propertyName + " property set to " + propertyValue); 
     517        System.err.println("Exception occurred: " + e.getMessage()); 
     518    } finally { 
     519        try { 
     520        if(fin != null) { 
     521            fin.close(); 
     522            fin = null; 
     523        } 
     524        if(fout != null) { 
     525            fout.close(); 
     526            fout = null; 
     527        } 
     528        } catch(IOException ioe) { 
     529        fin = null; 
     530        fout = null; 
     531        } 
     532         
     533    } 
     534     
     535    } 
    461536    
    462537}