Index: trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionMetadataPrompt.java
===================================================================
--- trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionMetadataPrompt.java	(revision 8243)
+++ trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionMetadataPrompt.java	(revision 8313)
@@ -32,15 +32,15 @@
 import java.util.*;
 import javax.swing.*;
+import javax.swing.border.*;
 import javax.swing.event.*;
 import org.greenstone.gatherer.Configuration;
 import org.greenstone.gatherer.Dictionary;
 import org.greenstone.gatherer.Gatherer;
-import org.greenstone.gatherer.checklist.CheckList;
-import org.greenstone.gatherer.checklist.Entry;
-import org.greenstone.gatherer.cdm.ElementWrapper;
-import org.greenstone.gatherer.msm.MetadataSet;
-import org.greenstone.gatherer.util.StaticStrings;
+import org.greenstone.gatherer.metadata.MetadataElement;
+import org.greenstone.gatherer.metadata.MetadataSet;
+import org.greenstone.gatherer.metadata.MetadataSetManager;
+import org.greenstone.gatherer.metadata.MetadataTools;
 import org.greenstone.gatherer.util.Utility;
-import org.w3c.dom.*;
+
 
 public class NewCollectionMetadataPrompt
@@ -48,7 +48,7 @@
 
     private boolean cancelled = true;
-    private CheckList sets_list;
     private JDialog self;
     private JList elements_list;
+    private MetadataSetList sets_list;
     static private Dimension size = new Dimension(700, 380);
 
@@ -68,16 +68,17 @@
 	setModal(true);
 	setSize(size);
-	
-
-	// And the remaining metadata sets.
-	ArrayList sets = new ArrayList();
-	// Determine what collections are available.
-	File metadata_directory = new File(Utility.METADATA_DIR);
-	File[] possible_mdses = metadata_directory.listFiles();
-	for(int i = 0; i < possible_mdses.length; i++) {
-	    String name = possible_mdses[i].getName();
-	    if(name.endsWith(StaticStrings.METADATA_SET_EXTENSION) && !name.equals(Utility.EXTRACTED_METADATA_NAMESPACE + StaticStrings.METADATA_SET_EXTENSION)) {
-		sets.add(new MetadataSet(possible_mdses[i]));
-	    }
+
+	// Show the metadata sets (except extracted!) available in the GLI "metadata" folder 
+	ArrayList sets = MetadataSetManager.listMetadataSets(new File(Utility.METADATA_DIR));
+	ArrayList metadata_set_list_entries = new ArrayList();
+	for (int i = 0; i < sets.size(); i++) {
+	    MetadataSet metadata_set = (MetadataSet) sets.get(i);
+
+	    // Don't show the extracted metadata set
+	    if (metadata_set.getNamespace().equals(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE)) {
+		continue;
+	    }
+
+	    metadata_set_list_entries.add(new MetadataSetListEntry(metadata_set));
 	}
 
@@ -97,5 +98,7 @@
 	sets_list_label.setOpaque(false);
 	Dictionary.setText(sets_list_label, "NewCollectionPrompt.Select_MDS");
-	sets_list = new CheckList(sets, true);
+	sets_list = new MetadataSetList();
+	sets_list.setListData(new Vector(metadata_set_list_entries));
+	sets_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
 	JPanel elements_list_pane = new JPanel();
@@ -103,8 +106,12 @@
 	Dictionary.setText(elements_list_label, "NewCollectionPrompt.Metadata_Elements");
 	elements_list = new JList();
+	elements_list.setCellRenderer(new MetadataElementListCellRenderer());
 	elements_list.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
 	elements_list.setForeground(Configuration.getColor("coloring.collection_tree_foreground", false));
 	elements_list.setSelectionBackground(Configuration.getColor("coloring.collection_tree_background", false));
 	elements_list.setSelectionForeground(Configuration.getColor("coloring.collection_tree_foreground", false));
+
+	// Select the Dublin Core metadata set by default, at Ian's request
+	sets_list.selectDublinCoreMetadataSet();
 
 	JPanel button_pane = new JPanel();
@@ -119,5 +126,4 @@
 	ok_button.addActionListener(new OKButtonListener());
 	cancel_button.addActionListener(new CancelButtonListener());
-	sets_list.addListSelectionListener(new MetadataListSelectionListener());
 
 	// Display
@@ -157,5 +163,5 @@
 
     public ArrayList getSets() {
-	return sets_list.getSelected();
+	return sets_list.getSelectedMetadataSets();
     }
 
@@ -163,4 +169,5 @@
 	return cancelled;
     }
+
 
     private class CancelButtonListener
@@ -172,35 +179,132 @@
     }
 
