Changeset 9996


Ignore:
Timestamp:
2005-06-01T14:12:40+12:00 (19 years ago)
Author:
kjdon
Message:

removed the text class variable - we no longer cache the string representation - it can get set wrong sometimes. changed getName to get the metadata name, and added getLevel to return the level string. comparesTo changed to just look at the level info, not the full string - we consider two levels the same if they have the same level, regardless of the meta name

File:
1 edited

Legend:

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

    r8243 r9996  
    4242    /** The Element this level object will source its information from. */
    4343    private Element element;
    44     /** A cached version of the string representation, for speed of painting (given toString() might be called several times during a list repaint). */
    45     private String text;
    4644
    4745    /** Constructor used only during DOMProxyListModel initialization. */
     
    5957     * @param  name the name of this type as a String
    6058     */
    61     public Level(String name) {
    62     element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT);
    63     element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
    64     text = null;
     59    public Level(String level) {
     60    this.element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CONTENT_ELEMENT);
     61    this.element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, level);
    6562    }
    6663
     
    6865     * @param  object the other Object to compare to
    6966     * @return <0 if this level should be before the given object, 0 if they are equal, and >0 if it should be after
     67     * since we can only have one instance of a particular level, we don't need to look at the name when comparing.
    7068     */
    7169    public int compareTo(Object object) {
     
    7371        return -1;
    7472    }
    75     return toString().compareTo(object.toString());
     73    // hope we never compare a Level with something that is not a Level!
     74    return getLevel().compareTo(((Level)object).getLevel());
    7675    }
    7776
     
    9998    }
    10099
    101     /** Retrieve the name of this level.
    102      * @return the name as a String
     100    /** Retrieve the level.
     101     * @return the level as a String
    103102     */
    104     public String getName() {
     103    public String getLevel() {
    105104    return element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE);
    106105    }
    107106
    108     /** Determine is this command has been assigned, either because it already existed in the collection configuration, or because it has been explicitly set by the user. Non-assigned entries imply they have been added by the GLI to ensure consistancy (and avoid NPE's!)
     107    /** Retrieve the display name
     108     */
     109    public String getName() {
     110    CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + getLevel(), false);
     111    if(metadatum != null) {
     112        return metadatum.getValue(CollectionMeta.TEXT);
     113    }
     114    return "";
     115    }
     116   
     117   /** Determine is this command has been assigned, either because it already existed in the collection configuration, or because it has been explicitly set by the user. Non-assigned entries imply they have been added by the GLI to ensure consistancy (and avoid NPE's!)
    109118     * @return true if this command has been assigned, false otherwise
    110119     * @see org.greenstone.gatherer.cdm.CollectionConfiguration
     
    129138    public void setElement(Element element) {
    130139    this.element = element;
    131     this.text = null;
    132140    }
    133141
     
    136144     * @see org.greenstone.gatherer.cdm.CollectionConfiguration
    137145     */
    138     public void setName(String name) {
     146    public void setLevel(String level) {
    139147    if(element != null) {
    140         element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name);
    141         this.text = null;
     148        element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, level);
    142149    }
    143150    }
     
    148155     */
    149156    public String toString() {
    150     if(text == null) {
    151         if(element == null) {
    152         text = "#Error";
    153         }
    154         else {
    155         String name = getName();
    156         StringBuffer text_buffer = new StringBuffer(name);
    157         CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER + name, false);
    158         if(metadatum != null) {
    159             text_buffer.append(" \"");
    160             text_buffer.append(metadatum.getValue(CollectionMeta.TEXT));
    161             text_buffer.append("\"");
    162         }
    163         text = text_buffer.toString();
    164         text_buffer = null;
    165         }
     157    String text ="";
     158    if(element == null) {
     159        text = "#Error";
    166160    }
     161    else {
     162        String level = getLevel();
     163        StringBuffer text_buffer = new StringBuffer(level);
     164        text_buffer.append(" \"");
     165        text_buffer.append(getName());
     166        text_buffer.append("\"");
     167   
     168        text = text_buffer.toString();
     169        text_buffer = null;
     170    }
     171   
    167172    return text;
    168173    }
Note: See TracChangeset for help on using the changeset viewer.