Changeset 9996
- Timestamp:
- 2005-06-01T14:12:40+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/Level.java
r8243 r9996 42 42 /** The Element this level object will source its information from. */ 43 43 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;46 44 47 45 /** Constructor used only during DOMProxyListModel initialization. */ … … 59 57 * @param name the name of this type as a String 60 58 */ 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); 65 62 } 66 63 … … 68 65 * @param object the other Object to compare to 69 66 * @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. 70 68 */ 71 69 public int compareTo(Object object) { … … 73 71 return -1; 74 72 } 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()); 76 75 } 77 76 … … 99 98 } 100 99 101 /** Retrieve the name of thislevel.102 * @return the nameas a String100 /** Retrieve the level. 101 * @return the level as a String 103 102 */ 104 public String get Name() {103 public String getLevel() { 105 104 return element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE); 106 105 } 107 106 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!) 109 118 * @return true if this command has been assigned, false otherwise 110 119 * @see org.greenstone.gatherer.cdm.CollectionConfiguration … … 129 138 public void setElement(Element element) { 130 139 this.element = element; 131 this.text = null;132 140 } 133 141 … … 136 144 * @see org.greenstone.gatherer.cdm.CollectionConfiguration 137 145 */ 138 public void set Name(String name) {146 public void setLevel(String level) { 139 147 if(element != null) { 140 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, name); 141 this.text = null; 148 element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, level); 142 149 } 143 150 } … … 148 155 */ 149 156 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"; 166 160 } 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 167 172 return text; 168 173 }
Note:
See TracChangeset
for help on using the changeset viewer.