Changeset 4405
- Timestamp:
- 2003-05-29T15:23:52+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/valuetree/GValueModel.java
r4364 r4405 82 82 /** Value may include path ie news/newssw */ 83 83 public GValueNode addValue(String value) { 84 ///ystem.err.println("Adding value to valuetree: " + value);85 84 StringTokenizer tokenizer = new StringTokenizer(value, "\\"); 86 85 GValueNode subject = (GValueNode) root; … … 88 87 String token = tokenizer.nextToken(); 89 88 subject = addValue(token, subject, null); 90 89 ///ystem.err.println("Found or created a node " + token); 91 90 } 92 91 return subject; … … 97 96 GValueNode value_node = subject.getValue(Utility.stripNL(value)); 98 97 if(value_node == null) { 99 98 // Now add the new value. 100 99 Document document = subject.getElement().getOwnerDocument(); 101 100 // Now we create a new subject and add it subject 102 101 Element new_subject = document.createElementNS("","Subject"); 103 102 Element new_value = document.createElementNS("","Value"); … … 112 111 } 113 112 value_node = new GValueNode(new_subject); 114 // Figure out where this node will be inserted in subjects 115 // children. 116 int position = -1; 117 for(int i = 0; position == -1 && i < subject.getChildCount(); i++) { 118 Object sibling = subject.getChildAt(i); 119 int rel_pos = value.compareTo(sibling.toString()); 120 ///ystem.err.println("'"+value+"'.compareTo('"+sibling+"') = " + rel_pos); 121 if(rel_pos <= 0) { 122 position = i; 123 } 124 } 125 if(position == -1) { 126 position = subject.getChildCount(); 127 } 128 // Insert it. If position is still -1, append it to the end of subjects children. 129 ///ystem.err.println("Inserting '" + value + "' at position " + position); 130 insertNodeInto(value_node, subject, position); 131 // Inform listeners that we've changed. 113 // Insert it. If position is still -1, append it to the end of subjects children. 114 SynchronizedTreeModelTools.insertNodeInto(this, subject, value_node); 115 // Inform listeners that we've changed. 132 116 Gatherer.c_man.getCollection().msm.fireValueChanged(element, null, this); 133 117 } … … 159 143 GValueNode result = null; 160 144 if(isHierarchy() && Utility.isIndex(index_str)) { 161 145 // StringTokenize the index 162 146 StringTokenizer tokenizer = new StringTokenizer(index_str, "."); 163 147 result = (GValueNode) root; 164 148 // Using the index numbers retrieve the appropriate node. 165 149 try { 166 150 while(result != null && tokenizer.hasMoreTokens()) { … … 177 161 } 178 162 } 179 163 // Most likely caused by parseInt throwing a wobbly. 180 164 catch (Exception error) { 181 165 result = null; 182 166 } 183 if(result != null) {184 // Ensure result is enabled185 result.setEnabled(true);186 }187 167 } 188 168 if(result == null) { 189 169 ///ystem.err.println("No existing value. Adding " + index_str); 190 170 result = addValue(index_str); 191 171 } … … 210 190 211 191 public void removeValue(GValueNode child) { 212 child.setEnabled(false); // Doesn't appear anymore.213 192 SynchronizedTreeModelTools.removeNodeFromParent(this, child); 214 193 Gatherer.c_man.getCollection().msm.fireValueChanged(new ElementWrapper(child.getElement()), null, this); … … 218 197 // Retrieve the node to be removed. 219 198 GValueNode node = getValue(value); 220 // Now remove it 221 removeNodeFromParent(node); 222 } 223 224 /** Called to remove a certain value of metadata within a specific 225 * subject within a sbject hierarchy. 226 * Note that this method currently doesn't do anything. 227 * @param value A String representing the value to be removed. 228 * @param subject An Element representing the subject you wish to remove 229 * this value from. 230 */ 231 public void removeValue(String value, GValueNode subject) { 199 if(node != null) { 200 removeValue(node); 201 } 232 202 } 233 203
Note:
See TracChangeset
for help on using the changeset viewer.