Changeset 6159


Ignore:
Timestamp:
2003-12-08T14:35:46+13:00 (20 years ago)
Author:
jmt12
Message:

The 'Base This Collection on' field now uses the same format for collection names as everywhere else

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionDetailsPrompt.java

    r6051 r6159  
    3737import org.greenstone.gatherer.Gatherer;
    3838import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
    39 import org.greenstone.gatherer.util.Utility;
    4039import org.greenstone.gatherer.gui.SimpleMenuBar;
    4140import org.greenstone.gatherer.gui.ModalDialog;
     41import org.greenstone.gatherer.util.StaticStrings;
     42import org.greenstone.gatherer.util.Utility;
    4243
    4344public class NewCollectionDetailsPrompt
    4445    extends ModalDialog {
     46
     47    static public boolean titleClashes(String title) {
     48    File collection_directory = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));
     49    File children[] = collection_directory.listFiles();
     50    for(int i = 0; children != null && i < children.length; i++) {
     51        if(children[i].isDirectory()) {
     52        BasicCollectionConfiguration other_collection = new BasicCollectionConfiguration(new File(children[i], Utility.CONFIG_DIR));
     53        if(other_collection.getName().equalsIgnoreCase(title)) { 
     54            return true;
     55        }
     56        other_collection = null;
     57        }
     58    }
     59    return false;
     60    }
     61
    4562    private boolean cancelled;
    4663    private File base_final;
     
    91108        if(metadata_directory.exists() || collection_name.equals(Utility.COLLECTION_DLS) || collection_name.equals(Utility.COLLECTION_DEMO)) {
    92109            // Add to model.
    93             Item item = new Item(possible_collections[i], collection_name);
     110            Item item = new Item(possible_collections[i], collect_cfg);
    94111            if(!base_collection_model.contains(item)) {
    95112            base_collection_model.add(item);
    96113            }
    97114        }
     115        collection_name = null;
     116        collect_cfg = null;
    98117        // Else not a collection we know how to retrieve the metadata set for.
    99118        }
     
    277296        while(i < title_final.length() && name_buffer.length() < 8) {
    278297            char c = title_final.charAt(i);
    279             if(!Character.isWhitespace(c)) {
    280                 name_buffer.append(Character.toLowerCase(c));
     298            // Arg. We need a few more tests than just whitespace
     299            if(Character.isLetterOrDigit(c)) {
     300                name_buffer.append(Character.toLowerCase(c));
    281301            }
    282302            i++;
     
    335355        file = file.getParentFile();
    336356        BasicCollectionConfiguration collect_cfg = new BasicCollectionConfiguration(new File(file, Utility.META_DIR));
    337         Item item = new Item(file, collect_cfg.getName());
     357        Item item = new Item(file, collect_cfg);
    338358        base_collection.addItem(item);
    339359        base_collection.setSelectedItem(item);
     360        collect_cfg = null;
    340361        }
    341362    }
     
    372393    }
    373394
    374     private class CreateListener
    375         implements ActionListener {
    376 
     395    private class CreateListener
     396    implements ActionListener {
     397   
    377398    public void actionPerformed(ActionEvent event) {
    378         // Validate.
    379         title_final = title.getText();
    380         if(title_final.length() == 0) {
    381             JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
     399        // Validate.
     400        title_final = title.getText();
     401        if(title_final.length() == 0) {
     402        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
     403        title.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
     404        title.setBackground(Gatherer.config.getColor("coloring.error_background", false));
     405        return;
     406        }
     407        // 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
     408        else {
     409        if(titleClashes(title_final)) {
     410            if(JOptionPane.showConfirmDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Clash"), Dictionary.get("General.Warning"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.NO_OPTION) {
    382411            title.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    383412            title.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    384413            return;
    385         }
    386         // 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
    387         else {
    388             File collection_directory = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));
    389             File children[] = collection_directory.listFiles();
    390             for(int i = 0; children != null && i < children.length; i++) {
    391                 if(children[i].isDirectory()) {
    392                     BasicCollectionConfiguration other_collection = new BasicCollectionConfiguration(new File(children[i], Utility.CONFIG_DIR));
    393                     if(other_collection.getName().equalsIgnoreCase(title_final)) {
    394                         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Title_Clash"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
    395                         title.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    396                         title.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    397                         return;
    398                     }
    399                     other_collection = null;
    400                 }
    401             }
    402         }
    403 
    404         /* Suppress filename
    405         name_final = file.getText();
    406         if(name_final.length() > 0) {
    407         // Determine if this filename is already in use.
    408         File collection_directory = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));
    409         File children[] = collection_directory.listFiles();
    410         for(int i = 0; children != null && i < children.length; i++) {
    411             if(children[i].getName().equals(name_final)) {
    412             JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
    413             file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    414             file.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    415             return;
    416414            }
    417415        }
    418416        }
    419         else {
    420         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
    421         file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    422         file.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    423         return;
    424         }
     417        /* Suppress filename
     418           name_final = file.getText();
     419           if(name_final.length() > 0) {
     420           // Determine if this filename is already in use.
     421           File collection_directory = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));
     422           File children[] = collection_directory.listFiles();
     423           for(int i = 0; children != null && i < children.length; i++) {
     424           if(children[i].getName().equals(name_final)) {
     425           JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
     426           file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
     427           file.setBackground(Gatherer.config.getColor("coloring.error_background", false));
     428           return;
     429           }
     430           }
     431           }
     432           else {
     433           JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
     434           file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
     435           file.setBackground(Gatherer.config.getColor("coloring.error_background", false));
     436           return;
     437           }
    425438        */
    426439        /* Suppress email
    427         email_final = address.getText() + "@" + host.getText();
    428         if(email_final.length() == 0 || email_final.startsWith("@") || email_final.endsWith("@")) {
    429         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Email_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
    430         address.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    431         address.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    432         host.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    433         host.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    434         return;
    435         }
     440           email_final = address.getText() + "@" + host.getText();
     441           if(email_final.length() == 0 || email_final.startsWith("@") || email_final.endsWith("@")) {
     442           JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Email_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
     443           address.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
     444           address.setBackground(Gatherer.config.getColor("coloring.error_background", false));
     445           host.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
     446           host.setBackground(Gatherer.config.getColor("coloring.error_background", false));
     447           return;
     448           }
    436449        */
    437450        description_final = description.getText();
     
    445458        Item item_final = (Item) base_collection.getSelectedItem();
    446459        base_final = item_final.getFile();
    447 
     460       
    448461        cancelled = false;
    449 
     462       
    450463        self.dispose();
    451464    }
    452465    }
    453 
     466   
    454467    private class DescriptionListener
    455468    extends KeyAdapter {
     
    464477    private class Item
    465478    implements Comparable {
     479    private BasicCollectionConfiguration config;
    466480    private File file;
    467481    private String name;
     482    public Item(File file, BasicCollectionConfiguration config) {
     483        this.config = config;
     484        this.file = file;
     485        this.name = null;
     486    }
    468487    public Item(File file, String name) {
     488        this.config = null;
    469489        this.file = file;
    470490        this.name = name;
     
    480500    }
    481501    public String toString() {
     502        if(name == null && config != null) {
     503        StringBuffer title_buffer = new StringBuffer(config.getName());
     504        title_buffer.append(StaticStrings.SPACE_CHARACTER);
     505        title_buffer.append(StaticStrings.OPEN_PARENTHESIS_CHARACTER);
     506        title_buffer.append(config.getShortName());
     507        title_buffer.append(StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
     508        name = title_buffer.toString();
     509        title_buffer = null;
     510        }
    482511        return name;
    483512    }
Note: See TracChangeset for help on using the changeset viewer.