Changeset 4405


Ignore:
Timestamp:
2003-05-29T15:23:52+12:00 (21 years ago)
Author:
jmt12
Message:

2030088: Changed add and remove method to used SynchronizedTreeModelTools (even though many of the events a subsequently run invokeLater due to the add and remove calls occuring on the Event Dispatch thread).

File:
1 edited

Legend:

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

    r4364 r4405  
    8282    /** Value may include path ie news/newssw */
    8383    public GValueNode addValue(String value) {
    84     ///ystem.err.println("Adding value to valuetree: " + value);
    8584    StringTokenizer tokenizer = new StringTokenizer(value, "\\");
    8685    GValueNode subject = (GValueNode) root;
     
    8887        String token = tokenizer.nextToken();
    8988        subject = addValue(token, subject, null);
    90                 ///ystem.err.println("Found or created a node " + token);
     89        ///ystem.err.println("Found or created a node " + token);
    9190    }
    9291    return subject;
     
    9796    GValueNode value_node = subject.getValue(Utility.stripNL(value));
    9897    if(value_node == null) {
    99                 // Now add the new value.
     98        // Now add the new value.
    10099        Document document = subject.getElement().getOwnerDocument();
    101                 // Now we create a new subject and add it subject
     100        // Now we create a new subject and add it subject
    102101        Element new_subject = document.createElementNS("","Subject");
    103102        Element new_value = document.createElementNS("","Value");
     
    112111        }
    113112        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.
    132116        Gatherer.c_man.getCollection().msm.fireValueChanged(element, null, this);
    133117    }
     
    159143    GValueNode result = null;
    160144    if(isHierarchy() && Utility.isIndex(index_str)) {
    161                 // StringTokenize the index
     145        // StringTokenize the index
    162146        StringTokenizer tokenizer = new StringTokenizer(index_str, ".");
    163147        result = (GValueNode) root;
    164                 // Using the index numbers retrieve the appropriate node.
     148        // Using the index numbers retrieve the appropriate node.
    165149        try {
    166150        while(result != null && tokenizer.hasMoreTokens()) {
     
    177161        }
    178162        }
    179                 // Most likely caused by parseInt throwing a wobbly.
     163        // Most likely caused by parseInt throwing a wobbly.
    180164        catch (Exception error) {
    181165        result = null;
    182166        }
    183         if(result != null) {
    184         // Ensure result is enabled
    185         result.setEnabled(true);
    186         }
    187167    }
    188168    if(result == null) {
    189                 ///ystem.err.println("No existing value. Adding " + index_str);
     169        ///ystem.err.println("No existing value. Adding " + index_str);
    190170        result = addValue(index_str);
    191171    }
     
    210190
    211191    public void removeValue(GValueNode child) {
    212     child.setEnabled(false); // Doesn't appear anymore.
    213192    SynchronizedTreeModelTools.removeNodeFromParent(this, child);
    214193    Gatherer.c_man.getCollection().msm.fireValueChanged(new ElementWrapper(child.getElement()), null, this);
     
    218197    // Retrieve the node to be removed.
    219198    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    }
    232202    }
    233203
Note: See TracChangeset for help on using the changeset viewer.