Changeset 4508


Ignore:
Timestamp:
2003-06-09T10:24:20+12:00 (21 years ago)
Author:
kjdon
Message:

fixed up the 'select element to merge with' dialog - used when adding stuff to teh collection which has metadata already associated.

File:
1 edited

Legend:

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

    r4490 r4508  
    674674    // Init controls
    675675    if(set.getItemCount() > 0) {
    676                 // We now try to determine the existing metadata element that is the closest match to the one we are trying to merge.
     676        // We now try to determine if there is any existing metadata
     677        // element whose name is the same as the new one.  we ignore
     678        // any namespaces - if the name was a full match (namespace
     679        // and element name) then we wouldn't be in here
    677680        MetadataSet closest_set = null;
    678681        ElementWrapper closest_element = null;
    679         int med = -1;
     682        String base_name = name;
     683        int ns_sep = base_name.indexOf(MSMUtils.NS_SEP);
     684        if (ns_sep != -1) {
     685        base_name = base_name.substring(ns_sep+1);
     686        }
    680687        for(int i = 0; i < set.getItemCount(); i++) {
    681688        MetadataSet mds = (MetadataSet) set.getItemAt(i);
    682689        for(int j = 0; j < mds.size(); j++) {
    683             ElementWrapper mde = new ElementWrapper(mds.getElement(j));
    684             int new_med = MED.LD(name, mde.toString());
    685             if(med == -1 || new_med < med) {
    686             med = new_med;
    687             closest_element = mde;
     690            Element mde = mds.getElement(j);
     691            String new_name = mde.getAttribute("name");
     692            if (base_name.equals(new_name)) {
     693            closest_element = new ElementWrapper(mde);
    688694            closest_set = mds;
     695            mde=null;
     696            break;
    689697            }
    690698            mde = null;
     699        } // for each element
     700        if (closest_element != null) {
     701            mds=null;
     702            break;
    691703        }
     704       
    692705        mds = null;
    693         }
     706        } // for each set
    694707        if(closest_set != null && closest_element != null) {
    695708        set.setSelectedItem(closest_set);
    696         element.setSelectedItem(closest_element);
    697         set_listener.actionPerformed();
     709        set_listener.actionPerformed(closest_element);
    698710        }
    699711        else {
    700         set_listener.actionPerformed();
     712        set_listener.actionPerformed((ElementWrapper)null);
    701713        }
    702714        closest_set = null;
     
    10161028        this.set = set;
    10171029    }
    1018     public void actionPerformed() {
     1030    /** because the dialog constructor is selecting an element before calling actionPerformed, and actionPerformed is where the list of elements is built, we need to tell this what element should be selected */
     1031    public void actionPerformed(ElementWrapper selected_elem) {
    10191032        element.removeAllItems();
    10201033        MetadataSet mds = (MetadataSet) set.getSelectedItem();
     
    10441057            an_element = null;
    10451058        }
     1059        // if we have a pre selected element
     1060        if (selected_elem != null) {
     1061            // if this element is not in the set, the selection wont change
     1062            element.setSelectedItem(selected_elem);
     1063        }
    10461064        add_button.setEnabled(add_button_enabled);
    10471065
     
    10631081    }
    10641082    public void actionPerformed(ActionEvent item) {
    1065         actionPerformed();
     1083        actionPerformed((ElementWrapper)null);
    10661084    } 
    10671085    }
Note: See TracChangeset for help on using the changeset viewer.