Changeset 5777


Ignore:
Timestamp:
2003-11-04T16:02:58+13:00 (20 years ago)
Author:
mdewsnip
Message:

Fixed bug 169: metadata element names and identifiers being confused when importing metadata (in collect view). Names and identifiers are still opposite to the way I would have them, but at least the bug is fixed.

Location:
trunk/gli/src/org/greenstone/gatherer/msm
Files:
3 edited

Legend:

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

    r5714 r5777  
    212212
    213213    public String toString() {
    214     return MSMUtils.getFullIdentifier(element, namespace);
     214    String element_name = getName();
     215    String element_identifier = getIdentity();
     216
     217    // Generate the element name without the namespace
     218    String element_name_no_namespace = element_name;
     219    int namespace_end = element_name.indexOf(MSMUtils.NS_SEP);
     220    if (namespace_end != -1) {
     221        element_name_no_namespace = element_name.substring(namespace_end + 1);
     222    }
     223
     224    // Return just the element name, unless the element identifier differs
     225    if (element_name_no_namespace.equals(element_identifier)) {
     226        return element_name;
     227    }
     228    else {
     229        return element_name + " (" + element_identifier + ")";
     230    }
    215231    }
    216232}
  • trunk/gli/src/org/greenstone/gatherer/msm/MSMPrompt.java

    r5713 r5777  
    10831083    }
    10841084
    1085     private class SetListener
     1085    /** Listens to changes in the metadata set combobox */
     1086    private class SetListener
    10861087    implements ActionListener {
     1088
    10871089    private JButton add_button = null;
    10881090    private JButton merge_button = null;
    1089     private JComboBox element = null;
    1090     private JComboBox set = null;
    1091     private String name = null;
    1092     public SetListener(JComboBox set, JComboBox element, String name, JButton add_button, JButton merge_button) {
     1091    private JComboBox element_combobox = null;
     1092    private JComboBox set_combobox = null;
     1093    private String element_name = null;
     1094
     1095    public SetListener(JComboBox set_combobox, JComboBox element_combobox, String element_name, JButton add_button, JButton merge_button)
     1096    {
     1097        this.element_name = element_name;
     1098        this.element_combobox = element_combobox;
     1099        this.set_combobox = set_combobox;
    10931100        this.add_button = add_button;
    1094         this.element = element;
    10951101        this.merge_button = merge_button;
    1096         this.name = name.toLowerCase();
    1097         this.set = set;
    1098     }
     1102    }
     1103
    10991104    /** 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 */
    1100     public void actionPerformed(ElementWrapper selected_elem) {
    1101         element.removeAllItems();
    1102         MetadataSet mds = (MetadataSet) set.getSelectedItem();
    1103         ///ystem.err.println("Set selected: " + mds);
    1104         if(mds != null) {
    1105            NodeList elements = mds.getElements();
    1106            
    1107            Vector temp = new Vector();
    1108            for(int i = elements.getLength() - 1; i >= 0; i--) {
    1109           temp.add(new ElementWrapper((Element)elements.item(i)));
    1110            }
    1111            Collections.sort(temp, MSMUtils.METADATA_COMPARATOR);
    1112        
    1113         // The add button is only enabled if an element with the same name doesn't already exist in the destination set.
    1114         boolean add_button_enabled = true;
    1115         ///ystem.err.println("Checking for " + name);
    1116         for(int j = 0; j < temp.size(); j++) {
    1117             ElementWrapper an_element = (ElementWrapper)temp.get(j);
    1118             // Can only add if no file with the same name exists.
    1119             String check = an_element.toString().toLowerCase();
    1120             int position = -1;
    1121             if((position = check.indexOf(".")) != -1) {
    1122             check = check.substring(position + 1);
    1123             }
    1124             ///ystem.err.println("does it match " + check + "? " + name.equals(check));
    1125             add_button_enabled = add_button_enabled && !name.equals(check);
    1126             check = null;
    1127             element.addItem(an_element);
    1128             an_element = null;
    1129         }
    1130         // if we have a pre selected element
    1131         if (selected_elem != null) {
    1132             // if this element is not in the set, the selection wont change
    1133             element.setSelectedItem(selected_elem);
    1134         }
    1135         add_button.setEnabled(add_button_enabled);
    1136 
    1137         // The merge button is only enabled if there is more than one element in the destination set.
    1138         if(temp.size() > 0) {
    1139             merge_button.setEnabled(true);
    1140         }
    1141         else {
    1142             merge_button.setEnabled(false);
    1143         }
    1144         temp = null;
    1145         elements = null;
    1146         }
    1147         else {
     1105    public void actionPerformed(ElementWrapper selected_elem)
     1106    {
     1107        MetadataSet mds = (MetadataSet) set_combobox.getSelectedItem();
     1108        if (mds == null) {
     1109        // If there is no metadata set selected, there isn't much you can do
    11481110        add_button.setEnabled(false);
    11491111        merge_button.setEnabled(false);
    1150         }
    1151         mds = null;
    1152     }
    1153     public void actionPerformed(ActionEvent item) {
    1154         actionPerformed((ElementWrapper)null);
    1155     } 
     1112        return;
     1113        }
     1114
     1115        // Fill the element combobox with the elements of the selected metadata set
     1116        element_combobox.removeAllItems();
     1117        Vector elements_list = mds.getElementsSorted();
     1118        for (int i = 0; i < elements_list.size(); i++) {
     1119        element_combobox.addItem(elements_list.get(i));
     1120        }
     1121
     1122        // If there is a pre-selected element, select it in the combobox
     1123        if (selected_elem != null) {
     1124        // If the element is not in the set, the selection won't change
     1125        element_combobox.setSelectedItem(selected_elem);
     1126        }
     1127
     1128        // Can only add if the element doesn't already exist in the metadata set
     1129        add_button.setEnabled(!mds.containsElement(element_name));
     1130
     1131        // Can only merge if the metadata set is not empty
     1132        merge_button.setEnabled(mds.size() > 0);
     1133    }
     1134
     1135    public void actionPerformed(ActionEvent item)
     1136    {
     1137        actionPerformed((ElementWrapper) null);
     1138    }
    11561139    }
    11571140}
  • trunk/gli/src/org/greenstone/gatherer/msm/MetadataSet.java

    r5593 r5777  
    279279    }
    280280
    281     /** A method to determine if this metadata set contains an element with a certain name.
     281    /** A method to determine if this metadata set contains an element with a certain name (case sensitive).
    282282     * @param name A <strong>String</strong> which is the name of the element whose presence we are checking.
    283283     * @return A <i>boolean</i> which is <i>true</i> if the named element exists, <i>false</i> otherwise.
     
    405405    return elements;
    406406    }
     407
     408    /** Method to retrieve a list of all the elements in this metadata set, sorted.
     409     * @return A <strong>Vector</strong> containing all of the elements of this sets, sorted.
     410     */
     411    public Vector getElementsSorted() {
     412    Vector elements_list = new Vector();
     413    for (int i = 0; i < elements.getLength(); i++) {
     414        elements_list.add(new ElementWrapper((Element) elements.item(i)));
     415    }
     416    Collections.sort(elements_list, MSMUtils.METADATA_COMPARATOR);
     417    return elements_list;
     418    }
     419
    407420    /** Method to retrieve the original file this metadata set was created from.
    408421     * @return A <strong>File</strong>.
Note: See TracChangeset for help on using the changeset viewer.