Changeset 4504 for trunk/gli


Ignore:
Timestamp:
2003-06-06T15:44:35+12:00 (21 years ago)
Author:
kjdon
Message:

fixed up adding and removing elements from teh set - need to add/remove their associated value trees too./shutdown.sh also removeValueTree now deals with GValueModels rather than Elements which it did in a really old version of value trees

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/msm/MetadataSet.java

    r4488 r4504  
    196196    /** Method to add a new metadata element to this metadata set, if and only if the element is not already present.
    197197     * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set.
     198     * @param model A <strong>GValueModel</strong> value tree
    198199     * @return <i>null</i> if the add is successful, otherwise a <strong>String</strong> containing an error message (phrase key).
    199200     */
    200     public String addElement(Element others_element) {
     201    public String addElement(Element others_element, GValueModel model) {
    201202    if(!containsElement(others_element.getAttribute("name"))) {
    202                 // First get ownership of the new element, then add it.
    203         Node our_element = document.importNode(others_element, true);
     203        // First get ownership of the new element, then add it.
     204        Element our_element = (Element)document.importNode(others_element, true);
     205        // add the value tree
    204206        root.appendChild(our_element);
     207        if (model != null) {
     208        addValueTree(new ElementWrapper(our_element), model);   
     209        }   
    205210        return null;
    206211    }
    207212    else {
    208         return "Element name already exists!";
     213        return "MSMPrompt.Name_Exists";
    209214    }
    210215    }
     
    213218     * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set.
    214219     * @param new_name The new name to be given this element, as a <strong>String</strong>.
     220     * @param model A <strong>GValueModel</strong> value tree
    215221     * @return <i>null</i> if the add is successful, otherwise a <strong>String</strong> containing an error message (phrase key).
    216222     */
    217     public String addElement(Element others_element, String new_name) {
     223    public String addElement(Element others_element, String new_name, GValueModel model) {
    218224    if(!containsElement(new_name)) {
    219                 // First get ownership of the new element, then add it.
     225        // First get ownership of the new element, then add it.
    220226        Element our_element =
    221227        (Element) document.importNode(others_element, true);
    222                 // Change name
     228        // Change name
    223229        our_element.setAttribute("name", new_name);
    224                 // Add it
     230        // we also want to change the english identifier of this element
     231        MSMUtils.setIdentifier(our_element, new_name);
     232        // Add it to teh set
    225233        root.appendChild(our_element);
     234        // add the value tree
     235        if (model != null) {
     236        addValueTree(new ElementWrapper(our_element), model);
     237        }
    226238        return null;
    227239    }
     
    232244    /** Add a value tree to a given metadata element.
    233245     * @param element The <strong>ElementWrapper</strong> containing the element you wish to add a value tree for.
    234      * @param value_tree The root <strong>Element</strong> of the value tree.
     246     * @param model A <strong>GValueModel</strong> value tree
    235247     */
    236248    public void addValueTree(ElementWrapper element, GValueModel model) {
     
    443455    public GValueModel getValueTree(ElementWrapper element) {
    444456    GValueModel value_tree = null;
    445     ///ystem.err.println("Retrieving value tree for element: " + element.toString());
    446457    // Stinking hashtable get doesn't use the overridden equals. So I'll do a loop, which should be pretty small ie O(n) for n metadata elements.
    447458    for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) {
     
    449460        if(sibling.equals(element)) {
    450461        value_tree = (GValueModel) value_trees.get(sibling);
     462        break;
    451463        }
    452464    }
     
    468480     */
    469481    public void removeElement(Element element) {
     482    // we need to remove the value tree too!!
     483    removeValueTree(new ElementWrapper(element));
    470484    root.removeChild(element);
    471485    }
    472486    /** Used to remove the value tree for a specific element.
    473487     * @param element The <strong>ElementWrapper</strong> whose tree you wish to remove.
    474      * @return The <strong>Element</strong> at the root of the value tree we just removed.
    475      */
    476     public Element removeValueTree(ElementWrapper element) {
     488     * @return The <strong>GValueModel</strong> we just removed
     489     */
     490    public GValueModel removeValueTree(ElementWrapper element) {
    477491    for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) {
    478492        ElementWrapper sibling = (ElementWrapper) keys.nextElement();
    479493        if(sibling.equals(element)) {
    480         Element tree_root = (Element) value_trees.get(sibling);
     494        GValueModel value_tree = (GValueModel) value_trees.get(sibling);
    481495        value_trees.remove(sibling);
    482         return tree_root;
     496        return value_tree;
    483497        }
    484498    }
Note: See TracChangeset for help on using the changeset viewer.