-    public class MetadataListSelectionListener
-	implements ListSelectionListener {
-	public void valueChanged(ListSelectionEvent event) {
-	    if(!sets_list.isSelectionEmpty()) {
-		// Retrieve the selected set.
-		Entry entry = (Entry) sets_list.getSelectedValue();
-		MetadataSet set = (MetadataSet) entry.getObject();
-		entry = null;
-		// Build a model from its elements.
-		NodeList elements = set.getElements();
-		set = null;
-		Vector elements_model = new Vector();
-		for(int i = 0; i < elements.getLength(); i++) {
-		    elements_model.add(new ElementWrapper(elements.item(i)));
-		}
-		elements = null;
-		Collections.sort(elements_model);
-		elements_list.setListData(elements_model);
-		elements_model = null;
-	    }
-	    else {
-		elements_list.setListData(new String[0]);
-	    }
-	}
-    }
-
-    public class OKButtonListener
+
+    private class MetadataSetList
+	extends JList
+    {
+	public MetadataSetList()
+	{
+	    super();
+	    addListSelectionListener(new MetadataSetListSelectionListener());
+	    addMouseListener(new MetadataSetListSelectionListener());
+	    setCellRenderer(new MetadataSetListCellRenderer());
+	}
+
+
+	public ArrayList getSelectedMetadataSets()
+	{
+	    ArrayList selected_metadata_sets = new ArrayList();
+
+	    ListModel model = (ListModel) getModel();
+	    for (int i = 0; i < model.getSize(); i++) {
+		MetadataSetListEntry metadata_set_list_entry = (MetadataSetListEntry) model.getElementAt(i);
+		if (metadata_set_list_entry.isSelected()) {
+		    selected_metadata_sets.add(metadata_set_list_entry.getMetadataSet());
+		}
+	    }
+
+	    return selected_metadata_sets;
+	}
+
+
+	/** Hack special-case code, used to select the Dublin Core metadata set by default */
+	public void selectDublinCoreMetadataSet()
+	{
+	    ListModel model = (ListModel) getModel();
+	    for (int i = 0; i < model.getSize(); i++) {
+		MetadataSetListEntry metadata_set_list_entry = (MetadataSetListEntry) model.getElementAt(i);
+		if (metadata_set_list_entry.getMetadataSet().getNamespace().equals("dc")) {
+		    metadata_set_list_entry.setSelected(true);
+		    metadata_set_list_entry.grabFocus();
+		    setSelectedIndex(i);
+		}
+	    }
+	}
+
+
+  	private class MetadataSetListCellRenderer
+  	    extends JLabel
+  	    implements ListCellRenderer {
+
+	    public Component getListCellRendererComponent(JList list, Object value, int index, boolean is_selected, boolean cell_has_focus)
+	    {
+		JCheckBox checkbox = (JCheckBox) value;
+		checkbox.setBackground(is_selected ? list.getSelectionBackground() : list.getBackground());
+		checkbox.setForeground(is_selected ? list.getSelectionForeground() : list.getForeground());
+		checkbox.setBorderPainted(true);
+		checkbox.setEnabled(list.isEnabled());
+		checkbox.setFont(list.getFont());
+		checkbox.setFocusPainted(false);
+		checkbox.setBorder((is_selected) ? UIManager.getBorder("List.focusCellHighlightBorder") : new EmptyBorder(1, 1, 1, 1));
+		return checkbox;
+	    }
+  	}
+
+
+	private class MetadataSetListSelectionListener
+	    extends MouseAdapter
+	    implements ListSelectionListener {
+
+	    public void mousePressed(MouseEvent e)
+	    {
+		JList list = (JList) e.getSource();
+		int index = list.locationToIndex(e.getPoint());
+		MetadataSetListEntry metadata_set_list_entry = (MetadataSetListEntry) list.getModel().getElementAt(index);
+		metadata_set_list_entry.setSelected(!metadata_set_list_entry.isSelected());
+		metadata_set_list_entry.grabFocus();
+
+		// Fire a selection changed event
+		fireSelectionValueChanged(index, index, false);
+	    }
+
+	    public void valueChanged(ListSelectionEvent event)
+	    {
+		if (!sets_list.isSelectionEmpty()) {
+		    // Retrieve the selected set
+		    MetadataSetListEntry metadata_set_list_entry = (MetadataSetListEntry) sets_list.getSelectedValue();
+		    MetadataSet set = (MetadataSet) metadata_set_list_entry.getMetadataSet();
+		    elements_list.setListData(new Vector(set.getMetadataSetElements()));
+		}
+		else {
+		    elements_list.setListData(new String[0]);
+		}
+	    }
+	}
+    }
+
+
+    private class MetadataSetListEntry
+	extends JCheckBox
+    {
+	private MetadataSet metadata_set = null;
+
+	public MetadataSetListEntry(MetadataSet metadata_set)
+	{
+	    this.metadata_set = metadata_set;
+	}
+
+	public MetadataSet getMetadataSet()
+	{
+	    return metadata_set;
+	}
+
+	public String getText()
+	{
+	    if (metadata_set == null) {
+		return null;
+	    }
+
+	    String interface_language_code = Configuration.getLanguage();
+	    String metadata_set_name = MetadataTools.getMetadataSetAttribute(metadata_set, "Name", interface_language_code, "en");
+	    return metadata_set_name + " (" + metadata_set.getNamespace() + ")";
+	}
+    }
+
+
+    private class OKButtonListener
 	implements ActionListener {
 	public void actionPerformed(ActionEvent event) {
 	    // See if the user has selected no metadata sets, and if so confirm thats what they really want.
-	    ArrayList selected_sets = sets_list.getSelected();
+	    ArrayList selected_sets = sets_list.getSelectedMetadataSets();
 	    cancelled = false;
 	    if(selected_sets.size() == 0) {
