Changeset 12824


Ignore:
Timestamp:
2006-09-22T09:40:43+12:00 (18 years ago)
Author:
kjdon
Message:

changed option list form HashMap to ArrayList so they stay in order, added ArgumentOption class, which replaces ListOption from ArgumentControl

File:
1 edited

Legend:

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

    r12466 r12824  
    4242import org.greenstone.gatherer.metadata.MetadataTools;
    4343import org.greenstone.gatherer.util.StaticStrings;
     44import org.greenstone.gatherer.util.Utility;
    4445import org.greenstone.gatherer.util.XMLTools;
    4546import org.w3c.dom.*;
     
    9495    private Element element;
    9596    /** If the argument is of type ENUM then this map holds all the various options. Each entry is an <option value> -> <description> mapping. */
    96     private HashMap list = null;
     97    private ArrayList option_list = null;
    9798    /** A default value for parameter-type arguments. May be a Perl pattern. */
    9899    private String default_value = null;
     
    117118    }
    118119
    119     /** Method to add an element to the option list.
     120    /** Method to add an element to the option_list.
    120121     * @param name the name value of the option as a String
    121122     * @param desc the description of this options as a String
     
    126127        desc = "";
    127128        }
    128         if(list == null) {
    129         list = new HashMap();
    130         }
    131         list.put(name, desc);
     129        if(option_list == null) {
     130        option_list = new ArrayList();
     131        }
     132        option_list.add(new ArgumentOption(name, desc));
    132133    }
    133134    }
     
    154155    copy.setDefaultValue(default_value);
    155156    copy.setDescription(description);
    156     copy.setOptions(list);
     157    copy.setOptions(option_list);
    157158    copy.setOwner(owner);
    158159    copy.setName(name);
     
    188189    }
    189190
    190     /** Method to retrieve the description of a certain list option value.
    191      * @param key the String whose description we are searching for
    192      * @return the description of the desired key as a String which may be empty if no such key exists
    193      */
    194     public String getDescription(String key) {
    195     if(list.containsKey(key)) {
    196         return (String)list.get(key);
    197     }
    198     return "";
    199     }
    200 
    201191    public Element getElement() {
    202192    return element;
     
    242232     * @return a HashMap containing <option value> -> <description> entries
    243233     */
    244     public HashMap getOptions() {
    245     return list;
     234    public ArrayList getOptions() {
     235    return option_list;
    246236    }
    247237
     
    377367     * @param list the new options list as a HashMap
    378368     */
    379     public void setOptions(HashMap list) {
    380     this.list = list;
     369    public void setOptions(ArrayList list) {
     370    this.option_list = list;
    381371    }
    382372
     
    416406    if(new_type.equalsIgnoreCase(StaticStrings.ENUM_STR)) {
    417407        this.type = ENUM;
    418         list = new HashMap();
     408        option_list = new ArrayList();
    419409    }
    420410    else if(new_type.equalsIgnoreCase(StaticStrings.FLAG_STR)) {
     
    626616   
    627617    } // parseXML
     618
     619    public class ArgumentOption
     620    implements Comparable {
     621    public String name;
     622    public String description;
     623    private String text; // cached version
     624
     625    public ArgumentOption(String name, String desc) {
     626        this.name = name;
     627        this.description = desc;
     628    }
     629   
     630    public int compareTo(Object obj) {
     631        return toString().compareTo(obj.toString());
     632    }
     633
     634    public boolean equals(Object obj) {     
     635        return (obj != null && compareTo(obj) == 0);
     636    }
     637   
     638    public String toString() {
     639        return name + " "+ StaticStrings.MINUS_CHARACTER + " "+ description;
     640    }
     641   
     642    public String getToolTip() {
     643        return Utility.formatHTMLWidth(name+": "+description, 80);
     644    }
     645    }
    628646}
Note: See TracChangeset for help on using the changeset viewer.