Ignore:
Timestamp:
2003-06-16T10:47:06+12:00 (21 years ago)
Author:
jmt12
Message:

Sunday's work

Location:
trunk/gli/src/org/greenstone/gatherer/collection
Files:
3 edited

Legend:

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

    r4366 r4675  
    1414    private Element maintainer_element;
    1515    private Element name_element;
     16    private File file;
    1617    private String creator;
    1718    private String description;
     
    2021
    2122    public CollectionConfiguration(File file) {
     23    this.file = file;
    2224    try {
    2325        String filename = file.getName().toLowerCase();
    2426        if(filename.endsWith(".xml")) {
    25                      
     27
    2628        }
    2729        else if(filename.endsWith(".cfg")) {
     
    5658                    String language = temp.substring(temp.indexOf("=") + 1, temp.length() - 1);
    5759                    if(name == null || language.equalsIgnoreCase(Gatherer.dictionary.getLanguage())) {
    58                         name = Utility.decodeGreenstone(tokenizer.nextToken()); 
     60                        name = Utility.decodeGreenstone(tokenizer.nextToken());
    5961                    }
    6062                    }
     
    101103                ///ystem.err.println("creator     = " + creator);
    102104                ///ystem.err.println("maintainer  = " + maintainer);
    103                 ///ystem.err.println("description = " + description); 
     105                ///ystem.err.println("description = " + description);
    104106    }
    105107    catch(Exception error) {
     
    131133    }
    132134
     135    public File getFile() {
     136        return file;
     137    }
     138
    133139    public String getMaintainer() {
    134140    String result = "";
     
    153159    }
    154160
     161    /** Retrieve the short name for this collection which, given this current file is in <col_name>/etc/collect.cfg, is the name of this file's parent file's parent.
     162    * @return the short name of this collection as a String
     163    */
     164    public String getShortName() {
     165        return file.getParentFile().getParentFile().getName();
     166    }
     167
    155168    public void setName(String name) {
    156169    /** @todo */
    157170    }
     171
     172    /** Display the title for this collection. */
     173    public String toString() {
     174        return getName();
     175    }
    158176}
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r4673 r4675  
    103103
    104104    private int special_case = -1;
     105    /** Holds a reference to the thread responsible for closing the collection. If non-null then only calls from the given thread will see the collection is non-ready. All other threads will have to wait until closing thread, and all of it consequential calls, are completely finished. */
     106    private Thread closing_thread = null;
     107
    105108    /** The name of the standard lock file. */
    106109    static final public String LOCK_FILE = "gatherer.lck";
     
    142145      */
    143146    public void buildCollection() {
    144     Gatherer.println("Building collection");
     147    Gatherer.println("CollectionManager.buildCollection()");
    145148    building = true;
    146149
     
    162165    shell.addGShellListener(Gatherer.g_man.create_pane);
    163166    shell.start();
     167    Gatherer.println("CollectionManager.buildCollection().return");
    164168    }
    165169    /** Used to determine whether the currently active collection has been built.
     
    178182     */
    179183    public void closeCollection() {
     184    Gatherer.println("Close collection: " + collection.getName());
     185    // We set the closing thread, as it should be the only one who can actually see the collection is closed, at least until the closing thread expires.
     186    closing_thread = Thread.currentThread();
    180187    // System.err.println("Closing collection...");
    181188    // Remove the lock on this file, then remove the collection.
     
    190197    Gatherer.g_man.collectionChanged(false);
    191198    // System.err.println("Closed collection.");
     199    // All of the consequences of a close should have been processed by now, so others should now see the collection as non-ready.
     200    closing_thread = null;
    192201    }
    193202
     
    199208    }
    200209
    201     /** Used to set the current collection to the given collection. Note that this call should -always- be proceeded by a ready call, and if the colection is ready and the saved flag is unset then the user should be prompted to save. Also note that this method creates yet another GShell to run buildcol.pl. 
     210    /** Used to set the current collection to the given collection. Note that this call should -always- be proceeded by a ready call, and if the colection is ready and the saved flag is unset then the user should be prompted to save. Also note that this method creates yet another GShell to run buildcol.pl.
    202211     * @param description a description of the collection as a String
    203212     * @param email the email address of the author/maintainer as a String
     
    243252        progress.setNote(get("Log_Created"));
    244253        }
    245                
     254
    246255        progress.setProgress(2);
    247256
     
    707716      */
    708717    public void importCollection() {
     718    Gatherer.println("CollectionManager.importCollection()");
    709719    if(!saved()) {
    710720        // Force save.
     
    742752        shell.start();
    743753    }
     754    Gatherer.println("CollectionManager.importCollection().return");
    744755    }
    745756    /** Attempts to load the given collection. Currently uses simple serialization of the collection class.
     
    890901      */
    891902    public synchronized void processBegun(GShellEvent event) {
     903    Gatherer.println("CollectionManager.processBegun(" + event.getType() + ")");
    892904    ///ystem.err.println("ProcessBegun " + event.getType());
    893905    // If this is one of the types where we wish to lock user control
     
    901913      */
    902914    public synchronized void processComplete(GShellEvent event) {
     915    Gatherer.println("CollectionManager.processComplete(" + event.getType() + ")");
    903916    ///ystem.err.println("ProcessComplete " + event.getType());
    904917    Gatherer.g_man.lockCollection((event.getType() == GShell.IMPORT), false);
     
    936949      * @return A <i>boolean</i> which is <i>true</i> to indicate a collection has been loaded and thus the collection is ready for editing, <i>false</i> otherwise.
    937950      */
    938     public boolean ready() {
    939     if(collection != null) {
    940         return true;
    941     }
    942     return false;
    943     }
     951
     952    public synchronized boolean ready() {
     953        if(collection != null) {
     954            return true;
     955        }
     956        else {
     957            return false;
     958        }
     959    }
     960
     961    public synchronized boolean reallyReady() {
     962    if(collection == null) {
     963        Gatherer.println("Called reallyReady() when collection was null.");
     964        Gatherer.println("Closing thread = " + closing_thread);
     965        Gatherer.println("This thread = " + Thread.currentThread());
     966        Gatherer.println("Thus we return: " + (closing_thread == null || closing_thread == Thread.currentThread() ? "not ready" : "ready"));
     967    }
     968    // If the closing thread is non-null we should only allow that thread to see the collection as closed.
     969    if(closing_thread != null) {
     970        // Only the closing thread sees the truth
     971        if(Thread.currentThread() == closing_thread) {
     972            return (collection == null);
     973        }
     974        // All other threads are told a lie.
     975        else {
     976            return true;
     977        }
     978    }
     979    else {
     980        if(collection != null) {
     981            return true;
     982        }
     983        else {
     984            return false;
     985        }
     986    }
     987    }
    944988    /** Called to refresh the models upon which the trees are based.
    945989      * @see org.greenstone.gatherer.collection.Collection
     
    10011045      */
    10021046    public void saveCollection(boolean close_after, boolean exit_after) {
     1047        Gatherer.println("Save collection: " + collection.getName());
    10031048    try {
    10041049        SaveCollectionTask save_task = new SaveCollectionTask(collection, close_after, exit_after);
     1050        save_task.start();
    10051051        // Run this in the same thread
    1006         save_task.run();
     1052        //save_task.run();
    10071053    }
    10081054    catch(Exception error) {
     
    10881134
    10891135    try {
    1090                 // We have to ensure that the local library 
     1136                // We have to ensure that the local library
    10911137        if(Gatherer.config.exec_file != null) {
    10921138        ///ystem.err.println("Local Library Found!");
  • trunk/gli/src/org/greenstone/gatherer/collection/DeleteCollectionPrompt.java

    r4660 r4675  
    4343import org.greenstone.gatherer.Gatherer;
    4444import org.greenstone.gatherer.collection.Collection;
    45 import org.greenstone.gatherer.gui.ModalDialog;
    46 import org.greenstone.gatherer.gui.SimpleMenuBar;
    4745import org.greenstone.gatherer.util.ArrayTools;
    48 import org.greenstone.gatherer.util.GSDLSiteConfig;
    4946import org.greenstone.gatherer.util.Utility;
    5047/** This class provides the functionality to delete current collections from the GSDLHOME/collect/ directory. The user chooses the collection from a list, where each entry also displays details about itself, confirms the delete of a collection by checking a checkbox then presses the ok button to actually delete the collection.
     
    5350 */
    5451public class DeleteCollectionPrompt
    55     extends ModalDialog {
     52    extends JDialog {
    5653    /** The currently selected collection for deletion. */
    57     private CollectionEntry collection = null;
     54    private CollectionConfiguration collection = null;
    5855    /** The model behind the list. */
    5956    private DefaultListModel list_model = null;
     
    7673    /** A string array used to pass arguments to the phrase retrieval method. */
    7774    private String args[] = null;
    78 
    79     private boolean current_coll_deleted = false;
    8075    /** The size of the delete prompt screen. */
    8176    public static final Dimension SIZE = new Dimension(500, 500);
     
    8782     */
    8883    public DeleteCollectionPrompt() {
    89     super(Gatherer.g_man);
     84    super();
    9085    this.close_button = new JButton(get("General.Close", null));
    9186    this.confirmation = new JCheckBox(get("Confirm_Delete", null));
     
    10095    this.setSize(SIZE);
    10196    this.setTitle(get("Title", null));
    102     this.setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at
    10397    close_button.addActionListener(new CloseButtonListener());
    10498    confirmation.addActionListener(new ConfirmationCheckBoxListener());
     
    127121    prompt = null;
    128122    }
    129     /** This method causes the modal prompt to be displayed.
    130      * returns true if it has deleted the collection that is currently open*/
    131     public boolean display() {
     123    /** This method causes the modal prompt to be displayed. */
     124    public void display() {
    132125    // Central pane
    133126    JPanel list_pane = new JPanel(new BorderLayout());
     
    170163    Dimension screen_size = Gatherer.config.screen_size;
    171164    this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
    172     this.setVisible(true); // blocks until the dialog is killed
    173     return current_coll_deleted;
    174    
    175     }
    176     /** Shows a delete complete prompt.
     165    this.show();
     166    }
     167
     168    /** Shows a delete complete prompt.
    177169      * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
    178170      * @see org.greenstone.gatherer.collection.Collection
     
    188180    }
    189181    }
     182
    190183    /** Retrieves a phrase from the <strong>Dictionary</strong> in <strong>Gatherer</strong>.
    191184      * @param key A <strong>String</strong> used to match against a specific phrase in the dictionary.
     
    199192    return Gatherer.dictionary.get(key, args);
    200193    }
    201     /** Attempts to load the given collection. Currently uses simple
    202       * serialization of the collection class.
    203       * @param location The path to the serialized collection.
    204       */
    205 //      public Collection loadCollection(File file) {
    206 //      Collection col = null;
    207 //      try {
    208 //          FileInputStream fis = new FileInputStream(file);
    209 //          BufferedInputStream bin = new BufferedInputStream(fis);
    210 //          ObjectInputStream input = new ObjectInputStream(bin);
    211 //          col = (Collection) input.readObject();
    212 //          input.close();
    213 //          input = null;
    214 //          bin.close();
    215 //          bin = null;
    216 //          fis.close();
    217 //          fis = null;
    218 //      }
    219 //      catch (Exception error) {
    220 //          error.printStackTrace();
    221 //      }
    222 //      return col;
    223 //      }
     194
    224195    /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
    225196      * @see org.greenstone.gatherer.Configuration
     
    233204    File collect_directory = new File(collect_directory_name);
    234205    if(collect_directory.exists()) {
    235         // Now for each child directory see if it contains a .col file and
    236         // if so try to load it..
     206        // Now for each child directory see if it contains a .col file and if so try to load it..
    237207        File collections[] = collect_directory.listFiles();
    238208        ArrayTools.sort(collections);
    239209        for(int i = 0; collections != null && i < collections.length; i++) {
    240         File config_file = Utility.findConfigFile(collections[i]);
    241         if (config_file != null) {
    242             CollectionConfiguration config = new CollectionConfiguration(config_file);
    243             if (config != null) {
    244             CollectionEntry col = new CollectionEntry(collections[i].getName(), config);
    245             list_model.addElement(col);
     210        File children[] = collections[i].listFiles();
     211        for(int j = 0; children != null && j < children.length; j++) {
     212            if(children[j].getAbsolutePath().endsWith(".col")) {
     213            list_model.addElement(new CollectionConfiguration(children[j]));
    246214            }
    247            
    248             //File children[] = collections[i].listFiles();
    249             //for(int j = 0; children != null && j < children.length; j++) {
    250             //if(children[j].getAbsolutePath().endsWith(".col")) {
    251             //Collection col = loadCollection(children[j]);
    252             // If we've actually loaded
    253             //if(col != null) {
    254             //   list_model.addElement(col);
    255             //}
    256             //}
    257215        }
    258216        }
     
    261219    }
    262220    /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
    263     private class CloseButtonListener 
     221    private class CloseButtonListener
    264222    implements ActionListener {
    265223    /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
     
    272230    /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
    273231      */
    274     private class CollectionListListener 
     232    private class CollectionListListener
    275233    implements ListSelectionListener {
    276234    /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
     
    280238        if(!list.isSelectionEmpty()) {
    281239        confirmation.setEnabled(true);
    282         collection = (CollectionEntry) list.getSelectedValue();
    283         args = new String[4];
    284         args[0] = collection.getTitle();
    285         args[1] = collection.getName();
     240        collection = (CollectionConfiguration) list.getSelectedValue();
     241        args = new String[5];
     242        args[0] = collection.getName();
     243        args[1] = collection.getShortName();
    286244        args[2] = collection.getCreator();
    287         args[3] = collection.getDescription();
     245        args[3] = collection.getMaintainer();
     246        args[4] = collection.getDescription();
    288247        details.setText(get("Details", args));
    289         details.setCaretPosition(0);
    290248        }
    291249        else {
     
    309267        }
    310268    }
    311     }         
     269    }
    312270    /** The OK button listener implementation. */
    313     private class OKButtonListener 
     271    private class OKButtonListener
    314272    implements ActionListener {
    315273    /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
     
    320278     */
    321279    public void actionPerformed(ActionEvent event) {
    322         // Delete the selected collection.
    323 
    324         // first of all we must release it from the local library
    325         if(Gatherer.config.exec_file != null) {
    326         ///ystem.err.println("Local Library Found!");
    327         Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getName());
    328         }
    329 
    330         File delete_me = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator);
     280                // Delete the selected collection.
     281        File delete_me = collection.getFile().getParentFile().getParentFile();
    331282        if(Utility.delete(delete_me)) {
    332         if (collection.getName().equals(Gatherer.c_man.getCollection().getName())) {
    333             current_coll_deleted = true;
    334         }
    335 
    336283        resultPrompt(true);
    337284        list_model.removeElement(collection);
     
    347294    }
    348295    }
    349 
    350     private class CollectionEntry {
    351 
    352     private String name = null;
    353     private CollectionConfiguration config = null;
    354 
    355     public CollectionEntry(String name, CollectionConfiguration config) {
    356         this.name = name;
    357         this.config = config;
    358     }
    359 
    360     public String getName() {
    361         return name;
    362     }
    363 
    364     public String getTitle() {
    365         return config.getName();
    366     }
    367 
    368     public String getCreator() {
    369         return config.getCreator();
    370     }
    371 
    372     public String getDescription() {
    373         return config.getDescription();
    374     }
    375    
    376     public String toString() {
    377         return config.getName();
    378        
    379     }
    380     }
    381296}
    382297
Note: See TracChangeset for help on using the changeset viewer.