Changeset 5164


Ignore:
Timestamp:
2003-08-18T14:10:31+12:00 (21 years ago)
Author:
jmt12
Message:

I can't remember what has changed, but I bet it was for the better

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
22 edited

Legend:

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

    r5045 r5164  
    5656public class Configuration
    5757    extends Hashtable {
     58
     59    static final public boolean COLLECTION_SPECIFIC = true;
     60    static final public boolean GENERAL_SETTING = true;
     61
     62    /** The string identifying an argument's name attribute. */
     63    static final private String ARGUMENT_NAME = "name";
     64    /** The name of the general Gatherer configuration file. */
     65    static final private String CONFIG_XML = "config.xml";
     66    /** The name of the root element of the subtree containing gatherer configuration options. This is required as the document itself may contain several other subtrees of settings (such as in the case of a '.col' file). */
     67    static final private String GATHERER_CONFIG = "GathererConfig";
     68    /** The string identifying an argument element. */
     69    static final private String GATHERER_CONFIG_ARGUMENT = "Argument";
     70    /** The name of a Name Element. */
     71    static final private String NAME = "Name";
     72    /** The name of the other arguments element. */
     73    static final private String OTHER = "Other";
     74    /** The name of an information Element within the Other subtree. */
     75    static final private String OTHER_INFO = "Info";
     76    /** The name of the general Gatherer configuration template. */
     77    static final private String TEMPLATE_CONFIG_XML = "xml/config.xml";
     78    /** The first of two patterns used during tokenization, this pattern handles a comma separated list. */
     79    static final private String TOKENIZER_PATTERN1 = " ,\n\t";
     80    /** The second of two patterns used during tokenization, this pattern handles an underscore separated list. */
     81    static final private String TOKENIZER_PATTERN2 = "_\n\t";
     82
    5883    public File exec_file;
    5984    /** The path (or url) to the webserver which is serving the Greenstone collection. */
     
    78103    private int cache_miss = 0;
    79104    public URL exec_address = null;
    80     /** The string identifying an argument's name attribute. */
    81     static final private String ARGUMENT_NAME = "name";
    82     /** The name of the general Gatherer configuration file. */
    83     static final private String CONFIG_XML = "config.xml";
    84     /** The name of the root element of the subtree containing gatherer configuration options. This is required as the document itself may contain several other subtrees of settings (such as in the case of a '.col' file). */
    85     static final private String GATHERER_CONFIG = "GathererConfig";
    86     /** The string identifying an argument element. */
    87     static final private String GATHERER_CONFIG_ARGUMENT = "Argument";
    88     /** The name of a Name Element. */
    89     static final private String NAME = "Name";
    90     /** The name of the other arguments element. */
    91     static final private String OTHER = "Other";
    92     /** The name of an information Element within the Other subtree. */
    93     static final private String OTHER_INFO = "Info";
    94     /** The name of the general Gatherer configuration template. */
    95     static final private String TEMPLATE_CONFIG_XML = "xml/config.xml";
    96     /** The first of two patterns used during tokenization, this pattern handles a comma separated list. */
    97     static final private String TOKENIZER_PATTERN1 = " ,\n\t";
    98     /** The second of two patterns used during tokenization, this pattern handles an underscore separated list. */
    99     static final private String TOKENIZER_PATTERN2 = "_\n\t";
     105
    100106    /** Constructor.
    101107     * @param gsdl_path The path to the Greenstone directory as a <strong>String</strong>.
     
    356362    try {
    357363        String raw = getString(property, general);
    358                 // Locale is a underscore separated code.
     364        // Locale is a underscore separated code.
    359365        StringTokenizer tokenizer = new StringTokenizer(raw, TOKENIZER_PATTERN2);
    360366        String language = tokenizer.nextToken();
    361         String country = tokenizer.nextToken();
    362         result = new Locale(language, country);
     367        if(tokenizer.hasMoreTokens()) {
     368        String country = tokenizer.nextToken();
     369        result = new Locale(language, country);
     370        }
     371        else {
     372        result = new Locale(language);
     373        }
    363374    }
    364375    catch(Exception error) {
     
    433444    /** Set the named property, from the specified configuration, using the given boolean value. */
    434445    public void set(String property, boolean general, boolean value) {
     446    if(property.startsWith("workflow")) {
     447        System.err.println("Set property: " + property + ", general=" + general + ", value=" + value);
     448    }
    435449    setString(property, general, (value ? "true" : "false"));
    436450    }
     
    537551    StringBuffer text = new StringBuffer("");
    538552    text.append(value.getLanguage());
    539     text.append("_");
    540     text.append(value.getCountry());
     553    String country = value.getCountry();
     554    if(country != null && country.length() > 0) {
     555        text.append("_");
     556        text.append(country);
     557    }
     558    country = null;
    541559    setString(property, general, text.toString());
    542560    }
     
    544562    /** Sets the value of the named property argument using the given string. */
    545563    public void setString(String property, boolean general, String value) {
    546     ///atherer.println("Set configuration property: " + property + " = " + value + (general ? "" : " [Collection]"));
     564    Gatherer.println("Set configuration property: " + property + " = " + value + (general ? "" : " [Collection]"));
    547565    try {
    548566        Document document = null;
     
    615633    UIManager.put("CheckBox.background", new ColorUIResource(getColor("coloring.collection_heading_background", false)));
    616634
     635
    617636    // Editable coloring
    618637    UIManager.put("ComboBox.background", new ColorUIResource(getColor("coloring.collection_tree_background", false))); // Indicate clickable
     
    624643    UIManager.put("Table.background", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
    625644    UIManager.put("List.background", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
     645    UIManager.put("RadioButton.background", new ColorUIResource(getColor("coloring.collection_tree_background", false)));
     646
    626647    // Selection color
    627648    UIManager.put("TabbedPane.selected", new ColorUIResource(getColor("coloring.collection_selection_background", false)));
  • trunk/gli/src/org/greenstone/gatherer/Dictionary.java

    r4928 r5164  
    103103    // Load new dictionary
    104104    dictionary = ResourceBundle.getBundle(Utility.DICTIONARY, locale);
     105    language = dictionary.getString("Language");
     106    System.err.println("Having loaded new dictionary: " + language);
    105107    // Refresh all registered component
     108    System.err.println("Updating components");
    106109    for(Iterator keys = keySet().iterator(); keys.hasNext(); ) {
    107110        Object component = keys.next();
  • trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r5083 r5164  
    5454import org.greenstone.gatherer.gui.GUIManager;
    5555import org.greenstone.gatherer.gui.Splash;
     56import org.greenstone.gatherer.gui.URLField;
    5657import org.greenstone.gatherer.gui.WarningDialog;
    5758import org.greenstone.gatherer.msm.MetadataSetManager;
     
    8182public class Gatherer {
    8283
    83     static final private String SKIN_DEFINITION_FILE = "lib/greenaqua/greenaqua.xml";
     84    static final private String SKIN_DEFINITION_FILE = "lib/greenaqua/greenaqua.xml";
    8485
    8586    /** Has the exit flag been set? <i>true</i> if so, <i>false</i> otherwise. */
     
    128129      map.removeKeyStrokeBinding(enter);
    129130    }
    130 
    131 
    132131
    133132    /** Constructor. Make the three main modules, c_man, f_man and g_man, and any other necessary classes such as Dictionary.
     
    597596    WarningDialog dialog = new WarningDialog("warning.MissingEXEC", "general.exec_address", dictionary);
    598597    //NoSettingDialog dialog = new NoSettingDialog("warning.MissingEXEC", "NoSettingEXEC.Message", false, dictionary);
     598    dialog.setValueField(new URLField(Gatherer.config.getColor("coloring.editable_foreground", false), Gatherer.config.getColor("coloring.editable_background", false), Gatherer.config.getColor("coloring.error_foreground", false), Gatherer.config.getColor("coloring.error_background", false)));
    599599    dialog.display();
    600600    dialog.dispose();
  • trunk/gli/src/org/greenstone/gatherer/cdm/Argument.java

    r4932 r5164  
    205205        ElementWrapper element_wrapper = Gatherer.c_man.getCollection().msm.getElement(value);
    206206        if(element_wrapper != null) {
    207             value = element_wrapper.toString();
     207            value = element_wrapper.getName();
    208208        }
    209209        }
  • trunk/gli/src/org/greenstone/gatherer/cdm/ArgumentConfiguration.java

    r4932 r5164  
    587587            return true;
    588588        case Argument.METADATUM:
     589            argument.setValue(((ElementWrapper)((JComboBox)value).getSelectedItem()).getName());
     590            // Kinda lucked out here. Its impossible not to choose an entry from these comboboxes as they are restricted.
     591            return true;
    589592        case Argument.HIERARCHY:
    590593            argument.setValue(((JComboBox)value).getSelectedItem().toString());
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java

    r5087 r5164  
    349349    public Element getBeta() {
    350350    Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_BETA_ELEMENT, null, null);
     351    element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_BETA_STR);
    351352    element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR);
    352353    return element;
     
    355356    public Element getCreator() {
    356357    Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_CREATOR_ELEMENT, null, null);
     358    element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_CREATOR_STR);
    357359    element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR);
    358360    return element;
     
    378380    public Element getMaintainer() {
    379381    Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_MAINTAINER_ELEMENT, null, null);
     382    element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_MAINTAINER_STR);
    380383    element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR);
    381384    return element;
     
    393396    public Element getPublic() {
    394397    Element element = getOrCreateElementByTagName(COLLECTIONMETADATA_PUBLIC_ELEMENT, null, null);
     398    element.setAttribute(NAME_ATTRIBUTE, COLLECTIONMETADATA_PUBLIC_STR);
    395399    element.setAttribute(SPECIAL_ATTRIBUTE, TRUE_STR);
    396400    return element;
     
    581585    // Create the element
    582586    Element element = document.createElement(name);
     587    // If there was a property set it
     588    if(conditional_attribute != null) {
     589        element.setAttribute(conditional_attribute, required_value);
     590    }
    583591    Node target_node = findInsertionPoint(element);
    584592    if(target_node != null) {
     
    743751        text.append(name_str);
    744752        text.append(SPACE_CHARACTER);
    745         }
    746         String language_str = command_element.getAttribute(LANGUAGE_ATTRIBUTE);
    747         // If this is element is in english, and it is the first one found, we don't need to write the language argument.
    748         if(!language_str.equals(ENGLISH_LANGUAGE_STR) || known_metadata == null || known_metadata.contains(name_str)) {
    749         text.append(LBRACKET_CHARACTER);
    750         text.append(LANGUAGE_ARGUMENT);
    751         text.append(language_str);
    752         text.append(RBRACKET_CHARACTER);
    753         text.append(SPACE_CHARACTER);
    754         }
    755         if(known_metadata != null) {
    756         known_metadata.add(name_str);
    757         }
    758         language_str = null;
     753        String language_str = command_element.getAttribute(LANGUAGE_ATTRIBUTE);
     754        // If this is element is in english, and it is the first one found, we don't need to write the language argument.
     755        if(!language_str.equals(ENGLISH_LANGUAGE_STR) || known_metadata == null || known_metadata.contains(name_str)) {
     756            text.append(LBRACKET_CHARACTER);
     757            text.append(LANGUAGE_ARGUMENT);
     758            text.append(language_str);
     759            text.append(RBRACKET_CHARACTER);
     760            text.append(SPACE_CHARACTER);
     761        }
     762        if(known_metadata != null) {
     763            known_metadata.add(name_str);
     764        }
     765        language_str = null;
     766        }
    759767        name_str = null;
    760768        // We don't wrap the email addresses in quotes, nor any string without spaces
     
    11291137            command_element.setAttribute(NAME_ATTRIBUTE, name_str);
    11301138            command_element.setAttribute(LANGUAGE_ATTRIBUTE, language_str);
    1131             MSMUtils.setValue(command_element, value_str);
     1139            MSMUtils.setValue(command_element, Utility.encodeXML(value_str));
    11321140        }
    11331141        else {
     
    11821190    private Element parsePlugIn(String command_str) {
    11831191    Element command_element = null;
     1192    boolean use_metadata_files = false;
    11841193    try {
    11851194        CommandTokenizer tokenizer = new CommandTokenizer(command_str);
     
    11901199        tokenizer.nextToken();
    11911200        // The next token is the type
    1192         command_element.setAttribute(TYPE_ATTRIBUTE, tokenizer.nextToken());
     1201        String type = tokenizer.nextToken();
     1202        command_element.setAttribute(TYPE_ATTRIBUTE, type);
    11931203        // Now we parse out the remaining arguments into a hashmapping from name to value
    11941204        HashMap arguments = parseArguments(tokenizer);
     
    11991209            String value = (String) arguments.get(name); // Can be null
    12001210            Element option_element = document.createElement(OPTION_ELEMENT);
     1211            if(name.substring(1).equals(USE_METADATA_FILES_ARGUMENT)) {
     1212            use_metadata_files = true;
     1213            }
    12011214            option_element.setAttribute(NAME_ATTRIBUTE, name.substring(1));
    12021215            option_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
     
    12161229            value = null;
    12171230        }
     1231        // Finally if the type happened to be a RecPlug we ensure that the use metadata files argument is set
     1232        if(type.equals(RECPLUG_STR) && !use_metadata_files) {
     1233            Element option_element = document.createElement(OPTION_ELEMENT);
     1234            option_element.setAttribute(NAME_ATTRIBUTE, USE_METADATA_FILES_ARGUMENT);
     1235            option_element.setAttribute(ASSIGNED_ATTRIBUTE, TRUE_STR);
     1236            option_element.setAttribute(CUSTOM_ATTRIBUTE, TRUE_STR);
     1237            command_element.appendChild(option_element);
     1238            option_element = null;
     1239        }
     1240        type = null;
    12181241        names = null;
    12191242        arguments = null;
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMetaManager.java

    r4932 r5164  
    106106
    107107    public CollectionMeta getMetadatum(String name, boolean add_if_not_found) {
    108     ///atherer.println("Get the metadata for " + name + " in the default language.");
     108    //Gatherer.println("Get the metadata for " + name + " in the default language.");
    109109    int size = getSize();
    110110    for(int i = 0; i < size; i++) {
    111111        CollectionMeta metadatum = (CollectionMeta) getElementAt(i);
    112112        if(metadatum.getName().equals(name) && metadatum.getLanguage().equals(Gatherer.config.interface_language)) {
    113         ///atherer.println("Found '" + metadatum + "'");
     113        //Gatherer.println("Found '" + metadatum + "'");
    114114        return metadatum;
    115115        }
    116116        else {
    117         ///atherer.println("No match with: " + metadatum.getName() + " [l=" + metadatum.getLanguage() + "] \"" + metadatum.getValue() + "\"");
     117        //Gatherer.println("No match with: " + metadatum.getName() + " [l=" + metadatum.getLanguage() + "] \"" + metadatum.getValue() + "\"");
    118118        }
    119119        metadatum = null;
     
    122122        CollectionMeta result = new CollectionMeta(name);
    123123        addMetadatum(result);
    124         ///atherer.println("Added new metadata.");
     124        //Gatherer.println("Added new metadata.");
    125125        return result;
    126126    }
  • trunk/gli/src/org/greenstone/gatherer/cdm/FormatManager.java

    r5090 r5164  
    216216        Vector elements = Gatherer.c_man.getCollection().msm.getAssignedElements();
    217217        for(int i = 0; i < elements.size(); i++) {
    218         special_model.add("[" + ((ElementWrapper)elements.get(i)).toString() + "]");
     218        special_model.add("[" + ((ElementWrapper)elements.get(i)).getName() + "]");
    219219        }
    220220        Collections.sort(special_model);
  • trunk/gli/src/org/greenstone/gatherer/collection/Collection.java

    r4675 r5164  
    128128        mapping_element = null;
    129129        }
    130                 // Otherwise add the mapping.
     130        // Otherwise add the mapping.
    131131        if(!found) {
    132132        Element mapping_element = document.createElement(MAPPING);
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r5076 r5164  
    7070import org.greenstone.gatherer.util.GSDLSiteConfig;
    7171import org.greenstone.gatherer.util.MetadataXML;
     72import org.greenstone.gatherer.util.StaticStrings;
    7273import org.greenstone.gatherer.util.SynchronizedTreeModelTools;
    7374import org.greenstone.gatherer.util.Utility;
     
    197198    Gatherer.g_man.collectionChanged(false);
    198199    ///ystem.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;
     200    // All of the consequences of a close should have been processed by now, so others should now see the collection as non-ready.
     201    closing_thread = null;
    201202    }
    202203
     
    226227        progress.setProgress(1);
    227228
    228         // ACTIVE_DIR/gimport/
    229229        String a_dir = Utility.getCollectionDir(Gatherer.config.gsdl_path) + name + File.separator;
    230 
    231         // Has to be done before creating greenstone directory metadata manager.
    232         File gimport_dir_temp = new File(Utility.getImportDir(a_dir)+"temp.dat");
    233         File gimport_dir = gimport_dir_temp.getParentFile();
    234         gimport_dir.mkdirs();
    235         if(progress != null) {
    236         progress.setNote(get("Gimport_Created"));
    237         }
    238230
    239231        // ACTIVE_DIR/gcache/
     
    260252        msm = collection.msm; // Legacy
    261253        collection.msm.load();
     254        // Always import the extracted metadata set
     255        collection.msm.importMDS(new File(Utility.METADATA_DIR + Utility.EXTRACTED_METADATA_NAMESPACE + StaticStrings.METADATA_SET_EXTENSION), false);
    262256        // Import default metadata sets if any.
    263257        for(int i = 0; metadata_sets != null && i < metadata_sets.size(); i++) {
     
    360354            // Find the import directory
    361355            File base_import = new File(base_collection_directory, Utility.IMPORT_DIR);
    362             if(!base_import.exists()) {
    363                 base_import = new File(base_collection_directory, Utility.OLD_IMPORT_DIR);
    364             }
    365356            if(base_import.exists()) {
    366357                searchForMetadata(base_import);
     
    536527    return Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator + collection.getName() + ".col";
    537528    }
    538     /** Constructs the absolute filename of the collection import directory, which should resemble "$GSDLHOME/collect/&lt;col_name&gt;/gimport/"
     529    /** Constructs the absolute filename of the collection import directory, which should resemble "$GSDLHOME/collect/&lt;col_name&gt;/import/"
    539530      * @return A <strong>String</strong> containing the filename.
    540531      * @see org.greenstone.gatherer.Configuration
     
    577568    }
    578569
    579     public String getCollectionOldImport() {
    580     return Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator + Utility.OLD_IMPORT_DIR;
    581     }
    582 
    583570    /** This method either returns the title of the current collection, or a placeholder string of 'No Collection'.
    584571      * @return A <strong>String</strong> which represents what we wish to display for a collection title.
     
    595582    public TreeModel getRecordSet() {
    596583    if(collection_model == null && collection != null) {
    597         // Check if the gimport directory exists, and if so use it.
    598         File gimport_directory = new File(getCollectionImport());
    599         if(gimport_directory.exists()) {
    600         // Generate a new FileSystemModel based on the collection gimport directory.
    601         collection_model = new FileSystemModel(new FileNode(gimport_directory, false));
    602         }
    603         else {
    604         ///ystem.err.println("No gimport directory exists.");
    605         // Otherwise default to the import directory. If it doesn't exist, there aint much more I can do.
    606         // Generate a new FileSystemModel based on the collection import directory.
    607         collection_model = new FileSystemModel(new FileNode(new File(getCollectionOldImport()), false));
    608         }
     584        // Use the import directory to generate a new FileSystemModel
     585        collection_model = new FileSystemModel(new FileNode(new File(getCollectionImport()), false));
    609586        // Ensure that the manager is a change listener for the tree.
    610587        if(fm_tree_model_listener == null) {
     
    661638    // If mirroring is enabled show the public and private caches.
    662639    if(Gatherer.config.get("workflow.mirror", false)) {
    663                 // Add Public workspace
     640        // Add Public workspace
    664641        FileNode public_root = new FileNode(new File(Utility.CACHE_DIR), get("Tree.Public"));
    665642        workspace_root.insert(public_root);
    666                 // Add Private workspace if a collection has been loaded.
     643        // Add Private workspace if a collection has been loaded.
    667644        if(ready()) {
    668645        FileNode private_root = new FileNode(new File(getCollectionCache()), get("Tree.Private"));
     
    973950    }
    974951    }
     952
     953    /** Refresh the Greenstone Collections special mapping in the workspace tree to account for collections being added/removed
     954     */
     955    public void refreshGreenstoneCollections() {
     956    FileNode root = (FileNode) workspace_model.getRoot();
     957    FileNode greenstone_collections_node = null;
     958    int root_child_count = root.getChildCount();
     959    String greenstone_collections_str = get("Tree.World");
     960    for(int i = 0; greenstone_collections_node == null && i < root_child_count; i++) {
     961        TreeNode child = root.getChildAt(i);
     962        if(child.toString().equals(greenstone_collections_str)) {
     963        greenstone_collections_node = (FileNode) child;
     964        }
     965        child = null;
     966    }
     967    greenstone_collections_str = null;
     968    root = null;
     969    if(greenstone_collections_node != null) {
     970        TreePath greenstone_collections_path = new TreePath(greenstone_collections_node.getPath());
     971        workspace_model.refresh(greenstone_collections_path);
     972        greenstone_collections_path = null;
     973        greenstone_collections_node = null;
     974    }
     975    }
     976
    975977    /** Called to refresh the models upon which the trees are based.
    976978     * @see org.greenstone.gatherer.collection.Collection
  • trunk/gli/src/org/greenstone/gatherer/file/FileNode.java

    r4851 r5164  
    1010import org.greenstone.gatherer.file.FileSystemModel;
    1111import org.greenstone.gatherer.util.ArrayTools;
     12import org.greenstone.gatherer.util.StaticStrings;
    1213import org.greenstone.gatherer.util.Utility;
    1314
     
    242243        File cols[] = start.listFiles();
    243244        ArrayTools.sort(cols);
    244         // We add their import and gimport directories, but only if its not our current collection.
     245        // We add their import directories, but only if its not our current collection, nor the model collection.
    245246        for(int i = 0; cols != null && i < cols.length; i++) {
    246             if(!cols[i].getName().equals("modelcol") && (!Gatherer.c_man.ready() || !Gatherer.c_man.getCollectionDirectory().equals(cols[i].getAbsolutePath()))) {
     247            if(!cols[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME) && (!Gatherer.c_man.ready() || !Gatherer.c_man.getCollectionDirectory().equals(cols[i].getAbsolutePath()))) {
    247248            File dirs[] = cols[i].listFiles();
    248249            ArrayTools.sort(dirs);
    249             File import_dir = new File(cols[i], "gimport");
    250             if(!import_dir.exists()) {
    251                 import_dir = new File(cols[i], "import");
    252             }
     250            File import_dir = new File(cols[i], StaticStrings.IMPORT_FOLDER);
    253251            if(import_dir.exists()) {
    254252                FileNode collection_root = new FileNode(import_dir, cols[i].getName(), true);
     
    290288            }
    291289            // Finally remove any files whose canonical path do not match their absolute one (ie symbolic links). We only do this test under linux, because under windows there is no such thing as a symbolic link, and instead we suffer difficulties with the 16bit truncated file paths not being the same as the canonical ones (i.e Program Files => Progra~1).
     290            /* This test to eliminate infinite recursions causes more problems than it solves
    292291            if(!Utility.isWindows()) {
    293292            for(int k = files.length; k != 0; k--) {
     
    305304            }
    306305            }
     306            */
    307307            // Sort the remaining files.
    308308            tools.sort(files, true);
  • trunk/gli/src/org/greenstone/gatherer/file/FileSystemModel.java

    r5057 r5164  
    100100    // If no path is set, take the path to the root node (ie update the whole tree)
    101101    if(path == null) {
    102                 ///ystem.err.println("Refresh entire tree.");
     102        System.err.println("Refresh entire tree.");
    103103        path = new TreePath(((FileNode)root).getPath());
    104104    }
    105105    else {
    106                 ///ystem.err.println("Refresh: " + path.getLastPathComponent());
     106        System.err.println("Refresh: " + path.getLastPathComponent());
    107107    }
    108108    // Only a valid action if this model is currently being displayed in a tree.
    109109    if(tree != null) {
    110                 // Retrieve the error node.
     110        // Retrieve the error node.
    111111        FileNode node = (FileNode) path.getLastPathComponent();
    112                 // If this error node is a dummy node (ie has no associated file) we can't unmap it, so we iterate through its children refreshing each in turn.
    113         if(node.getFile() == null) {
     112        // If this error node is a dummy node (ie has no associated file) we can't unmap it, so we iterate through its children refreshing each in turn. The exception being Greenstone Collections, as it is a dummy node but we can map/unmap it
     113        if(node.getFile() == null && !node.toString().equals(Gatherer.dictionary.get("Tree.World"))) {
    114114        for(int i = 0; i < node.getChildCount(); i++) {
    115115            FileNode child = (FileNode) node.getChildAt(i);
     
    118118        }
    119119        }
    120                 // Otherwise we refresh this node.
     120        // Otherwise we refresh this node.
    121121        else {
    122122        // Record all of the expanded paths under this node. How come getExpandedDescendants returns more results each time.
     
    181181    }
    182182    else {
    183                 ///ystem.err.println("No Tree!");
     183        ///ystem.err.println("No Tree!");
    184184    }
    185185    }
  • trunk/gli/src/org/greenstone/gatherer/gui/CreatePane.java

    r5033 r5164  
    5454import org.greenstone.gatherer.shell.GShellListener;
    5555import org.greenstone.gatherer.shell.GShellProgressMonitor;
     56import org.greenstone.gatherer.util.AppendLineOnlyFileDocument;
    5657/** This class provides a GUI view showing some statistics on your current collection, and options for building it. As the collection is built this initial view is replaced with one showing progress bars and a message log of the creation process. This log can be later accessed via the options tree located in the center of the initial pane. This class is also responsible for creating the GShellProgressMonitors that are then attatched to external shell processes, and calling the methods in the CollectionManager for actually importing and building the collection. <br><BR>
    5758 * <center><table width=80% border=2 cellspacing=0 cellpadding=2><tr><td align=center colspan=4>
     
    8889    /** The options pane generates all the various option sheet configuations. */
    8990    public OptionsPane options_pane = null;
     91    private AppendLineOnlyFileDocument document;
    9092    /** A card layout is used to store the separate configuration and progress panes. */
    9193    private CardLayout card_layout = null;
     
    121123    private JScrollPane scroll_pane;
    122124    /** The message log for the entire session. */
    123     private JTextArea message_log;
     125    private JTextArea log_textarea;
    124126    /** A tree used to display the currently available option views. */
    125127    private OptionTree tree = null;
     
    148150    public CreatePane() {
    149151    Collection collection = Gatherer.c_man.getCollection();
    150     message_log = new JTextArea();
     152    log_textarea = new JTextArea();
    151153
    152154    // Create components
     
    210212    ///ystem.err.println("Collection changed... ");
    211213    if(Gatherer.c_man != null && ready) {
    212         ///ystem.out.println("create coll changed");
    213         if (!processing && this.options_pane != null) {
    214         // we only do this if we are not processing - if we are processing, then we haven't added the new entry yet, and it will be added by another method
    215         this.options_pane.resetLogList(); // saves any residual message
    216         }
    217214        Collection current_collection = Gatherer.c_man.getCollection();
    218215        if (current_collection != previous_collection) {
    219         message_log.setText(null);
    220         this.options_pane = new OptionsPane(message_log, current_collection.build_options);
     216        this.options_pane = new OptionsPane(current_collection.build_options);
    221217        previous_collection = current_collection;
    222218        }
     
    280276    progress_pane.setLayout(new BorderLayout());
    281277    progress_pane.add(bar_area, BorderLayout.NORTH);
    282     progress_pane.add(new JScrollPane(message_log), BorderLayout.CENTER);
     278    progress_pane.add(new JScrollPane(log_textarea), BorderLayout.CENTER);
    283279
    284280    // Main pane
     
    340336     */
    341337    public synchronized void message(GShellEvent event) {
    342     final String text = event.getMessage();
    343     ///ystem.err.println("Recieved message: " + event.getMessage());
    344     SwingUtilities.invokeLater(new Runnable() {
    345         public void run() {
    346             message_log.append(text);
    347         }
    348         });
    349     }
     338    document.appendLine(event.getMessage());
     339    }
     340
    350341    /** All implementation of GShellListener must include this method so the listener can be informed when a GShell begins its task. Implementation side-effect, not actually used.
    351342      * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
     
    364355        int status = event.getStatus();
    365356        if (status == GShell.OK) {
    366         options_pane.addNewLog(OptionsPane.SUCCESSFUL);
     357        document.setSpecialCharacter(OptionsPane.SUCCESSFUL);
    367358        } else {
    368         options_pane.addNewLog(OptionsPane.UNSUCCESSFUL);
    369         }
     359        document.setSpecialCharacter(OptionsPane.UNSUCCESSFUL);
     360        }
     361        options_pane.resetFileEntry();
    370362        card_layout.show(main_pane, CONTROL);
    371363    }
     
    407399        build_button.setEnabled(false);
    408400        cancel_button.setEnabled(true);
    409         // clear the log list and message_log
    410         options_pane.resetLogList();
     401        // Create a new log document and assign it to the two textareas
     402        document = options_pane.createNewLogDocument();
     403        log_textarea.setDocument(document);
     404        options_pane.log_textarea.setDocument(document);
    411405        // Change the view.
    412406        processing = true;
     
    438432        cancel_button.setEnabled(false);
    439433        processing = false;
    440         options_pane.addNewLog(OptionsPane.CANCELLED);
     434        document.setSpecialCharacter(OptionsPane.CANCELLED);
    441435        card_layout.show(main_pane, CONTROL);
    442         // Set the stop flag in all the process monitor.
     436        // Set the stop flag in all the process monitor.
    443437        build_monitor.setStop(true);
    444438        copy_monitor.setStop(true);
    445439        import_monitor.setStop(true);
    446         // Set removeold automatically.
     440        // Set removeold automatically.
    447441        Gatherer.c_man.getCollection().build_options.setImportValue("removeold", true, null);
    448         // Remove the collection lock.
     442        // Remove the collection lock.
    449443        //Gatherer.g_man.lockCollection(false, false);
    450444    }
  • trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionDetailsPrompt.java

    r4803 r5164  
    2121    private JComboBox base_collection;
    2222    private JDialog self;
     23    private JRadioButton hide_extracted_metadata_radio_button;
     24    private JRadioButton view_extracted_metadata_radio_button;
    2325    private JTextArea description;
    2426    private JTextField address;
     
    5961        String collection_name = collect_cfg.getName();
    6062        // Even if there is no metadata directory we add it if its one of the 'big five + 1' that we know how to handle.
    61         if(metadata_directory.exists() || collection_name.equals(Utility.COLLECTION_DLS) || collection_name.equals(Utility.COLLECTION_DEMO)) { /** @todo - the other big five */
     63        if(metadata_directory.exists() || collection_name.equals(Utility.COLLECTION_DLS) || collection_name.equals(Utility.COLLECTION_DEMO)) {
    6264            // Add to model.
    6365            Item item = new Item(possible_collections[i], collection_name);
     
    123125    JButton base_collection_browse = new JButton(get("General.Browse"));
    124126
     127    JPanel extracted_metadata_pane = new JPanel();
     128    ButtonGroup extracted_metadata_button_group = new ButtonGroup();
     129    view_extracted_metadata_radio_button = new JRadioButton(get("View_Extracted_Metadata"));
     130    view_extracted_metadata_radio_button.setOpaque(false);
     131    extracted_metadata_button_group.add(view_extracted_metadata_radio_button);
     132    hide_extracted_metadata_radio_button = new JRadioButton(get("Hide_Extracted_Metadata"));
     133    hide_extracted_metadata_radio_button.setOpaque(false);
     134    extracted_metadata_button_group.add(hide_extracted_metadata_radio_button);
     135    view_extracted_metadata_radio_button.setSelected(true);
     136
    125137    JPanel button_pane = new JPanel();
    126138    button_pane.setOpaque(false);
     
    182194    description_pane.add(new JScrollPane(description), BorderLayout.CENTER);
    183195
     196    extracted_metadata_pane.setLayout(new GridLayout(1,2,5,0));
     197    extracted_metadata_pane.add(view_extracted_metadata_radio_button);
     198    extracted_metadata_pane.add(hide_extracted_metadata_radio_button);
     199
     200    base_collection_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
    184201    base_collection_pane.setLayout(new BorderLayout());
    185202    base_collection_pane.add(base_collection_label, BorderLayout.NORTH);
     
    192209         
    193210    bottom_pane.setLayout(new BorderLayout());
     211    bottom_pane.add(extracted_metadata_pane, BorderLayout.NORTH);
    194212    bottom_pane.add(base_collection_pane, BorderLayout.CENTER);
    195213    bottom_pane.add(button_pane, BorderLayout.SOUTH);
     
    233251    public String getTitle() {
    234252    return title_final;
     253    }
     254
     255    public boolean viewExtractedMetadata() {
     256    return view_extracted_metadata_radio_button.isSelected();
    235257    }
    236258
     
    302324    implements ActionListener {
    303325    public void actionPerformed(ActionEvent event) {
    304                 // Validate.
     326        // Validate.
    305327        title_final = title.getText();
    306328        if(title_final.length() == 0) {
     
    362384        }
    363385        description_final = Utility.encodeGreenstone(description_final);
    364                 // If we got this far there are no errors.
     386        // If we got this far there are no errors.
    365387        Item item_final = (Item) base_collection.getSelectedItem();
    366388        base_final = item_final.getFile();
  • trunk/gli/src/org/greenstone/gatherer/gui/OpenCollectionDialog.java

    r4686 r5164  
    216216                // Retrieve the files usually returned by the platform specific file system view.
    217217        File[] files = default_system_view.getFiles(dir, useFileHiding);
    218                 // Determine if the current dir actually contains a valid greenstone collection. To do this we check for the presence of the file <dir>/etc/collect.cfg and a directory named import or gimport.
     218                // Determine if the current dir actually contains a valid greenstone collection. To do this we check for the presence of the file <dir>/etc/collect.cfg and a directory named import.
    219219        File collect_cfg_file = new File(dir, Utility.CONFIG_DIR);
    220         File import_dir_file = new File(dir, Utility.OLD_IMPORT_DIR);
    221         File gimport_dir_file = new File(dir, Utility.IMPORT_DIR);
    222         if(collect_cfg_file.exists() && (gimport_dir_file.exists() || import_dir_file.exists())) {
     220        File import_dir_file = new File(dir, Utility.IMPORT_DIR);
     221        if(collect_cfg_file.exists() && import_dir_file.exists()) {
    223222        // Create a new dummy collection file.
    224223        String name = dir.getName();
     
    235234        name = null;
    236235        }
    237         gimport_dir_file = null;
    238236        import_dir_file = null;
    239237        collect_cfg_file = null;
  • trunk/gli/src/org/greenstone/gatherer/gui/OptionsPane.java

    r5033 r5164  
    4242import javax.swing.*;
    4343import javax.swing.event.*;
     44import javax.swing.text.*;
    4445import org.greenstone.gatherer.Gatherer;
    4546import org.greenstone.gatherer.cdm.Argument;
     
    4950import org.greenstone.gatherer.collection.CollectionManager;
    5051import org.greenstone.gatherer.msm.ElementWrapper;
     52import org.greenstone.gatherer.util.AppendLineOnlyFileDocument;
     53import org.greenstone.gatherer.util.AppendLineOnlyFileDocumentOwner;
    5154import org.greenstone.gatherer.util.Utility;
    5255//import org.w3c.dom.*;
     
    5558 * @version 2.2
    5659 */
    57 final public class OptionsPane
    58     extends JPanel {
     60public class OptionsPane
     61    extends JPanel
     62    implements AppendLineOnlyFileDocumentOwner {
     63
     64    static final public char SUCCESSFUL = 's';
     65    static final public char UNSUCCESSFUL = 'u';
     66    static final public char CANCELLED = 'c';
     67    static final public char UNKNOWN = 'x';
     68
     69    /** All process messages are written to this log text area. */
     70    public JTextArea log_textarea = null;
     71
    5972    /** The <strong>BuildOptions</strong> data object contains all the option settings we wish to persist between Gatherer sessions (and thus is stored in <strong>Collection</strong>). */
    6073    private BuildOptions build_options = null;
     74
     75    private FileEntry file_entry = null;
    6176    /** the log pane - we only create it once now, not each time */
    6277    private JPanel log_pane = null;
    6378    /** the list of previous log messages */
    6479    private JList log_list = null;
    65     /** whether that currently showing log is changed or not */
    66     private boolean is_log_changed = false;
    67     /** the list entry that is currently displayed */
    68     private FileEntry displayed_log = null;
    69     /** a listener for changes in the log text */
    70     private LogChangeListener log_change_listener = null;
    71     /** All process messages are written to this log text area. */
    72     private JTextArea log_display = null;
    73 
    74     static final public char SUCCESSFUL = 's';
    75     static final public char UNSUCCESSFUL = 'u';
    76     static final public char CANCELLED = 'c';
     80    private Vector writing_documents;
    7781
    7882    static private int BUILD = 0;
     
    8892
    8993     /** The default constructor creates the few session length options, but either retrieves the rest from the current collection, or creates a default set of options. */
    90     public OptionsPane(JTextArea message_log, BuildOptions build_options) {
    91     this.log_display = new JTextArea(message_log.getDocument());
     94    public OptionsPane(BuildOptions build_options) {
    9295    this.build_options = build_options;
    93     this.log_change_listener = new LogChangeListener();
    94     //this.target_pane = target_pane;
    95     }
    96 
    97     /** creates a new log from the text in log. The new file is named
    98      * build_log.<current time>.txt. A new FileEntry is added to teh log list
    99      * and made selected. A fresh listener is added to teh document */
    100     public void addNewLog(char success) {
    101     ///ystem.out.println("add new log");
    102 
    103     // create the file name
    104     long time = System.currentTimeMillis();
    105     StringBuffer name = new StringBuffer();
    106     name.append("build_log.");
    107     name.append(time);
    108     name.append(success);
    109     name.append(".txt");
    110     File f = new File(Gatherer.c_man.getCollectionLog()+name.toString());
    111     // just in case there is no log directory
    112     File parent_file = f.getParentFile();
    113     parent_file.mkdirs();
    114 
    115     // save the log text to the file
    116     saveLogFile(f);
    117     is_log_changed=false;
    118     log_display.getDocument().addDocumentListener(log_change_listener);
    119 
    120     // create the file entry and add it to the list at pos 0 - it will always be the newest one created
    121     FileEntry fe = new FileEntry(f);
    122     ((DefaultListModel)log_list.getModel()).add(0, fe);
    123     log_list.setSelectedIndex(0);
    124     displayed_log = fe;
    125 
     96    this.writing_documents = new Vector();
     97
     98    // Have to do this here, not in display, as the message log view may not have been displayed yet.
     99    log_textarea = new JTextArea();
     100    log_textarea.setEditable(false);
    126101    }
    127102
     
    134109    pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    135110    int build_argument_count = build_options.getBuildArgumentCount();
    136     pane.setLayout(new GridLayout(build_argument_count, 1, 0, 0));
    137     int total_height = PANE_SIZE.height;
     111    pane.setPreferredSize(new Dimension(ROW_SIZE.width, ROW_SIZE.height * build_argument_count));
    138112    for(int i = 0; i < build_argument_count; i++) {
    139113        // Retrieve the argument so we know how to format the control.
     
    143117        String value = build_options.getBuildValue(argument.getName());
    144118        ArgumentControl argument_control = new ArgumentControl(BUILD, argument, enabled, value);
    145         total_height = total_height - argument_control.getPreferredSize().height;
    146119        pane.add(argument_control);
    147     }
    148     if(total_height > 0) {
    149         JPanel filler = new JPanel();
    150         filler.setPreferredSize(new Dimension(100, total_height));
    151         filler.setSize(filler.getPreferredSize());
    152         pane.add(filler);
    153120    }
    154121    return pane;
     
    162129    pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    163130    int import_argument_count = build_options.getImportArgumentCount();
    164     pane.setLayout(new GridLayout(import_argument_count, 1, 0, 0));
    165     int total_height = PANE_SIZE.height;
     131    pane.setPreferredSize(new Dimension(ROW_SIZE.width, ROW_SIZE.height * import_argument_count));
    166132    for(int i = 0; i < import_argument_count; i++) {
    167133        // Retrieve the argument so we know how to format the control.
     
    171137        String value = build_options.getImportValue(argument.getName());
    172138        ArgumentControl argument_control = new ArgumentControl(IMPORT, argument, enabled, value);
    173         total_height = total_height - argument_control.getPreferredSize().height;
    174139        pane.add(argument_control);
    175     }
    176     if(total_height > 0) {
    177         JPanel filler = new JPanel();
    178         filler.setPreferredSize(new Dimension(100, total_height));
    179         filler.setSize(filler.getPreferredSize());
    180         pane.add(filler);
    181140    }
    182141    return pane;
     
    195154        File children[] = log_directory.listFiles();
    196155        for(int i = 0; children != null && i < children.length; i++) {
    197         if(children[i].getName().startsWith("build_log")&&children[i].getName().endsWith(".txt") ) {
    198             FileEntry entry = new FileEntry(children[i]);
     156        if(children[i].getName().startsWith("build_log") && children[i].getName().endsWith(".txt") ) {
     157            FileEntry entry = new FileEntry(children[i].getName(), children[i].getAbsolutePath());
    199158            // We are about to insert it. But where.
    200159            boolean found = false;
    201             for(int j = 0; j < contents.size(); j++) {
     160            for(int j = 0; !found && j < contents.size(); j++) {
    202161            FileEntry sibling = (FileEntry) contents.getElementAt(j);
    203162            int order = entry.compareTo(sibling);
     
    205164                contents.insertElementAt(entry, j);
    206165                found = true;
    207                 break;
    208166            }
    209167            }
     
    217175        log_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    218176        log_list.setLayoutOrientation(JList.VERTICAL);
     177        log_list.setPreferredSize(new Dimension(600, 100));
    219178        log_list.setVisibleRowCount(3);
    220179        log_list.addListSelectionListener(new LogListListener());
    221180
    222         JScrollPane list_scroller = new JScrollPane(log_list);
    223 
    224         // If log is not empty and we have something in displayed_log - make that element selected
    225         if (log_display.getText().length()>0 && displayed_log != null) {
    226         int index = contents.indexOf(displayed_log);
    227         if (index != -1) {
    228             log_list.setSelectedIndex(index);
    229         }
    230 
    231         }
    232 
    233         log_pane.add(new JScrollPane(log_display), BorderLayout.CENTER);
    234181        JLabel log_history_label = new JLabel(get("LogHistory"));
    235182        JPanel log_history_pane = new JPanel();
    236 
     183        log_history_pane.setPreferredSize(new Dimension(600, 100));
    237184        log_history_pane.setLayout(new BorderLayout());
    238185        log_history_pane.add(log_history_label, BorderLayout.NORTH);
    239         log_history_pane.add(list_scroller, BorderLayout.SOUTH);
     186        log_history_pane.add(new JScrollPane(log_list), BorderLayout.CENTER);
    240187       
     188        log_pane.add(new JScrollPane(log_textarea), BorderLayout.CENTER);
    241189        log_pane.add(log_history_pane, BorderLayout.SOUTH);
    242190    }
    243191    return log_pane;
     192    }
     193
     194    public AppendLineOnlyFileDocument createNewLogDocument() {
     195    long time = System.currentTimeMillis();
     196    StringBuffer name = new StringBuffer();
     197    name.append("build_log.");
     198    name.append(time);
     199    name.append(".txt");
     200    // just in case there is no log directory
     201    File file = new File(Gatherer.c_man.getCollectionLog() + name.toString());
     202    File parent_file = file.getParentFile();
     203    parent_file.mkdirs();
     204    parent_file = null;
     205    // create the file entry and add it to the list at pos 0 - it will always be the newest one created
     206    file_entry = new FileEntry(name.toString(), file.getAbsolutePath());
     207    ((DefaultListModel)log_list.getModel()).add(0, file_entry);
     208    log_list.setSelectedIndex(0);
     209    // Finally retrieve and return the document associated with this file entry
     210    return file_entry.getDocument();
    244211    }
    245212
     
    265232    }
    266233    /** Attempts to discover the latest document count.
    267       * @return An <strong>int</strong> detailing the number of documents in this collection.
    268     */
     234     * @return An <strong>int</strong> detailing the number of documents in this collection.
     235    */
    269236    public int getDocumentCount() {
    270237    if(Gatherer.c_man.ready()) {
     
    277244    }
    278245
    279     /** Loads a new log into the log text - saves the currently showing one,
    280      * and loads the new one, adding a fresh listener to the document
    281      * Note, we need to remove any listener before making the changes, then
    282      * add a listener back in
    283      */
    284     public void loadSelectedLog(FileEntry fe) {
    285     ///ystem.out.println("load selected log");
    286     if(displayed_log != null) {
    287         if (is_log_changed) {
    288         saveLogFile(displayed_log.getFile());
    289         } else {
    290         log_display.getDocument().removeDocumentListener(log_change_listener);
    291         }
    292     }
    293 
    294     displayed_log = fe;
    295     if (fe != null) {
    296         log_display.setText(fe.getFileText());
    297     } else {
    298         log_display.setText("");
    299     }
    300     is_log_changed=false;
    301     log_display.getDocument().addDocumentListener(log_change_listener);
    302 
    303     }
    304 
    305     /** Neutralizes the log list - saves any unsaved changes to the current log
    306      * clears the log text, unselects the log list, and adds a fresh listener
    307      * to the log's document
    308      * Note, we need to remove any listener before making the changes, then
    309      * add a listener back in */
    310     public void resetLogList() {
    311     ///ystem.out.println("reset log");
    312     if (is_log_changed) {
    313         saveLogFile(displayed_log.getFile());
    314     } else {
    315         log_display.getDocument().removeDocumentListener(log_change_listener);
    316     }
    317     log_display.setText("");
    318     displayed_log = null;
    319     if (log_list != null) {
    320         log_list.clearSelection();
    321     }
    322     is_log_changed=false;
    323     log_display.getDocument().addDocumentListener(log_change_listener);
    324 
    325     }
    326 
    327     /** saves the current text in log to the File specified */
    328     public void saveLogFile(File file) {
    329 
    330     try {
    331         BufferedWriter out = new BufferedWriter(new FileWriter(file)); // uses the default encoding
    332         String log_text = log_display.getText();
    333         // set teh return delims to true, then swap them for newLine() (platform dependent) - having return delims set to false seemed to not get empty strings so that empty lines were not preserved.
    334         StringTokenizer t = new StringTokenizer(log_text, "\n", true);
    335         while (t.hasMoreTokens()) {
    336         String token = t.nextToken();
    337         if (token.equals("\n")) {
    338             out.newLine();
    339         } else {
    340             out.write(token, 0, token.length());
    341         }
    342 
    343         }
    344         out.close();
    345 
    346     } catch(Exception e) {
    347         System.out.println("Error in saving log file: "+file.toString());
    348         e.printStackTrace();
    349     }
    350 
    351 
    352     }
    353 
     246    /** Called by our magic log documents after they have finished writing themselves to file, whereapon it is no longer necessary to hold a reference to them. */
     247    public void remove(AppendLineOnlyFileDocument document) {
     248    writing_documents.remove(document);
     249    }
     250
     251    public void resetFileEntry() {
     252    if(file_entry != null) {
     253        file_entry.reset();
     254    }
     255    }
    354256
    355257    /** Given a panel containing ArgumentControls, update the values associated with them. */
     
    591493    }
    592494
    593     /** holds a File which has a particular naming convention
    594      * build_log.date.txt
    595      * also keeps a Date corresponding to the date in its name*/
     495    /** Holds a File which has a particular naming convention build_log.date.txt also keeps a Date corresponding to the date in its name*/
    596496    private class FileEntry {
    597497
    598     private Date date=null;
    599     private File file=null;
    600     private String display=null;
    601     public FileEntry(File f) {
    602         this.file=f;
    603         this.date = getDateFromFileName();
    604         this.display = createDisplayText();
    605 
     498    private Date date;
     499    private long last_modified;
     500    private String display;
     501    private String filename;
     502    private String filepath;
     503
     504    public FileEntry(String filename, String filepath) {
     505        this.date = null;
     506        this.display = null;
     507        this.filename = filename;
     508        this.filepath = filepath;
     509        this.last_modified = 0L;
    606510    }
    607511
    608512    /** returns 0 if the dates are the same, -ve number if the current FileEntry is earlier than the fe FileEntry ...*/
    609     public int compareTo(FileEntry fe) {
    610         Date d = fe.getDate();
    611         return date.compareTo(d);
     513    public int compareTo(FileEntry file_entry) {
     514        Date our_date = getDate();
     515        Date other_date = file_entry.getDate();
     516        return our_date.compareTo(other_date);
    612517    }
    613518
    614519    public Date getDate() {
    615         return this.date;
    616     }
    617     public File getFile() {
    618         return this.file;
    619     }
    620     /** returns the contents of the file */
    621     public String getFileText() {
    622         if (!this.file.exists()) {
    623         return "";
    624         }
    625         StringBuffer contents = new StringBuffer();
    626         try {
    627         BufferedReader in = new BufferedReader(new FileReader(this.file));
    628         String line;
    629 
    630         while ((line = in.readLine()) != null) {
    631             contents.append(line);
    632             contents.append("\n");
    633         }
    634         } catch (FileNotFoundException fnfe) {
    635         Gatherer.println("Error: log file not found: "+ this.file.toString());
    636         return "";
    637         } catch (IOException ioe) {
    638         Gatherer.println("Error: exception occurred when trying to read in file "+this.file.toString()+", "+ioe.getMessage());
    639 
    640         }
    641 
    642         return contents.toString();
    643     }
     520        if(date == null) {
     521        // Need to exclude first '.'
     522        int first_index = filename.indexOf(".") + 1;
     523        // Need to exclude the last '.'
     524        int last_index = filename.lastIndexOf(".");
     525        if(first_index > 0 && last_index > 0 && first_index < last_index) {
     526            String date_string = filename.substring(first_index, last_index);
     527            date = new Date(Long.parseLong(date_string));
     528        }
     529        else {
     530            date = new Date(); // Current date
     531        }
     532        }
     533        return date;
     534    }
     535
     536    public AppendLineOnlyFileDocument getDocument() {
     537        return new AppendLineOnlyFileDocument(filepath);
     538    }
     539
     540    public void reset() {
     541        display = null;
     542    }
     543
    644544    /** we only want the date out of the file name, not the whole path */
    645545    public String toString() {
    646         return this.display;
    647     }
    648     /** creates the display text for the list */
    649     private String createDisplayText() {
    650         StringBuffer d = new StringBuffer();
    651         d.append(date.toString());
    652         //char success= this.file.getName().charAt(23);
    653         String filename = this.file.getName();
    654         int index = filename.lastIndexOf(".") - 1;
    655         if(index >= 0) {
    656             char success = filename.charAt(index);
    657             switch (success) {
    658             case OptionsPane.SUCCESSFUL:
    659             d.append(get("Successful"));
    660             break;
    661             case OptionsPane.UNSUCCESSFUL:
    662             d.append(get("Unsuccessful"));
    663             break;
    664             case OptionsPane.CANCELLED:
    665             d.append(get("Cancelled"));
    666             break;
    667             }
    668         }
    669         return d.toString();
    670     }
    671     /** extracts the date from the file name, which is of the form 'build_log.'<long>[scu]'.txt' */
    672     private Date getDateFromFileName() {
    673         String name = this.file.getName();
    674         // Need to exclude first '.'
    675         int first_index = name.indexOf(".") + 1;
    676         // Need to exclude state letter before last '.'
    677         int last_index = name.lastIndexOf(".") - 1;
    678         if(first_index > 0 && last_index > 0 && first_index < last_index) {
    679         String date_string = name.substring(first_index, last_index);
    680         return new Date(Long.parseLong(date_string));
    681         }
    682         else {
    683         return new Date(); // Current date
    684         }
    685     }
    686 
    687 
    688     }
    689 
    690     /** A DocumentListener that listens for changes in the log_display document
    691      * if a change is registered, the flag is_log_changed is set to true,
    692      * and the listener removes itself from log_display
    693      * Because we only want to register user's changes, the listener must be removed before the system makes any changes, and then put back. For example, each time we switchlogs to display, a remove event and an insert event are sent. We dont want to register these as changes to the document, so the listener must be removed before the switch, and added back afterwards */
    694     private class LogChangeListener implements DocumentListener {
    695 
    696     public void changedUpdate(DocumentEvent e) {
    697         ///ystem.out.println("changed update");
    698         registerChange();
    699     }
    700     public void insertUpdate(DocumentEvent e) {
    701         ///ystem.out.println("insert update");
    702         registerChange();
    703     }
    704     public void removeUpdate(DocumentEvent e) {
    705         ///ystem.out.println("remove update");
    706         registerChange();
    707     }
    708 
    709     private void registerChange() {
    710         ///ystem.err.println("a change in the doc occurred, removing the listener");
    711         is_log_changed = true;
    712         log_display.getDocument().removeDocumentListener(this);
    713     }
    714     }
    715 
    716     /** a ListSelectionListener that triggers the load of a newly selected
    717     log */
     546        File file = new File(filename);
     547        if(display == null) {
     548        last_modified = file.lastModified();
     549        StringBuffer d = new StringBuffer();
     550        Date date = getDate();
     551        d.append(date.toString());
     552        char success = UNKNOWN;
     553        try {
     554            FileInputStream in = new FileInputStream(new File(filepath));
     555            success = (char) in.read();
     556            in.close();
     557            in = null;
     558        }
     559        catch(Exception error) {
     560            error.printStackTrace();
     561        }
     562        switch (success) {
     563        case SUCCESSFUL:
     564            d.append(get("Successful"));
     565            break;
     566        case UNSUCCESSFUL:
     567            d.append(get("Unsuccessful"));
     568            break;
     569        case CANCELLED:
     570            d.append(get("Cancelled"));
     571            break;
     572        default:
     573            d.append(get("Unknown"));
     574        }
     575        display = d.toString();
     576        }
     577        return display;
     578    }
     579    }
     580
     581    /** a ListSelectionListener that triggers the load of a newly selected log */
    718582    private class LogListListener implements ListSelectionListener {
    719583
     
    721585        if (!e.getValueIsAdjusting()) { // we get two events for one change in list selection - use the false one ( the second one)
    722586        JList source  = (JList)e.getSource();
    723         FileEntry fe = (FileEntry) source.getSelectedValue();
    724         loadSelectedLog(fe);
     587        file_entry = (FileEntry) source.getSelectedValue();
     588        // First we determine if the old log has been completely written to file
     589        Document document = log_textarea.getDocument();
     590        if(document instanceof AppendLineOnlyFileDocument) {
     591            AppendLineOnlyFileDocument append_line_only_file_document = (AppendLineOnlyFileDocument) document;
     592            if(append_line_only_file_document.isStillWriting()) {
     593                writing_documents.add(append_line_only_file_document); // We have to maintain a reference until they are all done.
     594                append_line_only_file_document.setOwner(OptionsPane.this);
     595                append_line_only_file_document.setExit();
     596            }
     597        }
     598        // Load the new log
     599        log_textarea.setDocument(file_entry.getDocument());
    725600        }
    726601    }
  • trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java

    r5042 r5164  
    33import java.awt.*;
    44import java.awt.event.*;
     5import java.io.*;
    56import java.net.*;
    67import java.util.*;
    78import javax.swing.*;
     9import javax.swing.event.*;
     10import org.greenstone.gatherer.Configuration;
    811import org.greenstone.gatherer.Gatherer;
    912import org.greenstone.gatherer.checklist.CheckList;
     
    1316import org.greenstone.gatherer.gui.NumberField;
    1417import org.greenstone.gatherer.gui.SimpleMenuBar;
     18import org.greenstone.gatherer.util.StaticStrings;
    1519import org.greenstone.gatherer.util.Utility;
    1620import org.greenstone.gatherer.util.XORToggleButtonGroup;
     
    3337    private JCheckBox workflow_export;
    3438    private JCheckBox workflow_preview;
     39    private JComboBox language_combobox;
     40    private JLabel extracted_metadata_label;
     41    private JLabel file_size_label;
     42    private JLabel language_label;
     43    private JLabel library_path_label;
     44    private JLabel predefined_label;
     45    private JLabel proxy_host_label;
     46    private JLabel proxy_port_label;
     47    private JLabel title_label;
     48    private JRadioButton hide_extracted_metadata_radio_button;
     49    private JRadioButton hide_file_size_radio_button;
     50    private JRadioButton show_file_size_radio_button;
     51    private JRadioButton view_extracted_metadata_radio_button;
    3552    private JTabbedPane tab_pane;
    3653    private JTextField library_path_field;
     
    3956    private Preferences self;
    4057
    41     static final Dimension LABEL_SIZE = new Dimension(100, 25);
    42     static final Dimension ROW_SIZE = new Dimension(380, 25);
    43     static final Dimension SIZE = new Dimension(400, 345);
     58    static final Dimension LABEL_SIZE = new Dimension(150, 25);
     59    static final Dimension ROW_SIZE = new Dimension(450, 25);
     60    static final Dimension SIZE = new Dimension(450, 345);
    4461    static final String TRUE = "true";
    4562
     
    5471    JPanel content_pane = (JPanel) getContentPane();
    5572    tab_pane = new JTabbedPane();
     73    tab_pane.add("Preferences.General", createGeneralPreferences());
    5674    tab_pane.add("Preferences.Workflow", createWorkflowPreferences());
    5775    tab_pane.add("Preferences.Connection", createConnectionPreferences());
     
    101119    JPanel library_path_pane = new JPanel();
    102120    library_path_pane.setPreferredSize(ROW_SIZE);
    103     JLabel library_path_label = new JLabel("Preferences.Connection.Library_Path");
     121    library_path_label = new JLabel("Preferences.Connection.Library_Path");
    104122    library_path_label.setPreferredSize(LABEL_SIZE);
    105123    library_path_field = new JTextField(Gatherer.config.getString("general.exec_address", true));
     
    113131    JPanel proxy_host_pane = new JPanel();
    114132    proxy_host_pane.setPreferredSize(ROW_SIZE);
    115     JLabel proxy_host_label = new JLabel("Preferences.Connection.Proxy_Host");
     133    proxy_host_label = new JLabel("Preferences.Connection.Proxy_Host");
    116134    proxy_host_label.setPreferredSize(LABEL_SIZE);
    117135    proxy_host_field = new JTextField(Gatherer.config.getString("general.proxy_host", true));
     
    119137    JPanel proxy_port_pane = new JPanel();
    120138    proxy_port_pane.setPreferredSize(ROW_SIZE);
    121     JLabel proxy_port_label = new JLabel("Preferences.Connection.Proxy_Port");
     139    proxy_port_label = new JLabel("Preferences.Connection.Proxy_Port");
    122140    proxy_port_label.setPreferredSize(LABEL_SIZE);
    123141    proxy_port_field = new NumberField(Gatherer.config.getString("general.proxy_port", true));
     
    152170    }
    153171
     172    private JPanel createGeneralPreferences() {
     173    JPanel general_pane = new JPanel();
     174
     175    // Build the model of available languages
     176    ArrayList dictionary_model = new ArrayList();
     177
     178    Locale french = new Locale("fr","FR");
     179    System.err.println("French locale: " + french);
     180
     181
     182    dictionary_model.add(new DictionaryEntry(Locale.ENGLISH));
     183    File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER);
     184    File[] possible_dictionaries = classes_folder.listFiles();
     185    for(int i = 0; i < possible_dictionaries.length; i++) {
     186        String filename = possible_dictionaries[i].getName();
     187        if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) {
     188        StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER);
     189        Locale locale = null;
     190        switch(tokenizer.countTokens()) {
     191        case 1:
     192            locale = new Locale(tokenizer.nextToken().toLowerCase());
     193            break;
     194        case 2:
     195            locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase());
     196            break;
     197        }
     198        tokenizer = null;
     199        // Open the file and read the first line
     200        String description = null;
     201        try {
     202            BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i]));
     203            String first_line = br.readLine();
     204            br.close();
     205            description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1);
     206        }
     207        catch(Exception error) {
     208        }
     209        DictionaryEntry entry = new DictionaryEntry(description, locale);
     210        description = null;
     211        locale = null;
     212        if(!dictionary_model.contains(entry)) {
     213            dictionary_model.add(entry);
     214        }
     215        entry = null;
     216        }
     217        filename = null;
     218    }
     219    possible_dictionaries = null;
     220    classes_folder = null;
     221
     222    // Extracted metadata
     223    JPanel extracted_metadata_pane = new JPanel();
     224    extracted_metadata_label = new JLabel("NewCollectionPrompt.Extracted_Metadata");
     225    ButtonGroup extracted_metadata_button_group = new ButtonGroup();
     226    view_extracted_metadata_radio_button = new JRadioButton("NewCollectionPrompt.View_Extracted_Metadata");
     227    view_extracted_metadata_radio_button.setEnabled(Gatherer.c_man.ready());
     228    view_extracted_metadata_radio_button.setOpaque(false);
     229    extracted_metadata_button_group.add(view_extracted_metadata_radio_button);
     230    hide_extracted_metadata_radio_button = new JRadioButton("NewCollectionPrompt.Hide_Extracted_Metadata");
     231    hide_extracted_metadata_radio_button.setEnabled(Gatherer.c_man.ready());
     232    hide_extracted_metadata_radio_button.setOpaque(false);
     233    extracted_metadata_button_group.add(hide_extracted_metadata_radio_button);
     234    if(Gatherer.config.get("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC)) {
     235        view_extracted_metadata_radio_button.setSelected(true);
     236    }
     237    else {
     238        hide_extracted_metadata_radio_button.setSelected(true);
     239    }
     240
     241    // Show file sizes
     242    JPanel file_size_pane = new JPanel();
     243    file_size_label = new JLabel("Prefereces.General.File_Size");
     244    ButtonGroup file_size_button_group = new ButtonGroup();
     245    show_file_size_radio_button = new JRadioButton("Prefereces.General.Show_File_Size");
     246    show_file_size_radio_button.setEnabled(Gatherer.c_man.ready());
     247    show_file_size_radio_button.setOpaque(false);
     248        file_size_button_group.add(show_file_size_radio_button);
     249    hide_file_size_radio_button = new JRadioButton("Prefereces.General.Hide_File_Size");
     250    hide_file_size_radio_button.setEnabled(Gatherer.c_man.ready());
     251    hide_file_size_radio_button.setOpaque(false);
     252    file_size_button_group.add(hide_file_size_radio_button);
     253    if(Gatherer.config.get("general.show_file_size", Configuration.COLLECTION_SPECIFIC)) {
     254        show_file_size_radio_button.setSelected(true);
     255    }
     256    else {
     257        hide_file_size_radio_button.setSelected(true);
     258    }
     259
     260    // Language
     261    JPanel language_pane = new JPanel();
     262    language_label = new JLabel("Preferences.General.Interface_Language");
     263    language_label.setPreferredSize(LABEL_SIZE);
     264    language_combobox = new JComboBox(dictionary_model.toArray());
     265
     266    // Connect
     267    Gatherer.dictionary.register(file_size_label, null, false);
     268    Gatherer.dictionary.register(show_file_size_radio_button, null, false);
     269    Gatherer.dictionary.register(hide_file_size_radio_button, null, false);
     270    Gatherer.dictionary.register(view_extracted_metadata_radio_button, null, false);
     271    Gatherer.dictionary.register(hide_extracted_metadata_radio_button, null, false);
     272    Gatherer.dictionary.register(language_label, null, false);
     273    language_combobox.addActionListener(new LanguageComboboxListener());
     274    // Layout
     275
     276    file_size_pane.setLayout(new GridLayout(1,3,5,0));
     277        file_size_pane.add(show_file_size_radio_button);
     278    file_size_pane.add(hide_file_size_radio_button);
     279
     280    extracted_metadata_pane.setLayout(new GridLayout(1,3,5,0));
     281    extracted_metadata_pane.add(view_extracted_metadata_radio_button);
     282    extracted_metadata_pane.add(hide_extracted_metadata_radio_button);
     283
     284    language_pane.setLayout(new BorderLayout());
     285    language_pane.add(language_label, BorderLayout.WEST);
     286    language_pane.add(language_combobox, BorderLayout.CENTER);
     287
     288    general_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     289    general_pane.setLayout(new GridLayout(5,1,0,5));
     290    general_pane.add(extracted_metadata_pane);
     291    general_pane.add(file_size_pane);
     292    general_pane.add(language_pane);
     293
     294    return general_pane;
     295    }
     296
    154297    /** The warning preferences are controlled through a checklist. */
    155298    private JPanel createWarningPreferences() {
    156299    // Retrieve all of the warning preferences settings.
    157300    HashMap warning_preferences = Gatherer.config.getAll("warning\\..*", true);
    158     warning_preferences_check_list = new CheckList();
     301    warning_preferences_check_list = new CheckList(false);
    159302    for(Iterator keys = warning_preferences.keySet().iterator(); keys.hasNext(); ) {
    160303        String property = (String) keys.next();
     
    189332    JPanel workflow_preferences_pane = new JPanel();
    190333    JPanel checklist_pane = new JPanel();
    191     JLabel title_label = new JLabel("Preferences.Workflow.Title");
     334    title_label = new JLabel("Preferences.Workflow.Title");
    192335    title_label.setPreferredSize(ROW_SIZE);
    193336    XORToggleButtonGroup checkbox_group = new XORToggleButtonGroup();
     
    209352    workflow_preview.setPreferredSize(ROW_SIZE);
    210353    JPanel predefined_pane = new JPanel();
    211     JLabel predefined_label = new JLabel("Preferences.Workflow.Predefined.Label");
     354    predefined_label = new JLabel("Preferences.Workflow.Predefined.Label");
    212355    predefined_label.setPreferredSize(new Dimension(150,25));
    213356    JComboBox predefined_combobox = new JComboBox(predefined);
     
    272415    public void dispose() {
    273416    // Deregister dictionary components
     417
     418    // Connection
     419    Gatherer.dictionary.deregister(library_path_label);
     420    Gatherer.dictionary.deregister(use_proxy_checkbox);
     421    Gatherer.dictionary.deregister(proxy_host_label);
     422    Gatherer.dictionary.deregister(proxy_port_label);
     423
     424    // General
     425    Gatherer.dictionary.deregister(file_size_label);
     426    Gatherer.dictionary.deregister(show_file_size_radio_button);
     427    Gatherer.dictionary.deregister(hide_file_size_radio_button);
     428    Gatherer.dictionary.deregister(extracted_metadata_label);
     429    Gatherer.dictionary.deregister(view_extracted_metadata_radio_button);
     430    Gatherer.dictionary.deregister(hide_extracted_metadata_radio_button);
     431    Gatherer.dictionary.deregister(language_label);
     432
     433    // Workflow
     434    Gatherer.dictionary.deregister(title_label);
     435    Gatherer.dictionary.deregister(workflow_browse);
     436    Gatherer.dictionary.deregister(workflow_mirror);
     437    Gatherer.dictionary.deregister(workflow_gather);
     438    Gatherer.dictionary.deregister(workflow_enrich);
     439    Gatherer.dictionary.deregister(workflow_design);
     440    Gatherer.dictionary.deregister(workflow_export);
     441    Gatherer.dictionary.deregister(workflow_create);
     442    Gatherer.dictionary.deregister(workflow_preview);
     443    Gatherer.dictionary.deregister(predefined_label);
     444
     445    // Dialog
    274446    Gatherer.dictionary.deregister(this);
    275447    Gatherer.dictionary.deregister(tab_pane);
     
    288460    }
    289461    public void actionPerformed(ActionEvent event) {
    290                 // Submit the various changes.
    291                 // Connection preferences
     462        // Submit the various changes.
     463        // Connection preferences
    292464        String library_path_string = library_path_field.getText();
    293465        Gatherer.config.setString("general.exec_address", true, library_path_string);
     
    300472        }
    301473        }
    302 
    303474        Gatherer.config.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
    304475        Gatherer.config.setString("general.proxy_host", true, proxy_host_field.getText());
    305476        Gatherer.config.setString("general.proxy_port", true, proxy_port_field.getText());
    306477        Gatherer.setProxy();
    307                 // Warning preferences
     478
     479        // General preferences
     480        Gatherer.config.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, show_file_size_radio_button.isSelected());
     481        if(Gatherer.g_man.mirror_pane != null) {
     482        Gatherer.g_man.mirror_pane.refreshTrees();
     483        }
     484        Gatherer.g_man.collection_pane.refreshTrees();
     485        Gatherer.g_man.metaedit_pane.refreshTrees();
     486
     487        Gatherer.config.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, view_extracted_metadata_radio_button.isSelected());
     488        Gatherer.g_man.metaedit_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table
     489
     490        Gatherer.config.setLocale("general.locale", Configuration.GENERAL_SETTING, ((DictionaryEntry)language_combobox.getSelectedItem()).getLocale());
     491
     492        // Warning preferences
    308493        for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {
    309494        Entry entry = warning_preferences_check_list.get(i);
    310495        Gatherer.config.set(entry.getProperty(), true, entry.isSelected());
    311496        }
    312                 // Workflow preferences
     497        // Workflow preferences
    313498        Gatherer.config.set("workflow.browse", false, workflow_browse.isSelected());
    314499        Gatherer.config.set("workflow.mirror", false, workflow_mirror.isSelected());
     
    327512        Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
    328513        Gatherer.g_man.workflowUpdate("Preview", workflow_preview.isSelected());
    329                 // Hide dialog
     514        // Hide dialog
    330515        if(close) {
    331516        self.dispose();
     
    338523    public void actionPerformed(ActionEvent event) {
    339524        self.dispose();
     525    }
     526    }
     527
     528    private class DictionaryEntry
     529    implements Comparable {
     530    private Locale locale;
     531    private String description;
     532    public DictionaryEntry(Locale locale) {
     533        this.description = null;
     534        this.locale = locale;
     535    }
     536    public DictionaryEntry(String description, Locale locale) {
     537        this.description = description;
     538        this.locale = locale;
     539    }
     540    public int compareTo(Object object) {
     541        return toString().compareTo(object.toString());
     542    }
     543    public boolean equals(Object object) {
     544        return toString().equals(object.toString());
     545    }
     546    public Locale getLocale() {
     547        return locale;
     548    }
     549    public String toString() {
     550        if(description != null) {
     551        return description;
     552        }
     553        else {
     554        return locale.getDisplayName();
     555        }
    340556    }
    341557    }
     
    369585    }
    370586
     587    private class LanguageComboboxListener
     588    implements ActionListener {
     589    public void actionPerformed(ActionEvent event) {
     590        // Retrieve the entry
     591        DictionaryEntry entry = (DictionaryEntry) language_combobox.getSelectedItem();
     592        if(entry != null) {
     593        Gatherer.dictionary.changeDictionary(entry.getLocale());
     594        // Display message
     595        JOptionPane.showMessageDialog(Gatherer.g_man, Gatherer.dictionary.get("Preferences.General.Restart_Required"), Gatherer.dictionary.get("Preferences.General.Restart_Required"), JOptionPane.WARNING_MESSAGE);
     596        }
     597    }
     598    }
     599
    371600    private class UseProxyListener
    372601    implements ActionListener {
  • trunk/gli/src/org/greenstone/gatherer/gui/WarningDialog.java

    r5058 r5164  
    88import org.greenstone.gatherer.Gatherer;
    99import org.greenstone.gatherer.gui.SmarterTextArea;
     10import org.greenstone.gatherer.util.FocusChangerTask;
    1011import org.greenstone.gatherer.util.Utility;
    1112
     
    2526    private JCheckBox show_check;
    2627    private JTextField value_field;
     28    private JPanel value_panel;
    2729    private String affected_property;
    2830    private String full_property;
     
    7678    text_area.setLineWrap(true);
    7779    text_area.setWrapStyleWord(true);
    78     JPanel value_panel = new JPanel();
     80    value_panel = new JPanel();
    7981    JLabel value_label = new JLabel(get("WarningDialog.Value"));
    8082    value_label.setPreferredSize(LABEL_SIZE);
     
    137139
    138140    public void actionPerformed(ActionEvent event) {
     141    boolean bad_value = false;
    139142    if(event.getSource() == ok_button) {
    140         result = JOptionPane.OK_OPTION;
     143        if(affected_property != null && Gatherer.config != null) {
     144        String value = value_field.getText();
     145        if(value.length() == 0) {
     146            bad_value = true;
     147        }
     148        else if(value_field instanceof URLField) {
     149            bad_value = !((URLField)value_field).validateURL();
     150        }
     151        if(!bad_value) {
     152            // Store the value of the property
     153            Gatherer.config.setString(affected_property, true, value_field.getText());
     154        }
     155        }
     156        if(!bad_value) {
     157        result = JOptionPane.OK_OPTION;
     158        }
     159    }
     160    if(!bad_value) {
    141161        if(Gatherer.config != null) {
    142         // Store the value of the property
    143         Gatherer.config.setString(affected_property, true, value_field.getText());
    144         }
    145     }
    146     if(Gatherer.config != null) {
    147         // Store the state of the show message checkbox.
    148         Gatherer.config.set(full_property, true, !show_check.isSelected());
    149     }
    150     // Done.
    151     dispose();
     162        // Store the state of the show message checkbox.
     163        Gatherer.config.set(full_property, true, !show_check.isSelected());
     164        }
     165        // Done.
     166        dispose();
     167    }
     168    else {
     169        JOptionPane.showMessageDialog(Gatherer.g_man, get("WarningDialog.Invalid_Value"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
     170    }
    152171    }
    153172
     
    155174    ///ystem.err.println("Show " + full_property + ": " + Gatherer.config.get(full_property, false));
    156175    if(Gatherer.config == null || Gatherer.config.get(full_property, false)) {
    157         // We only show if the warning has not been disabled.
     176        // Create and run the shortlived move focus thread
     177        FocusChangerTask task = null;
     178        if(affected_property != null) {
     179        task = new FocusChangerTask(value_field);
     180        }
     181        else {
     182        task = new FocusChangerTask(ok_button);
     183        }
     184        task.start();
    158185        show();
    159186    }
     
    163190    }
    164191    return result;
     192    }
     193
     194    /** Allows you to replace the generic text field control with a JTextField subclass with further functionality. For instance you might provide a URLField to allow only valid URLs to be accepted.
     195     * @param  control the JTextField subclass you want to use for the control
     196     */
     197    public void setValueField(JTextField control) {
     198    // Remove the current control
     199    value_panel.remove(value_field);
     200    // Replace with the new one
     201    value_field = control;
     202    // Re-add
     203    value_panel.add(value_field, BorderLayout.CENTER);
    165204    }
    166205
  • trunk/gli/src/org/greenstone/gatherer/msm/GDMDocument.java

    r4674 r5164  
    3232import org.greenstone.gatherer.msm.MSMUtils;
    3333import org.greenstone.gatherer.util.HashMap3D;
     34import org.greenstone.gatherer.util.StaticStrings;
    3435import org.greenstone.gatherer.util.Utility;
    3536import org.greenstone.gatherer.valuetree.GValueModel;
     
    138139        filename_element = null;
    139140        }
    140                 // Now, finally, we can add the metadata.
     141        // Now, finally, we can add the metadata.
    141142        Element metadata_element = base_document.createElement(METADATA_ELEMENT);
    142         metadata_element.setAttribute(NAME_ATTRIBUTE, metadata.getElement().getName());
    143 
    144                 // To determine if this metadata entry should overwrite or accumulate we check if there are other entries with the same element in this fileset.
     143        String name = metadata.getElement().getName();
     144        if(name.startsWith(Utility.EXTRACTED_METADATA_NAMESPACE)) {
     145        name = name.substring(Utility.EXTRACTED_METADATA_NAMESPACE.length() + 1);
     146        }
     147        metadata_element.setAttribute(NAME_ATTRIBUTE, name);
     148
     149        // To determine if this metadata entry should overwrite or accumulate we check if there are other entries with the same element in this fileset.
    145150        boolean will_accumulate = false;
    146151        NodeList sibling_description_elements = fileset_element.getElementsByTagName(DESCRIPTION_ELEMENT);
     
    180185        }
    181186        metadata_element.appendChild(base_document.createTextNode(metadata.getAbsoluteValue()));
    182                 // Retrieve the first description element for this fileset (there should only be one, but I'll play it safe).
     187        // Retrieve the first description element for this fileset (there should only be one, but I'll play it safe).
    183188        NodeList description_elements = fileset_element.getElementsByTagName("Description");
    184189        Element description_element = (Element) description_elements.item(0);
     
    194199        Gatherer.printStackTrace(error);
    195200    }
     201    }
     202
     203    public int countMetadata() {
     204    int count = 0;
     205    try {
     206        // Retrieve the document element.
     207        Element directorymetadata_element = base_document.getDocumentElement();
     208        // Iterate through the filesets, checking the FileName child element against    the target file's name using regular expression matching.
     209        NodeList fileset_elements = directorymetadata_element.getElementsByTagName(FILESET_ELEMENT);
     210        for(int i = 0; i < fileset_elements.getLength(); i++) {
     211        Element fileset_element = (Element) fileset_elements.item(i);
     212        NodeList description_elements = fileset_element.getElementsByTagName(DESCRIPTION_ELEMENT);
     213        for(int k = 0; k < description_elements.getLength(); k++) {
     214            Element description_element = (Element) description_elements.item(k);
     215            NodeList metadata_elements = description_element.getElementsByTagName(METADATA_ELEMENT);
     216            count = count + metadata_elements.getLength();
     217            metadata_elements = null;
     218            description_element = null;
     219        }
     220        description_elements = null;
     221        fileset_element = null;
     222        }
     223        fileset_elements = null;
     224        directorymetadata_element = null;
     225    }
     226    catch (Exception error) {
     227        Gatherer.printStackTrace(error);
     228    }
     229    return count;
    196230    }
    197231
     
    240274                    raw_value = MSMUtils.getValue(metadata_element);
    241275                }
     276                // ***** LEGACY SUPPORT *****
     277                // If this raw_value contains a '\' character, but no '\\', '[' or ']' characters, then replace the '\' with a '\\'
     278                if(raw_value.indexOf(StaticStrings.ESCAPE_STR) != -1 && raw_value.indexOf(StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR) == -1 && raw_value.indexOf(StaticStrings.RBRACKET_CHARACTER) == -1 && raw_value.indexOf(StaticStrings.LBRACKET_CHARACTER) == -1) {
     279                    Gatherer.println("Detected Legacy Path: " + raw_value);
     280                    raw_value = raw_value.replaceAll(StaticStrings.ESCAPE_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.ESCAPE_PATTERN);
     281                    Gatherer.println("Updated Path To: " + raw_value);
     282                    metadata_element.setAttribute(HVALUE_ATTRIBUTE, raw_value);
     283                }
     284                // **************************
    242285                // Using the element string and value, retrieve a matching Metadata object from the cache
    243286                Metadata metadata = null;
  • trunk/gli/src/org/greenstone/gatherer/msm/GDMManager.java

    r4674 r5164  
    319319        // First purge any old references.
    320320        document.getMetadata(null, false, null, null, true);
    321         // Now write the xml
    322         Utility.export(document.getDocument(), file);
    323         document.setUpToDate(true);
     321        // If there is no metadata in this document then don't write out a file. In fact delete any file that already exists.
     322        int count = document.countMetadata();
     323        if(count > 0) {
     324            // Now write the xml
     325            Utility.export(document.getDocument(), file);
     326            document.setUpToDate(true);
     327        }
     328        else if(file.exists()) {
     329            file.delete();
     330        }
    324331        }
    325332    }
  • trunk/gli/src/org/greenstone/gatherer/msm/GreenstoneArchiveParser.java

    r5047 r5164  
    8080            args[0] = document_directories[i].getName();
    8181            args[1] = String.valueOf(count);
    82             shell.message(GShell.IMPORT, shell.typeAsString(GShell.IMPORT) + "> " + Gatherer.dictionary.get("GShell.Extracted", args), GShell.OK);
     82            shell.fireMessage(GShell.IMPORT, shell.typeAsString(GShell.IMPORT) + "> " + Gatherer.dictionary.get("GShell.Extracted", args), GShell.OK);
    8383            args = null;
    8484            progress.increment();
  • trunk/gli/src/org/greenstone/gatherer/msm/Metadata.java

    r4674 r5164  
    4444import org.greenstone.gatherer.valuetree.GValueModel;
    4545import org.greenstone.gatherer.valuetree.GValueNode;
     46import org.greenstone.gatherer.util.StaticStrings;
    4647import org.w3c.dom.Element;
    4748/** Stores a mapping between a particular metadata element, and a certain value node.
     
    124125    if(model != null && model.isHierarchy()) {
    125126        if(value != null) {
    126         GValueNode node = (GValueNode)value.getParent();
    127         while(node != null) {
    128             GValueNode next = (GValueNode)node.getParent();
    129             if(next != null) {
    130             abs_value = node.toString() + "\\" + abs_value;
    131             }
    132             node = next;
    133         }
     127        abs_value = value.getFullPath();
    134128        }
    135129        abs_value = model.getHIndex(abs_value);
     130    }
     131    else {
     132        abs_value = abs_value.replaceAll(StaticStrings.LBRACKET_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.LBRACKET_PATTERN);
     133        abs_value = abs_value.replaceAll(StaticStrings.RBRACKET_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.RBRACKET_PATTERN);
    136134    }
    137135    // Return the result
Note: See TracChangeset for help on using the changeset viewer.