Index: /trunk/gli/src/org/greenstone/gatherer/gems/ElementWrapper.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/ElementWrapper.java	(revision 8970)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/ElementWrapper.java	(revision 8971)
@@ -63,7 +63,6 @@
     private String namespace = "";
     private ArrayList subelements = null; //The list of subelements
-    // private XMLTools xmlTools = new XMLTools(); //uh, a class of XML tools, i guess
-
     private Troolean is_extracted = new Troolean();
+
     /** Constructor for elements with no namespace necessary.
      * @param element The DOM <strong>Element</strong> this is to be based on.
@@ -95,5 +94,5 @@
        @param name the name of the subelement to check for, as a <strong>String</strong> 
        @author Matthew Whyte
-       @date last modified: 19/01/04
+       Date last modified: 19/01/04
     */
     public boolean containsSubelement(String name)
@@ -113,4 +112,15 @@
     }
 
+    /*
+      Check to see if the element contains any subelements
+      @return tree if element contains subelements
+      @author Matthew Whyte
+      Date last modified: 2/02/05
+     */
+    public boolean containsSubelements()
+    {
+	return(subelements.size() != 0);
+    }
+
     /**
        Method to add a subelement to the list of subelements.
@@ -122,4 +132,15 @@
     {
 	subelements.add(element);
+    }
+
+    /**
+       Method to remove a subelement from the list of subelements.
+       @param element the subelement to remove from the list, as a <strong>Element</strong>
+       @author Matthew Whyte
+       Date last modified: 27/01/05
+     */
+    public void removeSubelementFromList(Element element)
+    {
+	subelements.remove(element);
     }
 
Index: /trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java	(revision 8970)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java	(revision 8971)
@@ -36,5 +36,4 @@
 package org.greenstone.gatherer.gems;
 
-
 import java.awt.*;
 import java.awt.event.*;
@@ -87,19 +86,13 @@
     static final private Dimension ADD_ELEMENT_SIZE = new Dimension(400,125);
     static final private Dimension RENAME_ELEMENT_SIZE = new Dimension(400, 95);
-    static final private Dimension ADD_FILE_SIZE = new Dimension(400,125);
     static final private Dimension ADD_SET_SIZE = new Dimension(400,150);
     static final private Dimension RENAME_SET_SIZE = new Dimension(400,120);
     static final private Dimension OPEN_SETS_SIZE = new Dimension(400,135);
     static final private Dimension ADD_OR_EDIT_ATTRIBUTE_SIZE = new Dimension(600,325);
-    static final private Dimension ADD_OR_EDIT_VALUE_SIZE = new Dimension(600,440);
-    
     static final private Dimension COMPONENT_SIZE = new Dimension(300,30);
     static final private Dimension SIZE = new Dimension(800,480);
     static final private String BLANK = "blank";
     static final private String ELEMENT = "element";
-    static final private String PROFILE = "profile";
     static final private String SET = "set";
-    static final private String SUBELEMENT = "subelement";
-    static final private String VALUES = "values";
 
     static final public String METADATA_SET_TEMPLATE = "xml/template.mds";
@@ -109,31 +102,21 @@
     static final public int T_COLLECTION = 0;
     static final public int T_ELEMENT    = 1;
-    static final public int T_PROFILER   = 2;
-    static final public int T_ROOT       = 3; 
     static final public int T_SET        = 4;
-    static final public int T_SUBELEMENT = 5;
-
-   // static final public String MAX_LOADED_SETS = 64;
+
+    //static final public String MAX_LOADED_SETS = 64;
     static public Configuration config = null;
     private MetadataSetManager msm = new MetadataSetManager(this);
 
     public AddElementActionListener add_element_action_listener = null;
-    private AddFileActionListener add_file_action_listener = null;
     public  AddSetActionListener add_set_action_listener = null;
     /** The class used to handle add or edit attribute actions has to be globally available so that we can dispose of its dialog properly. */
     public AddOrEditAttributeActionListener add_or_edit_attribute_action_listener = null;
-    /** The class used to handle add or edit value actions has to be globally available so that we can dispose of its dialog properly. */
-    //public AddOrEditValueActionListener add_or_edit_value_action_listener = null;
     private boolean ignore = false;
     /** A card layout is used to switch between the two differing detail views. */ 
     private CardLayout card_layout = null;
-    /** A card layout is used to switch between a value tree or an empty placeholder (if no value tree available). */
-    private CardLayout element_values_layout = null;
 
     /** Um, the size of the screen I'd guess. */
     private Dimension screen_size = null;
     private ElementWrapper current_element = null;
-    private ElementWrapper current_subelement = null;
-    private GValueNode current_value_node = null;
     /** A reference to ourselves so our inner classes can dispose of us. */
     private GEMS self = null;
@@ -142,24 +125,15 @@
     private int current_attribute_type = -1;
 
-    private JLabel element_name = null;
-    private JLabel profile_name = null;
+    //private JLabel element_name = null;
     private JLabel set_name = null;
     private JScrollPane element_attributes_scroll = null;
-    private JScrollPane profile_attributes_scroll = null;
     private JScrollPane set_attributes_scroll = null;
-    private JScrollPane subelement_attributes_scroll = null;
     private JPanel details_pane = null;
-    private JPanel element_values_pane = null;
-    private KeepTreeRootExpandedListener keep_root_expanded_listener = null;
     private GEMSModel model = null;
     private GEMSNode current_node = null;
     private MetadataSet current_set = null;
-    private Object target = null;
     public RemoveSetActionListener remove_set_action_listener;
-    private SmarterTable subelement_attributes = null;
     private SmarterTable element_attributes = null;
-    private SmarterTable profile_attributes = null;
     private SmarterTable set_attributes = null;
-    private SmarterTree element_values = null;
     public org.w3c.dom.Element rootelement;
    
@@ -171,5 +145,4 @@
     /** A tree that represents the current metadata sets associated with this collection. */
     private SmarterTree mds_tree = null;
-    private String current_collection_file = null;
     private String dialog_options[] = null;
     private boolean atLeastOneSetChanged = false;
@@ -195,6 +168,4 @@
            
 	    config = new Configuration(go.gsdl_path, null, null);
-        
-           
 	}
 	catch (Exception exception) {
@@ -226,16 +197,4 @@
 	dialog_options[1] = Dictionary.get("General.Cancel");
 
-	// Creation
-	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
-	setSize(SIZE);
-	setJMenuBar(new GEMSMenuBar());
-	Dictionary.setText(this, "GEMS.Title");
-
-	JPanel content_pane = (JPanel) getContentPane();
-	content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
-		  
-	JPanel upper_pane = new JPanel();
-	upper_pane.setOpaque(false);
-		  
 	// Load all the core metadata sets (in the GLI "metadata" directory)
 	model = new GEMSModel();
@@ -254,7 +213,36 @@
 	}
 
+	// Creation
+	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+	setSize(SIZE);
+	setJMenuBar(new GEMSMenuBar());
+	Dictionary.setText(this, "GEMS.Title");
+
+	JPanel content_pane = (JPanel) getContentPane();
+	content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));	  
+	JPanel upper_pane = new JPanel();
+	upper_pane.setOpaque(false);
+	JPanel set_details_pane = new JPanel();
+	set_details_pane.setOpaque(false);
+	JPanel set_name_pane = new JPanel();
+	set_name_pane.setOpaque(false);
+	JLabel set_name_label = new JLabel();
+	set_name_label.setOpaque(false);
+	JPanel element_details_pane = new JPanel();
+	element_details_pane.setOpaque(false);	  
+	JPanel element_inner_pane = new JPanel();
+	element_inner_pane.setOpaque(false);
+	JPanel blank_pane = new JPanel(); // Some blank panel
+	blank_pane.setOpaque(false);
+
+	details_pane = new JPanel();
+	details_pane.setOpaque(false);
+	card_layout = new CardLayout();
+	set_name = new JLabel();
+	
 	JPanel mds_tree_pane = new JPanel();
 	mds_tree_pane.setOpaque(false);
 	mds_tree_pane.setPreferredSize(new Dimension(300,500));
+
 	mds_tree = new SmarterTree(model);
 	mds_tree.setCellRenderer(new GEMSTreeCellRenderer());
@@ -264,21 +252,8 @@
 	mds_tree.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
 	mds_tree.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
-        
         //add popupevent handler for tree items
-      
         mds_tree.addMouseListener(popupListener);
 	mds_tree.addKeyListener(new KeyPressedHandler());
-	details_pane = new JPanel();
-	details_pane.setOpaque(false);
-	card_layout = new CardLayout();
-		  
-	JPanel set_details_pane = new JPanel();
-	set_details_pane.setOpaque(false);
-		  
-	JPanel set_name_pane = new JPanel();
-	set_name_pane.setOpaque(false);
-	JLabel set_name_label = new JLabel();
-	set_name_label.setOpaque(false);
-	set_name = new JLabel();
+	mds_tree.addTreeSelectionListener(new MDSTreeSelectionListener());
 		  
 	JPanel set_attributes_pane = new JPanel();
@@ -300,14 +275,5 @@
 	set_attributes.addMouseListener(new AddOrEditAttributeActionListener());
 	set_attributes.addKeyListener(new RemoveAttributeActionListener()); //Listen for DELETE key
-	JPanel element_details_pane = new JPanel();
-	element_details_pane.setOpaque(false);
-
-	JPanel element_name_pane = new JPanel();
-	element_name_pane.setOpaque(false);
-	JLabel element_name_label = new JLabel();
-	element_name_label.setOpaque(false);
-		  
-	JPanel element_inner_pane = new JPanel();
-	element_inner_pane.setOpaque(false);
+	set_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(set_attributes));
 		  
 	JPanel element_attributes_pane = new JPanel();
@@ -328,121 +294,10 @@
 	element_attributes.addMouseListener(new AddOrEditAttributeActionListener());
 	element_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key
-        
-	element_values_layout = new CardLayout();
-	element_values_pane = new JPanel();
-	element_values_pane.setOpaque(false);
-	element_values = new SmarterTree();
-	element_values.setBackground(config.getColor("coloring.collection_tree_background", false));
-	element_values.setForeground(config.getColor("coloring.collection_tree_foreground", false));
-	element_values.setRootVisible(false);
-	element_values.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
-	element_values.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
-		
-	JPanel subelement_details_pane = new JPanel();
-	subelement_details_pane.setOpaque(false);
-	JPanel subelement_name_pane = new JPanel();
-	subelement_name_pane.setOpaque(false);
-	JLabel subelement_name_label = new JLabel();
-	subelement_name_label.setOpaque(false);
-	JPanel subelement_inner_pane = new JPanel();
-	subelement_inner_pane.setOpaque(false);
-
-	JPanel subelement_attributes_pane = new JPanel();
-	subelement_attributes_pane.setOpaque(false);
-	subelement_attributes_scroll = new JScrollPane();
-	subelement_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false));
-	subelement_attributes_scroll.setOpaque(true);
-	subelement_attributes = new SmarterTable();
-	subelement_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
-	subelement_attributes.setBackground(config.getColor("coloring.collection_tree_background", false));
-	subelement_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false));
-	subelement_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false));
-	subelement_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false));
-	subelement_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
-	subelement_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
-	subelement_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-        subelement_attributes.addMouseListener(popupListener);
-	subelement_attributes.addMouseListener(new AddOrEditAttributeActionListener());
-	subelement_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key
-	
-	JPanel element_novalues_pane = new JPanel();
-
-	keep_root_expanded_listener = new KeepTreeRootExpandedListener();
-
-	JPanel profile_details_pane = new JPanel();
-	profile_details_pane.setOpaque(false);
-	JPanel profile_name_pane = new JPanel();
-	profile_name_pane.setOpaque(false);
-	JLabel profile_name_label = new JLabel();
-	profile_name_label.setOpaque(false);
-	profile_name = new JLabel();
-	profile_name.setBorder(BorderFactory.createLoweredBevelBorder());
-	profile_name.setOpaque(false);
-
-	JPanel profile_attributes_pane = new JPanel();
-	profile_attributes_pane.setOpaque(false);
-	profile_attributes_scroll = new JScrollPane();
-	profile_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false));
-	profile_attributes_scroll.setOpaque(true);
-	profile_attributes = new SmarterTable();
-	profile_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
-	profile_attributes.setBackground(config.getColor("coloring.collection_tree_background", false));
-	profile_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false));
-	profile_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false));
-	profile_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false));
-	profile_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
-	profile_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
-	profile_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-
-	JPanel button_pane = new JPanel();
-	button_pane.setOpaque(false);
-
-	JPanel button_label_pane = new JPanel();
-	button_label_pane.setOpaque(false);
-
-	JLabel attribute_label = new JLabel();
-	attribute_label.setOpaque(false);
-	Dictionary.setText(attribute_label, "GEMS.Attribute");
-
-	JLabel element_label = new JLabel();
-	element_label.setOpaque(false);
-	Dictionary.setText(element_label, "GEMS.Element");
-
-	JLabel file_label = new JLabel();
-	file_label.setOpaque(false);
-	Dictionary.setText(file_label, "GEMS.File");
-
-	JLabel set_label = new JLabel();
-	set_label.setOpaque(false);
-	Dictionary.setText(set_label, "GEMS.Set");
-
-	JLabel value_label = new JLabel();
-	value_label.setOpaque(false);
-	Dictionary.setText(value_label, "GEMS.Value");
-
-	JPanel inner_button_pane = new JPanel();
-	inner_button_pane.setOpaque(false);
+	element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes));
 
 	add_element_action_listener = new AddElementActionListener();
-	add_file_action_listener = new AddFileActionListener();
 	add_set_action_listener = new AddSetActionListener();
 	add_or_edit_attribute_action_listener = new AddOrEditAttributeActionListener();
 	remove_set_action_listener = new RemoveSetActionListener();
-
-	// Some blank panel
-	JPanel blank_pane = new JPanel();
-	blank_pane.setOpaque(false);
-	JPanel edit_file_pane = new JPanel();
-	edit_file_pane.setOpaque(false);
-	JPanel edit_element_pane = new JPanel();
-	edit_element_pane.setOpaque(false);
-	JPanel edit_set_pane = new JPanel();
-	edit_set_pane.setOpaque(false);
-
-	element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes));
-	subelement_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(subelement_attributes));
-	profile_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(profile_attributes));
-	set_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(set_attributes));
-	mds_tree.addTreeSelectionListener(new MDSTreeSelectionListener());
 
 	// Layout
@@ -450,4 +305,5 @@
 	mds_tree_pane.add(new JScrollPane(mds_tree), BorderLayout.CENTER);
 		  
+	//Set panes
 	set_name_pane.setLayout(new BorderLayout());
 	set_name_pane.add(set_name_label, BorderLayout.WEST);
@@ -455,5 +311,4 @@
 				
 	set_attributes_scroll.setViewportView(set_attributes);
-
 	set_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2)));
 	set_attributes_pane.setLayout(new BorderLayout());
@@ -464,59 +319,19 @@
 	set_details_pane.add(set_name_pane, BorderLayout.NORTH);
 	set_details_pane.add(set_attributes_pane, BorderLayout.CENTER);
-
-	element_name_pane.setLayout(new BorderLayout());
-	//element_name_pane.add(element_name_label, BorderLayout.WEST);
-	//element_name_pane.add(element_name, BorderLayout.CENTER);
-				
+		
+	//Element panes
 	element_attributes_scroll.setViewportView(element_attributes);
-
 	element_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2)));
 	element_attributes_pane.setLayout(new BorderLayout());
 	element_attributes_pane.add(element_attributes_scroll, BorderLayout.CENTER);
 		  
-	element_values_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Values")), BorderFactory.createEmptyBorder(2,2,2,2)));
-	element_values_pane.setLayout(new BorderLayout());
-	element_values_pane.add(new JScrollPane(element_values), BorderLayout.CENTER);
-	element_values_pane.setLayout(element_values_layout);
-	//element_values_pane.add(element_novalues_pane, BLANK);
-	//element_values_pane.add(new JScrollPane(element_values), VALUES);
-
 	element_inner_pane.setLayout(new BorderLayout());
 	element_inner_pane.add(element_attributes_pane);
-	//element_inner_pane.add(element_values_pane);
 		  
 	element_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Element_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
 	element_details_pane.setLayout(new BorderLayout());
-	//element_details_pane.add(element_name_pane, BorderLayout.NORTH);
 	element_details_pane.add(element_inner_pane, BorderLayout.CENTER);
-	
-	subelement_name_pane.setLayout(new BorderLayout());
-	subelement_attributes_scroll.setViewportView(subelement_attributes);
-	subelement_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2)));
-	subelement_attributes_pane.setLayout(new BorderLayout());
-	subelement_attributes_pane.add(subelement_attributes_scroll, BorderLayout.CENTER);
-	
-
-	subelement_inner_pane.setLayout(new BorderLayout());
-	subelement_inner_pane.add(subelement_attributes_pane);
-	subelement_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Subelement_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
-	subelement_details_pane.setLayout(new BorderLayout());
-	subelement_details_pane.add(subelement_inner_pane, BorderLayout.CENTER);
-	
-	profile_name_pane.setLayout(new BorderLayout());
-	profile_name_pane.add(profile_name_label, BorderLayout.WEST);
-	profile_name_pane.add(profile_name, BorderLayout.CENTER);
-
-	profile_attributes_scroll.setViewportView(profile_attributes);
-
-	profile_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Profiles")), BorderFactory.createEmptyBorder(2,2,2,2)));
-	profile_attributes_pane.setLayout(new BorderLayout());
-	profile_attributes_pane.add(profile_attributes_scroll, BorderLayout.CENTER);
-
-	profile_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Profile_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
-	profile_details_pane.setLayout(new BorderLayout());
-	//profile_details_pane.add(profile_name_pane, BorderLayout.NORTH);
-	profile_details_pane.add(profile_attributes_pane, BorderLayout.CENTER);
-
+
+	//General panes
 	details_pane.setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
 	details_pane.setLayout(card_layout);
@@ -524,25 +339,12 @@
 	details_pane.add(set_details_pane, SET);
 	details_pane.add(element_details_pane, ELEMENT);
-	details_pane.add(subelement_details_pane, SUBELEMENT);
-	details_pane.add(profile_details_pane, PROFILE);
 
 	upper_pane.setLayout(new BorderLayout());
 	upper_pane.add(mds_tree_pane, BorderLayout.WEST);
 	upper_pane.add(details_pane, BorderLayout.CENTER);
-		  
-	button_label_pane.setLayout(new GridLayout(4,1,0,2));
-	button_label_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,2));
-
-	inner_button_pane.setLayout(new GridLayout(4,3,0,2));		
-		  
-	button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
-	button_pane.setLayout(new BorderLayout());
-	//button_pane.add(button_label_pane, BorderLayout.WEST);
-	//button_pane.add(inner_button_pane, BorderLayout.CENTER);
 
 	content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
 	content_pane.setLayout(new BorderLayout());
 	content_pane.add(upper_pane, BorderLayout.CENTER);
-	content_pane.add(button_pane, BorderLayout.SOUTH);
 
 	// initialise the selection
@@ -628,5 +430,4 @@
 	    file_save.addActionListener(this);
 	    file_save.setMnemonic(KeyEvent.VK_S);
-	   // Dictionary.registerText(file_save, "GEMS.Menu.File_Save");
             Dictionary.registerText(file_save, "Menu.File_Save");
             
@@ -634,5 +435,4 @@
 	    file_delete.addActionListener(new KeyPressedHandler()); //KeyPressedHandler handles deleting stuff.
 	    file_delete.setMnemonic(KeyEvent.VK_S);
-	   // Dictionary.registerText(file_delete, "GEMS.Menu.File_Delete");
             Dictionary.registerText(file_delete, "Menu.File_Delete");
             
@@ -640,5 +440,4 @@
 	    file_preferences.addActionListener(this);
 	    file_preferences.setMnemonic(KeyEvent.VK_S);
-	    //Dictionary.registerText(file_preferences, "GEMS.Menu.File_Preferences");
             Dictionary.registerText(file_preferences, "Menu.File_Options");
 
@@ -678,5 +477,5 @@
 	    edit.add(edit_paste);
 
-	    // Help menu
+	    // Help menu. Is not used! --Matthew
 	    help = new JMenu();
 	    help.setIcon(Utility.HELP_ICON);
@@ -805,9 +604,5 @@
 	{
 	    String file_name = file.getName().toLowerCase();
-	    if (file_name.endsWith(".mds") || file_name.indexOf(".") == -1) {
-		return true;
-	    }
-
-	    return false;
+	    return(file_name.endsWith(".mds") || file_name.indexOf(".") == -1);
 	}
 
@@ -860,6 +655,4 @@
           exit();
        }
-       
-  
    }
    //called from MetadataSetManager...I don't think it should be here anymore, but for now it's ok
@@ -889,10 +682,6 @@
 	element_attributes = null;
 	set_attributes = null;
-	subelement_attributes = null;
-	element_name = null;
 	set_name = null;
-	element_values = null;
 	mds_tree = null;
-	target = null;
         
         popupListener = null;
@@ -916,21 +705,21 @@
        Class to handle adding or modifying element attributes.
      */
-   private class AddOrEditAttributeActionListener
+    private class AddOrEditAttributeActionListener
 	extends ModalDialog
 	implements ActionListener, MouseListener {
-       private boolean add_type = true;
-       private ComboArea value = null;
-       private JButton cancel_button = null;
-       private JButton ok_button = null;
-       private JComboBox language_box = null;
-       private GComboBox name = null;
-       private HashMap name_to_values = null;
-       private JLabel target = null;
-       private JLabel target_label = null;
-       private Vector attributeLists = null;      
-       
+	private boolean add_type = true;
+	private ComboArea value = null;
+	private JButton cancel_button = null;
+	private JButton ok_button = null;
+	private JComboBox language_box = null;
+	private GComboBox name = null;
+	private HashMap name_to_values = null;
+	private JLabel target = null;
+	private JLabel target_label = null;
+	private Vector attributeLists = null;      
+	
         //org.w3c.dom.Document lang = Utility.parse("/home/arosmain/gsdl/gli/classes/xml/languages.xml", false);
-          org.w3c.dom.Document lang = Utility.parse(Configuration.gsdl_path + "/gli/classes/xml/languages.xml", false);
-          
+	org.w3c.dom.Document lang = Utility.parse(Configuration.gsdl_path + "/gli/classes/xml/languages.xml", false);
+	
 	/** Constructor. */
 	public AddOrEditAttributeActionListener() {
@@ -938,10 +727,9 @@
 	    setModal(true);
             attributeLists = new Vector();
-            //
             attributeLists.add("identifier");
             attributeLists.add("comment");
             attributeLists.add("definition");
             attributeLists.add("name");
-            
+
             attributeLists.add("creator");
             attributeLists.add("date");
@@ -1009,4 +797,5 @@
 	    ok_button = new GLIButton();
 	    ok_button.setMnemonic(KeyEvent.VK_O);
+	    getRootPane().setDefaultButton(ok_button);
 	    Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
 	    cancel_button = new GLIButton();
@@ -1073,5 +862,5 @@
        public void mouseClicked(MouseEvent e)
 	{
-	    if(e.getSource() == element_attributes || e.getSource() == set_attributes || e.getSource() == subelement_attributes)
+	    if(e.getSource() == element_attributes || e.getSource() == set_attributes)
 		{
 		    if(e.getClickCount() == 2) //Double click
@@ -1083,20 +872,9 @@
 		}
 	}
-	//required by MouseListener
-	public void mouseEntered(MouseEvent e)
-	{
-	}
-	//required by MouseListener
-	public void mouseExited(MouseEvent e)
-	{
-	}
-	//required by MouseListener
-	public void mousePressed(MouseEvent e)
-	{
-	}
-	//required by MouseListener
-	public void mouseReleased(MouseEvent e)
-	{
-	}
+	//These methods are required by interface MouseListener
+	public void mouseEntered(MouseEvent e){}
+	public void mouseExited(MouseEvent e){}
+	public void mousePressed(MouseEvent e){}
+	public void mouseReleased(MouseEvent e){}
 
 	/** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to add a new attribute to the selected set or element.
@@ -1105,8 +883,5 @@
 	public void actionPerformed(ActionEvent event) {
 	    Object source = event.getSource();
-            AttributeTableModel tablemodel = null;
 	    AttributeTableModel model = null;
-            String prevLang = new String("");
-            String prevValue = new String("");
            
 	    if(current_element != null)
@@ -1120,9 +895,4 @@
 		    target.setText(current_set.toString());
 		    Dictionary.setText(target_label, "GEMS.Target");
-		}
-	    else if(current_subelement != null)
-		{
-		    target.setText(current_subelement.getName());
-		    Dictionary.setText(target_label, "GEMS.Subelement");
 		}
 	    
@@ -1135,14 +905,9 @@
 		boolean success = true;
 
-		// Add or edit a collect/set/element attribute
+		// Add or edit a set/element attribute
 		switch(current_attribute_type) {
-		case GEMSNode.COLLECTION:
-		    model = (AttributeTableModel) profile_attributes.getModel();
-		    success = addOrEditCollectionAttribute(model);
-		    break;
 		case GEMSNode.SET:
 		    model = (AttributeTableModel) set_attributes.getModel();
-		    success = addOrEditSetAttribute(model);	
-                   
+		    success = addOrEditSetAttribute(model);
 		    break;
 		case GEMSNode.ELEMENT:
@@ -1150,15 +915,8 @@
 		    success = addOrEditElementAttribute(model);
 		    break;
-		    
-		case GEMSNode.SUBELEMENT:
-		    model = (AttributeTableModel) subelement_attributes.getModel();
-		    success = addOrEditSubelementAttribute(model);
-		    break;
-		    
 		}
                  
 		if (success) {
 		    // Hide dialog
-                
 		    atLeastOneSetChanged = true;
 		    setVisible(false);
@@ -1180,7 +938,4 @@
 		if(object != null) {
 		    java.util.List values = (java.util.List) name_to_values.get(object.toString());
-		    if(values == null && current_attribute_type==GEMSNode.COLLECTION) { 
-			values = msm.getElements();
-		    }
                     
                     if(value != null && values != null){
@@ -1192,5 +947,5 @@
 		}
 	    }
-	    else if (source == popupListener.menuAddAttributeAttribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement || source == popupListener.menuAddAttributeSubelement){
+	    else if (source == popupListener.menuAddAttributeAttribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement){
 
 		Dictionary.setText(this, "GEMS.AddAttribute");
@@ -1199,130 +954,8 @@
                     
 		}
-
-		
 		name.setEnabled(true);
 		setVisible(true);
             }
-           /* else if (source == popupListener.menuAddAttributeAttribute){
-                System.out.println("add attr\n");
-                
-                name.setEnabled(true);
-                
-            }*/
-          /* else{
-		// Name combo box is enabled except when attributes are edited
-		//name.setEnabled((source != popupListener.menuEditValue));
-                //System.out.println("elsed");
-		name_to_values.clear();
-		name.clear();
-		value.clear();
-		value.setText("");
-		// Build the correct name_to_values mapping
-		// Attributes are slightly tricky as they can come from several sources. Has a collection file been selected...
-		if(current_collection_file != null) {
-		    target.setText(current_collection_file);
-		    // Name is empty in this one, however values must be the current elements in the collection.						  
-		    language_box.setEnabled(false);
-		}
-		// or has an element been selected
-		else if(current_element != null) {
-		    target.setText(current_element.toString());
-		    // Develop a model for name based on known attributes from all other elements.
-		    java.util.List elements = msm.getElements();
-		    for(int i = 0; i < elements.size(); i++) {
-			ElementWrapper element = (ElementWrapper) elements.get(i);
-			TreeSet attributes = element.getAttributes();
-			for(Iterator attribute_iterator = attributes.iterator(); attribute_iterator.hasNext(); ) {
-			    Attribute attribute = (Attribute) attribute_iterator.next();
-			    java.util.List values = (java.util.List) name_to_values.get(attribute.name);
-			    if(values == null) {
-				values = new ArrayList();
-				name_to_values.put(attribute.name, values);
-			    }
-			    if(!values.contains(attribute.value)) {
-				values.add(attribute.value);
-			    }
-			    values = null;
-			    attribute = null;
-			}
-			attributes = null;
-			element = null;
-		    }
-		    elements = null;
-		    language_box.setEnabled(true);
-		}
-		else if(current_set != null) {
-		    target.setText(current_set.toString());
-		    // Develop a model for name based on known attributes from all other metadata sets. At the same time build a hashmap mapping attribute name to lists of values.
-		    java.util.List sets = msm.getSets();
-		    for(int i = 0; i < sets.size(); i++) {
-			MetadataSet set = (MetadataSet) sets.get(i);
-			NamedNodeMap attributes = set.getAttributes();
-			for(int j = 0; j < attributes.getLength(); j++) {
-			    Attr attribute = (Attr) attributes.item(j);
-			    String name_str = attribute.getName();
-			    String value_str = attribute.getValue();
-			    java.util.List values = (java.util.List) name_to_values.get(name_str);
-			    if(values == null) {
-				values = new ArrayList();
-				name_to_values.put(name_str, values);
-			    }
-			    if(!values.contains(value_str)) {
-				values.add(value_str);
-			    }
-			    values = null;
-			    value_str = null;
-			    name_str = null;
-			    attribute = null;
-			}
-			attributes = null;
-			set = null;
-			language_box.setEnabled(false);
-		    }
-		    sets = null;
-		    // If this is an add remove all the attributes already present in the current set.
-		    if(source == add_attribute) {
-			name.setEnabled(true);
-			NamedNodeMap attributes = current_set.getAttributes();
-			for(int i = 0; i < attributes.getLength(); i++) {
-			    Attr attribute = (Attr) attributes.item(i);
-			    String name_str = attribute.getName();
-			    name_to_values.remove(name_str);
-			    name_str = null;
-			    attribute = null;
-			}
-			attributes = null;
-		    }
-		}
-		// Otherwise we actually disable the name combobox
-		else {
-		    name.setEnabled(false);
-		}
-		// Now name_to_values should contain a list of unique attribute names each mapping to a list of attribute values.
-		for(Iterator name_iterator = name_to_values.keySet().iterator(); name_iterator.hasNext(); ) {
-		    name.add(name_iterator.next());
-		}
-		// Now pritty up the dialog depending on the action type
-		if(source == add_attribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement || source == popupListener.menuAddAttributeAttribute) {
-		    add_type = true;
-		    Dictionary.setText(this, "GEMS.AddAttribute");
-		    if(current_collection_file != null) {
-			// Name is empty in this one, however values must be the current elements in the collection.	
-			java.util.List values = msm.getElements();
-			for(int i = 0; i < values.size(); i++) {
-			    value.add(new NameElementWrapperEntry(values.get(i)));
-			}
-			values = null;
-		    }
-		    setVisible(true);
-		}*/
-               // else if(source == popupListener.menuAddAttributeAttribute){
-                    
-                //    System.out.println("fromattrib table");
-               // }
-               // else if(source == popupListener.menuAddAttributeElement){
-                    
-                 //   System.out.println("from elements");
-               // }*/
+           
 		else if(current_attribute != -1) {
 		    this.editAttribute();
@@ -1342,8 +975,4 @@
 	   //grab the table model based on what is currently selected
 	   switch(current_attribute_type) {
-	   case GEMSNode.COLLECTION:
-	       tablemodel = (AttributeTableModel) profile_attributes.getModel();
-	       
-	       break;
 	   case GEMSNode.SET:
 	       tablemodel = (AttributeTableModel) set_attributes.getModel();
@@ -1360,12 +989,4 @@
 	       
 	       break;
-	       
-	   case GEMSNode.SUBELEMENT:
-	       tablemodel = (AttributeTableModel) subelement_attributes.getModel();
-	       //grab values in table
-	       prevLang =  tablemodel.getValueAt(current_attribute,1).toString();
-	       prevValue = tablemodel.getValueAt(current_attribute,2).toString();
-	       break;
-	       
 	   default:
 	       //by default grab element_attr's
@@ -1407,15 +1028,7 @@
 	   
 	   switch(current_attribute_type) {
-	   case GEMSNode.COLLECTION:
-	       model = (AttributeTableModel) profile_attributes.getModel();
-	       break;
 	   case GEMSNode.ELEMENT:
 	       model = (AttributeTableModel) element_attributes.getModel();
 	       break;
-	       
-	   case GEMSNode.SUBELEMENT:
-	       model = (AttributeTableModel) subelement_attributes.getModel();
-	       break;
-	       
 	   case GEMSNode.SET:
 	       model = (AttributeTableModel) set_attributes.getModel();
@@ -1449,36 +1062,4 @@
        }
 
-       //Is this method ever used? What's a collection attribute? --Matthew
-	private boolean addOrEditCollectionAttribute(AttributeTableModel model)
-	{
-	    System.err.println("addOrEditCollectionAttribute was actually used!!"); //if this is ever used!!
-	    String name_str = name.getSelectedItem().toString();
-	    String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
-
-	    // Remove the existing attribute if this is an edit
-	    if(!add_type && current_attribute != -1) {
-		String old_source = (String) model.getValueAt(current_attribute, 0);
-		old_source = null;
-		model.removeRow(current_attribute);
-	    }
-
-	    boolean cont = true;
-	    // Check that there isn't already an entry for this attribute
-	    if (!model.contains(name_str, 0)) {
-		// Update attribute table
-		model.add(new Attribute(name_str, value_str));
-	    }
-	    // Otherwise show an error message and do not proceed
-	    else {
-		cont = false;
-		JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
-	    }
-
-	    value_str = null;
-	    name_str = null;
-	    return cont;
-	}
-
-
 	private boolean addOrEditSetAttribute(AttributeTableModel model)
 	{
@@ -1553,4 +1134,5 @@
 
 		    // Add the new attribute
+		    //System.err.println("current_element is: " + current_element.toString()); //debug
 		    current_element.addAttribute(new_name_str, language_code, value_str);
 		    // Update the attribute table
@@ -1571,156 +1153,17 @@
 	    return cont;
 	}
-       
-       //Very similar to addOrEditElementAttribute
-       private boolean addOrEditSubelementAttribute(AttributeTableModel model)
-       {
-	   String new_name_str = name.getSelectedItem().toString();
-	   String old_name_str = null;
-	   String language_code = (String) language_box.getSelectedItem();
-	   String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
-	   String old_value_str = null;
-	   String old_lang_code = null;
-	   boolean edit = false;
-	   boolean cont = false;
-
-	   if(!add_type && current_attribute != -1) //An edit
-	       {
-		   Attribute old_attribute = model.getAttribute(current_attribute);
-		   old_value_str = old_attribute.value;
-		   old_lang_code = old_attribute.language;
-		   old_name_str = (String) subelement_attributes.getValueAt(current_attribute, 0); //get the old name.
-		   edit = true;
-	       }
-	   
-	   //Check that there isn't already an entry for this attribute
-	   if (!model.contains(new_name_str, 0) || (edit && new_name_str.equals(old_name_str)))
-	       {
-		    if(edit) //If this is an edit, remove the old attribute
-			{
-			    current_subelement.removeAttribute(old_name_str, old_lang_code, old_value_str);
-			    model.removeRow(current_attribute);
-			}
-
-		   // Add the new attribute
-		   current_subelement.addAttribute(new_name_str, language_code, value_str);
-		   // Update the attribute table
-		   int row = model.add(new Attribute(new_name_str, language_code, value_str));
-		   subelement_attributes.setRowSelectionInterval(row, row);
-		   cont = true;
-	       }
-	   // Otherwise show an error message and do not proceed
-	   else
-	       {
-		   cont = false;
-		   JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
-	       } 
-	   
-	   value_str = null;
-	   language_code = null;
-	   new_name_str = null;
-	   return cont;
-       }
-
-
-	public void dispose() {
-	    cancel_button = null;
-	    name = null;
-	    name_to_values = null;
-	    ok_button = null;
-	    target = null;
-	    value = null;
-	    super.dispose();
-	}
     }
 
-
-    private class AddSubelementActionListener extends ModalDialog implements ActionListener {
-	private JButton cancel_button = null;
-	private JButton ok_button = null;
-	private JLabel element_field = null;
-	private NonWhitespaceField name_field = null;
+   
+    private class AddSubelementActionListener extends AddElementActionListener implements ActionListener {
 
 	public AddSubelementActionListener() {
-	    super(self);
-	    setModal(true);
-	    setSize(ADD_ELEMENT_SIZE);
-	    // Creation
-	    JPanel content_pane = (JPanel) getContentPane();
-	    content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
-	    JPanel center_pane = new JPanel();
-	    center_pane.setOpaque(false);
 	    Dictionary.setText(this, "GEMS.Popup.menuAddSubelement");
-
-	    JPanel labels_pane = new JPanel();
-	    labels_pane.setOpaque(false);
-	    JLabel element_label = new JLabel();
-	    element_label.setOpaque(false);
-	    Dictionary.setText(element_label, "GEMS.Element");
-	    element_field = new JLabel();
-	    element_field.setOpaque(false);
-
-	    JPanel values_pane = new JPanel();
-	    values_pane.setOpaque(false);
-	    JLabel name_label = new JLabel();
-	    name_label.setOpaque(false);
-	    Dictionary.setText(name_label, "GEMS.Name");
-	    name_field = new NonWhitespaceField();
-	    name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
-	    name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
-	    name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
-	    name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
 	    Dictionary.setTooltip(name_field, "GEMS.Subelement_Name_Tooltip");
-
-	    JPanel button_pane = new JPanel();
-	    button_pane.setOpaque(false);
-
-	    ok_button = new GLIButton();
-	    ok_button.setMnemonic(KeyEvent.VK_O);
-	    getRootPane().setDefaultButton(ok_button);
-	    Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
-	    cancel_button = new GLIButton();
-	    cancel_button.setMnemonic(KeyEvent.VK_C);
-	    Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
-
-	    TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
-
-	    // Connection
-	    cancel_button.addActionListener(this);
-	    ok_button.addActionListener(this);
-	    ok_button_enabler.add(name_field);
-
-	    // Layout
-	    labels_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
-	    labels_pane.setLayout(new GridLayout(2,1));
-	    labels_pane.add(element_label);
-	    labels_pane.add(name_label);
-
-	    values_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
-	    values_pane.setLayout(new GridLayout(2,1));
-	    values_pane.add(element_field);
-	    values_pane.add(name_field);
-
-	    center_pane.setLayout(new BorderLayout(5,5));
-	    center_pane.add(labels_pane, BorderLayout.WEST);
-	    center_pane.add(values_pane, BorderLayout.CENTER);
-
-	    button_pane.setLayout(new GridLayout(1,2,0,5));
-	    button_pane.add(ok_button);
-	    button_pane.add(cancel_button);
-
-	    content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
-	    content_pane.setLayout(new BorderLayout());
-	    content_pane.add(center_pane, BorderLayout.CENTER);
-	    content_pane.add(button_pane, BorderLayout.SOUTH);
-
-	    //use size of Add Element dialog
-	    setLocation((config.screen_size.width - ADD_ELEMENT_SIZE.width) / 2, (config.screen_size.height - ADD_ELEMENT_SIZE.height) / 2);
 	}
 
 	public void actionPerformed(ActionEvent event)
 	{
-	    //System.err.println("You chose to add a new subelement!!\n"); //debug
 	    Object source = event.getSource();
-	    GEMSNode new_node = null;
 	    current_element = current_node.getElement(); //current_element here is used generically for a element or subelement.
 
@@ -1728,7 +1171,5 @@
 		{
 		    String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
-		    
 		    current_set = msm.getSet(current_element.getNamespace());
-		    //System.err.println("current_element.getNamespace(): " + current_element.getNamespace()); //debug
 		    if(current_set != null)
 			{
@@ -1740,9 +1181,13 @@
 				    ElementWrapper subelement = current_set.addElement(name_str, language_code, current_node);
 
-				    // Then update the tree
-				    new_node = model.add(current_node, subelement, GEMSNode.SUBELEMENT);
-				    //Expand element so can see subelement.
-				    mds_tree.expandPath(new TreePath(current_node.getPath()));
-				    //Would like to select new subelement, but this doesn't seem to work.
+				    final GEMSNode new_node = model.add(current_node, subelement, GEMSNode.ELEMENT); //Then update the tree.
+				   
+				    //SwingUtilities.invokeLater is used so that expandPath works on new parents.
+				    SwingUtilities.invokeLater(new Runnable() {
+					    public void run() {
+						mds_tree.expandPath(new TreePath(current_node.getPath())); //Expand element so can see subelement.
+						mds_tree.getSelectionModel().setSelectionPath(new TreePath(new_node)); //works, but node on tree doesn't look hilighted!!
+					    }
+					});
 
 				    //Done. Finish up.
@@ -1769,5 +1214,5 @@
 	    else
 		{
-		    element_field.setText(current_node.toString()); //set to the name of the element
+		    set_field.setText(current_node.toString()); //set to the name of the subelement
 		    name_field.setText("");
 		    setVisible(true);
@@ -1780,5 +1225,5 @@
 	    ok_button = null;
 	    name_field = null;
-	    element_field = null;
+	    set_field = null;
 	    super.dispose();
 	}
@@ -1789,8 +1234,8 @@
 	extends ModalDialog
 	implements ActionListener {
-	private JButton cancel_button = null;
-	private JButton ok_button = null;
-	private JLabel set_field = null;
-	private NonWhitespaceField name_field = null;
+	protected JButton cancel_button = null;
+	protected JButton ok_button = null;
+	protected JLabel set_field = null;
+	protected NonWhitespaceField name_field = null;
 	public AddElementActionListener() {
 	    super(self);
@@ -1882,8 +1327,14 @@
 		    String language_code = config.getLanguage();
 		    ElementWrapper element = current_set.addElement(name_str, language_code, null);
+
 		    // Then update the tree
 		    model.add(current_node, element, GEMSNode.ELEMENT);
-		    mds_tree.expandPath(new TreePath(current_node.getPath())); //expand set.
-
+		    //SwingUtilities.invokeLater is used so that expandPath works on new parents.
+		    SwingUtilities.invokeLater(new Runnable() {
+			    public void run() {
+				mds_tree.expandPath(new TreePath(current_node.getPath())); //expand set.
+			    }
+			});
+		    
 		    // Done
 		    element = null;
@@ -1929,124 +1380,9 @@
 	    name_field = null;
 	    set_field = null;
-	    ///ystem.err.println("Dispose AddElementActionListener");
 	    super.dispose();
 	}
     }
 	 
-    private class AddFileActionListener
-	extends ModalDialog
-	implements ActionListener {
-	private JButton cancel_button = null;
-	private JButton ok_button = null;
-	private JTextField name_field = null;
-	public AddFileActionListener() {
-	    super(self);
-	    setModal(true);
-	    setSize(ADD_FILE_SIZE);
-	    // Creation
-	    JPanel content_pane = (JPanel) getContentPane();
-	    content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
-	    JPanel center_pane = new JPanel();
-	    center_pane.setOpaque(false);
-	    JPanel profile_pane = new JPanel();
-	    profile_pane.setOpaque(false);
-	    JLabel profile_label = new JLabel();
-	    profile_label.setOpaque(false);
-	    Dictionary.setText(profile_label, "GEMS.Profile");
-
-	    JPanel name_pane = new JPanel();
-	    name_pane.setOpaque(false);
-	    JLabel name_label = new JLabel();
-	    name_label.setOpaque(false);
-	    Dictionary.setText(name_label, "GEMS.Name");
-	    name_field = new JTextField();
-	    name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
-	    name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
-	    name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
-	    name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
-	    Dictionary.setTooltip(name_field, "GEMS.Profile_Name_Tooltip"); 
-
-	    JPanel button_pane = new JPanel();
-	    button_pane.setOpaque(false);
-
-	    ok_button = new GLIButton();
-	    ok_button.setMnemonic(KeyEvent.VK_O);
-	    Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
-	    cancel_button = new GLIButton();
-	    cancel_button.setMnemonic(KeyEvent.VK_C);
-	    Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
-
-	    TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
-
-	    // Connection
-	    cancel_button.addActionListener(this);
-	    ok_button.addActionListener(this);
-	    ok_button_enabler.add(name_field);
-
-	    // Layout
-	    profile_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
-	    profile_pane.setLayout(new BorderLayout());
-	    profile_pane.add(profile_label, BorderLayout.CENTER);
-
-	    name_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
-	    name_pane.setLayout(new BorderLayout(5,0));
-	    name_pane.add(name_label, BorderLayout.WEST);
-	    name_pane.add(name_field, BorderLayout.CENTER);
-
-	    center_pane.setLayout(new GridLayout(2,1,0,0));
-	    center_pane.add(profile_pane);
-	    center_pane.add(name_pane);
-
-	    button_pane.setLayout(new GridLayout(1,2,0,5));
-	    button_pane.add(ok_button);
-	    button_pane.add(cancel_button);
-
-	    content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
-	    content_pane.setLayout(new BorderLayout());
-	    content_pane.add(center_pane, BorderLayout.CENTER);
-	    content_pane.add(button_pane, BorderLayout.SOUTH);
-
-	    setLocation((config.screen_size.width - ADD_FILE_SIZE.width) / 2, (config.screen_size.height - ADD_FILE_SIZE.height) / 2);
-	}
-	/** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
-	 * @param event An <strong>ActionEvent</strong> containing information about the event.
-	 */
-	public void actionPerformed(ActionEvent event) {
-	    Object source = event.getSource();
-	    if(source == ok_button) {
-		String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
-		// Ensure that this source doesn't already exist.
-// 		if(!msm.profiler.containsSource(name_str)) {
-// 		    // Add source with empty hashmap of actions.
-// 		    msm.profiler.addSource(name_str);
-// 		    // Add to tree
-// 		    model.add(model.getProfileNode(), name_str, GEMSNode.COLLECTION);
-// 		    setVisible(false);
-// 		}
-		// Otherwise warn the user and don't hide the prompt.
-		// else {
-		JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.File_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
-		// }
-		name_str = null;
-	    }
-	    else if(source == cancel_button) {
-		setVisible(false);
-	    }
-	    else {
-		name_field.setText("");
-		setVisible(true);
-	    }
-	    source = null;
-	}
-
-	public void dispose() {
-	    cancel_button = null;
-	    ok_button = null;
-	    name_field = null;
-	    ///ystem.err.println("Dispose AddFileActionListener");
-	    super.dispose();
-	}
-    }
-
+   
     private class AddSetActionListener
 	extends ModalDialog
@@ -2135,5 +1471,4 @@
             //add sets to existingSetJComboBox
             
-            //String tempstr = new String();
             JLabel dummyl = new JLabel();
             Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit");
@@ -2180,6 +1515,4 @@
 	    Object source = event.getSource();
             
-            
-          // if(a_set_exists_with_this_namespace(namespace_field.getText()) == false){
 	    if(source == ok_button) {
                 //this code below handles whether we inherit from an existing set or not
@@ -2289,5 +1622,4 @@
 	    ok_button = null;
 	    name_field = null;
-	    ///ystem.err.println("Dispose AddSetActionListener");
 	    super.dispose();
 	}
@@ -2327,5 +1659,5 @@
 	    cancel_button.setMnemonic(KeyEvent.VK_C);
 	    Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
-	    TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
+	    //TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
 
 	    // Connection
@@ -2339,6 +1671,4 @@
             Dictionary.setText(inheritJLabel, "GEMS.inheritMetadataSet");
 	   
-            int getSetsLen = msm.getSets().toArray().length;
-            Vector theSets = msm.getSets();
             File[] col_dir = new File(Configuration.gsdl_path + "/collect").listFiles();
             
@@ -2358,5 +1688,4 @@
             
             existingSetJComboBox.setSelectedIndex(0);
-            //String tempstr = new String();
             JLabel dummyl = new JLabel();
             Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit");
@@ -2416,5 +1745,4 @@
 	    }
 	    else {
-		//name_field.setText("");
 		setVisible(true);
 	    }
@@ -2427,28 +1755,8 @@
 	}
     }
-    
-
-
-    /** This listener is responsible for keeping the root node of a value tree expanded where and when possible. */
-    private class KeepTreeRootExpandedListener
-	implements TreeModelListener {
-	/** Invoked after a node (or a set of siblings) has changed in some way. */
-	public void treeNodesChanged(TreeModelEvent e) {
-	}
-        /** Invoked after nodes have been inserted into the tree. */
-	public void treeNodesInserted(TreeModelEvent e) {
-	    //  if(element_values != null && element_values.getModel() != null && element_values.getModel().getRoot() != null) {
-	    //	element_values.expandPath(new TreePath(element_values.getModel().getRoot()));
-	    //  }
-	}
-	/** Invoked after nodes have been removed from the tree. */
-	public void treeNodesRemoved(TreeModelEvent e) {
-	}
-	/** Invoked after the tree has drastically changed structure from a given node down. */
-	public void treeStructureChanged(TreeModelEvent e) {
-	    // element_values.expandPath(new TreePath(element_values.getModel().getRoot()));
-	} 
-    }
-
+
+    /*
+      Class to handle removing set or element attributes.
+    */
     private class RemoveAttributeActionListener
 	implements ActionListener, KeyListener {
@@ -2457,4 +1765,5 @@
 	   Any implementation of KeyListener must include these mothods.
 	   When the DELETE key is pressed, fire the actionPerformed event.
+	   @param e A <strong>KeyEvent</strong> containing information about the event.
 	*/
 	public void keyTyped(KeyEvent e){
@@ -2466,5 +1775,5 @@
 			{
 			    //DELETE key pressed
-			    actionPerformed((ActionEvent)null);
+			    actionPerformed((ActionEvent)null); //is there a better way?
 			}
 		}
@@ -2482,16 +1791,7 @@
 		if(result == 0) {
 		    ignore = true;
-		    // Attributes are tricky little beasties, as they can come from several different places and depend upon what other little beasties have been selected
-		    // Has a collection file been selected...
-		    if(current_collection_file != null) {
-			// Remove a profile
-			String source = (String) profile_attributes.getValueAt(current_attribute, 0);
-			// !!! msm.profiler.removeAction(current_collection_file, source);
-			source = null;
-			// Refresh table
-			((AttributeTableModel)profile_attributes.getModel()).removeRow(current_attribute);
-		    }
-		    // or has an element been selected
-		    else if(current_element != null) {
+		    //Attributes are tricky little beasties, as they can come from several different places and depend upon what other little beasties have been selected
+		    //Has an element been selected
+		    if(current_element != null) {
 			// Remove element attribute
 			String name = (String) element_attributes.getValueAt(current_attribute, 0);
@@ -2510,18 +1810,7 @@
 			((AttributeTableModel)set_attributes.getModel()).removeRow(current_attribute);
 		    }
-		    else if(current_subelement != null)
-			{
-			    //Remove subelement attribute
-			    String name = (String)subelement_attributes.getValueAt(current_attribute, 0);
-			    String language = (String) subelement_attributes.getValueAt(current_attribute, 1);
-			    String value = (String) subelement_attributes.getValueAt(current_attribute, 2);
-			    current_subelement.removeAttribute(name, language, value);
-
-			    //Refresh table
-			    ((AttributeTableModel)subelement_attributes.getModel()).removeRow(current_attribute);
-			}
 		    ignore = false;
                     
-                     atLeastOneSetChanged= true;
+		    atLeastOneSetChanged= true;
 		}
 	    }
@@ -2533,46 +1822,9 @@
     }
 
-    /**
-       Class to handle deletion of subelements.
-       This class can be created from either PopupHandler or KeyPressedHandler. KeyPressedHandler passes a null ActionEvent!!
-       @author: Matthew Whyte
-       @Date last modified: 18/01/05
-                            25/01/05
-    */
-    private class RemoveSubelementActionListener implements ActionListener {
-	/** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to provide an editing prompt.
-	 * @param event An <strong>ActionEvent</strong> containing information about the event.
-	 */
-	public void actionPerformed(ActionEvent event)
-	{
-	    if(current_subelement != null)
-		{
-		    int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.Subelement")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
-		    if(result ==0) //Continue with remove
-			{
-			    TreeNode selPath = current_node.getParent();
-			    GEMSNode parent = (GEMSNode)selPath;
-			    current_element = parent.getElement();
-
-			    ignore = true;
-			    msm.removeElement(current_subelement, current_element); //remove the subelement.
-
-			    // Clear selection
-			    mds_tree.clearSelection();
-			    model.remove(current_node); //This is the new way of doing things :-) 
-			    card_layout.show(details_pane, BLANK); //Show a blank panel.
-			    ignore = false;
-			    
-			    atLeastOneSetChanged = true;
-			}
-		}
-	    else
-		{
-		    System.err.println("No subelement is selected."); //This should not happen
-		}
-	}
-
-    }
-
+    /*
+      Class to handle deletion of elements (including subelements).
+
+      Last modified 2/02/05 by Matthew Whyte
+     */
     private class RemoveElementActionListener
 	implements ActionListener {
@@ -2587,13 +1839,14 @@
 		// Remove this attribute
 		if(result == 0) {
+		    //Get the parent element
+		    GEMSNode parent_node = (GEMSNode)current_node.getParent();
+		    ElementWrapper parent_wrapped = parent_node.getElement();
+
 		    ignore = true;
-		    //System.err.println("Current element's getElement: " + current_element.getElement()); //Debug
-		    msm.removeElement(current_element, null);
+		    msm.removeElement(current_element, parent_wrapped);
 		    // Clear selection
 		    mds_tree.clearSelection();
-		    model.remove(current_element.getName(), GEMSNode.ELEMENT); //Need to use .getName() not .toString!!
-
-		    // Meanwhile disable/enable controls given we had an element selected, but no longer do.
-		    //remove_element.setEnabled(false);
+		    model.remove(current_node);
+
 		    // Show a blank panel.
 		    card_layout.show(details_pane, BLANK);
@@ -2604,34 +1857,8 @@
 	    }
 	    else {
-		///ystem.err.println("No current element selected.");
+		System.err.println("No element currently selected."); //This should not happen!
 	    }
 	}
     }
-
- 
-
-
-    private class RemoveFileActionListener
-	implements ActionListener {
-	/** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to provide an editing prompt.
-	 * @param event An <strong>ActionEvent</strong> containing information about the event.
-	 */
-	public void actionPerformed(ActionEvent event) {
-	    if(current_collection_file != null) {
-		int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.File")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
-		// Remove the current collection file profile from the profiler.
-		if(result == 0) {
-		    ignore = true;
- 
-		    // Clear selection
-		    mds_tree.clearSelection();
-		    model.remove(current_collection_file, GEMSNode.COLLECTION);
-		    card_layout.show(details_pane, BLANK); //Show a blank panel.
-		    ignore = false;
-		}
-	    }
-	}
-    }
-
 
 
@@ -2639,5 +1866,5 @@
        Class to handle renaming of a set and/or it's namespace.
 
-       Author: Matthew Whyte
+       @author: Matthew Whyte
        Date last modified: 10/01/05
     */
@@ -2736,5 +1963,4 @@
                 }
             }
-            
             return flag;
         }
@@ -2761,5 +1987,5 @@
 			    //Hide the set that are about to rename
 			    mds_tree.clearSelection();
-			    model.remove(current_set.toString(), GEMSNode.SET);
+			    model.remove(current_node);
 
 			    //Rename set & namespace
@@ -2809,71 +2035,10 @@
     }
 
-    /**
-       Class to handle renaming of a subelement
-
-       Author: Matthew Whyte
-       Date last modified: 18/01/05
-     */
-    private class RenameSubelementActionListener extends RenameElementActionListener implements ActionListener {
-	
-	/**
-	   Any implementation of ActionListener must include this method so that we can be informed when an action has occured.
-	   @param event An <string>ActionEvent</strong> containing information about the event.
-	*/
-	public void actionPerformed(ActionEvent event)
-	{
-	    Object source = event.getSource();
-
-	    if(source == ok_button)
-		{
-		    TreeNode selPath = current_node.getParent();
-		    GEMSNode parent = (GEMSNode)selPath;
-		    current_element = parent.getElement();
-		    //MetadataSet currentSet = msm.getSet(current_subelement.getNamespace());
-		    String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
-
-			if(!current_element.containsSubelement(name_str)) //Hopefully this works!
-			    {   
-				//Hide the element that are about to rename
-				mds_tree.clearSelection();
-				model.remove(current_node);
-				
-				msm.renameElement(current_subelement, name_str); //rename the element
-				model.add(parent, current_subelement, GEMSNode.SUBELEMENT);
-
-				//Finish up
-				ignore = false;    
-				atLeastOneSetChanged = true;
-				setVisible(false);
-			    }
-		    
-		    // Otherwise show an error message and do not proceed.
-			else
-			    {
-				JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Subelement_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
-			    }
-
-		    name_str = null;
-		}
-	    
-	    else if(source == cancel_button)
-		{
-		    setVisible(false); //hide dialog
-		}
-	    else
-		{
-		    Dictionary.setText(this, "GEMS.Popup.menuRenameSubelement"); //Set title of dialog
-		    name_field.setText(current_subelement.getNameOnly()); //show old name
-		    setVisible(true); //Show the dialog
-		}
-		    
-	    source = null;
-	}
-    }
+   
 
  /**
        Class to handle renaming of an element.
 
-       Author: Matthew Whyte
+       @author: Matthew Whyte
        Date last modified: 10/01/05
     */
@@ -2970,31 +2135,20 @@
 		    TreeNode selPath = current_node.getParent();
 		    GEMSNode parent = (GEMSNode)selPath;
-		    GEMSNode new_node = null;
 		    MetadataSet currentSet = msm.getSet(current_element.getNamespace());
 		    String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
-		    GValueModel value_model = msm.getValueTree(current_element);
-  
+		    GEMSNode new_node = null;
+
 		    // If this element doesn't already exist.
 		    if(!currentSet.containsElement(name_str)) //Do the renaming!
 			{   
-			    //Hide the element that are about to rename
-			    //mds_tree.clearSelection();
-			    model.remove(current_element.getName(), GEMSNode.ELEMENT);
+			    model.remove(current_node); //Hide the element that are about to rename
+			    msm.renameElement(current_element, name_str); //rename the element
+			    //Add the new element
+			    new_node = model.add(parent, current_element, GEMSNode.ELEMENT);
 			    
-			    msm.renameElement(current_element, name_str); //rename the element
+			    //mds_tree.setSelectionPath(new_node_path); //would like to do this but doesn't hilight tree :-(
+			    card_layout.show(details_pane, BLANK); // Show a blank panel.
 			    
-			    new_node = model.add(parent, current_element, GEMSNode.ELEMENT);
-			    TreePath new_node_path = new TreePath(new_node.getPath());
-
-			    value_model.nodeChanged((TreeNode)current_node); //trial!
-			    value_model.nodeStructureChanged((TreeNode)current_node);
-			    mds_tree.repaint();
-
-			    //mds_tree.setSelectionPath(new_node_path);
-			    //Could now select the new element, but for now will just clean up ;-)
-			    // Disable/enable controls given we had an element selected, but no longer do.
-			    //card_layout.show(details_pane, BLANK); // Show a blank panel.
-			    //ignore = false;
-			    
+			    //finish up
 			    currentSet.setSetChanged(true);
 			    atLeastOneSetChanged = true;
@@ -3037,5 +2191,5 @@
     /**
        Class to handle DELETE key presses on the tree.
-       The class then fires the appropriate event to remove that subelement/element/set.
+       The class then fires the appropriate event to remove that element/set.
        Attributes in the table are handled directly by the RemoveAttributeActionListener
 
@@ -3086,29 +2240,15 @@
 	    if(cont)
 		{
-		    
 		    //Check to see if pressed on Set or Element.
 		    TreePath selPath = mds_tree.getSelectionPath();
 		    GEMSNode t = (GEMSNode)selPath.getLastPathComponent();
 		    
-		    if(t.type == T_SUBELEMENT) //Remove the subelement
+		    if(t.type == T_ELEMENT) //Remove the element
 			{
-			    RemoveSubelementActionListener removeSubelement = new RemoveSubelementActionListener();
-			    removeSubelement.actionPerformed((ActionEvent)null);
-			}
-		    else if(t.type == T_ELEMENT) //Remove the element
-			{
-			    //System.err.println("element");
 			    RemoveElementActionListener removeElement = new RemoveElementActionListener();
 			    removeElement.actionPerformed((ActionEvent)null);
 			}
-		    
-		    else if(t.type == T_ROOT)
-			{
-			    //Do nothing
-			    System.err.println("Tree type of ROOT: this should not happen!");
-			}
 		    else if(t.type == T_SET) //Remove the whole set
 			{
-			    //System.err.println("set");
 			    RemoveSetActionListener removeSet = new RemoveSetActionListener();
 			    removeSet.actionPerformed((ActionEvent)null);
@@ -3118,7 +2258,4 @@
     }
     
-
-   
-
 
     private class RemoveSetActionListener
@@ -3151,30 +2288,8 @@
 		    // Clear selection
 		    mds_tree.clearSelection();
-		    model.remove(current_set.toString(), GEMSNode.SET);
+		    model.remove(current_node);
 		    card_layout.show(details_pane, BLANK); //Show a blank panel.
 		    ignore = false;
  
-		}
-	    }
-	}
-    }
-
-    /** This class will remove the currently selected metadata or profile value when any registered control is actioned. Note that removing a value acts differently from the other removes in that if you remove a value which is still assigned somewhere the values are restored next time said assignment is viewed. This turned out far easier and reasonable to code than attempting to remove all remaining values when you delete its reference in the GValueModel. */
-    private class RemoveValueActionListener
-	implements ActionListener {
-	/** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
-	 * @param event An <strong>ActionEvent</strong> containing information about the event.
-	 */
-	public void actionPerformed(ActionEvent event) {
-	    if(current_value_node != null) {	
-		int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.Value")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
-		// Remove the current selected value
-		if(result == 0) {
-		    ignore = true;
-		    ignore = false; //What the heck?? --Matthew
-                    
-                    //does this ever get called?
-                    System.out.println("\nGEMS.RemovevalueActionListener called");
-                    atLeastOneSetChanged = true;
 		}
 	    }
@@ -3247,28 +2362,5 @@
 		{
 		    current_attribute = table.getSelectedRow();
-		    /*
-		    if((current_attribute = table.getSelectedRow()) != -1)
-			{		    
-			}
-		    else
-			{
-			    current_attribute = -1;
-			}
-		    */
-		}
-	}
-    }
-    
-    private class ElementValuesTreeSelectionListener
-	implements TreeSelectionListener {
-	public void valueChanged(TreeSelectionEvent event) {
-	    if(element_values.getSelectionCount() > 0) {
-		// Retrieve the selected value node.
-		TreePath selected_path = element_values.getSelectionPath();
-		current_value_node = (GValueNode) selected_path.getLastPathComponent();
-	    }
-	    else {
-		current_value_node = null;
-	    }
+		}
 	}
     }
@@ -3278,7 +2370,5 @@
 	public void valueChanged(TreeSelectionEvent event) {
 	    if(!ignore) {
-		GValueModel value_model = null;
 		// Clear all variables based on previous tree selection
-		current_collection_file = null;
 		current_element = null;
 		current_set = null;
@@ -3291,34 +2381,4 @@
 		current_attribute_type = current_node.getType();
 		switch(current_attribute_type) {
-		case GEMSNode.COLLECTION:
-		    current_collection_file = (String) current_node.getUserObject();
-		    atm = current_node.getModel();
-		    if(atm == null) {
-			attributes = new TreeSet();
-      
-			atm = new AttributeTableModel(attributes, Dictionary.get("GEMS.Source"), Dictionary.get("GEMS.Target"), Dictionary.get("GEMS.Ignore"));
-		    }
-		    profile_attributes.setModel(atm);
-		    atm.setScrollPane(profile_attributes_scroll);
-		    atm.setTable(profile_attributes);
-
-		    card_layout.show(details_pane, PROFILE);
-		    break;
-
-		case GEMSNode.SUBELEMENT:
-		    current_subelement = current_node.getSubelement();
-		    
-		    atm = current_node.getModel();
-		    if(atm == null) {
-			atm = new AttributeTableModel(current_subelement.getAttributes(), Dictionary.get("GEMS.Name"), Dictionary.get("GEMS.Language_Code"), Dictionary.get("GEMS.Value"), "");
-		    }
-
-		    subelement_attributes.setModel(atm);
-		    atm.setScrollPane(subelement_attributes_scroll);
-		    atm.setTable(subelement_attributes);
-		    //System.err.println("atm is: " + atm); //debug
-
-		    card_layout.show(details_pane, SUBELEMENT); 
-		    break;
 
 		case GEMSNode.ELEMENT:
@@ -3333,16 +2393,4 @@
 		    atm.setTable(element_attributes);
 
-		    // Be careful not to add the keep_root_expanded_listener over and over!
-		    value_model = msm.getValueTree(current_element);
-		    if(value_model != null) {
-			value_model.removeTreeModelListener(keep_root_expanded_listener); // Remove it if its already there
-			value_model.addTreeModelListener(keep_root_expanded_listener); // Then add again.
-			element_values.setModel(value_model);
-			element_values_layout.show(element_values_pane, VALUES);
-		    }
-		    else {
-			//this shouldn't happen!
-			element_values_layout.show(element_values_pane, BLANK);
-		    }
 		    card_layout.show(details_pane, ELEMENT);
 		    break;
@@ -3371,5 +2419,4 @@
 		    attributes = null;
 		    break;
-		case GEMSNode.PROFILER:
 
 		default:
@@ -3395,35 +2442,27 @@
 
     //PopupListener is our main manager for all right-click popups
-  class PopupListener extends MouseAdapter implements ActionListener{
-      JPopupMenu setPopup;
-      JPopupMenu subelementPopup;
-      JPopupMenu elementPopup;
-      JPopupMenu attributePopup;
-      //all of our popup menu items EVER!
-      JMenuItem menuAddSet;
-      JMenuItem menuRenameSet;
-      JMenuItem menuAddElement;
-      JMenuItem menuAddAttributeSet;
-
-      JMenuItem menuRenameSubelement;
-      JMenuItem menuDeleteSubelement;
-      JMenuItem menuAddAttributeSubelement;
-      JMenuItem menuRenameElement;
-      
-      JMenuItem menuDeleteElement;
-      JMenuItem menuAddAttributeElement;
-      JMenuItem menuAddSubelement;
-      JMenuItem menuAddSubelementCopy;
-      
-      JMenuItem menuEditValue;
-      JMenuItem menuDeleteAttribute;
-      JMenuItem menuAddAttributeAttribute;
-      
-      JMenuItem menuRemoveSet;
-      
+    class PopupListener extends MouseAdapter implements ActionListener{
+	JPopupMenu setPopup;
+	JPopupMenu elementPopup;
+	JPopupMenu attributePopup;
+
+	//all of our popup menu items EVER!
+	JMenuItem menuAddAttributeSet;
+	JMenuItem menuAddElement;
+	JMenuItem menuRenameSet;
+	JMenuItem menuRemoveSet;
+
+	JMenuItem menuAddAttributeElement;
+	JMenuItem menuAddSubelement;
+	JMenuItem menuRenameElement;
+	JMenuItem menuDeleteElement;
+
+	JMenuItem menuAddAttributeAttribute;
+	JMenuItem menuEditValue;
+	JMenuItem menuDeleteAttribute;
+	
         GEMS GEMSRef = null;
         PopupListener(GEMS g) {
 	    setPopup = new JPopupMenu();
-	    subelementPopup = new JPopupMenu();
 	    elementPopup = new JPopupMenu();
 	    attributePopup = new JPopupMenu();
@@ -3431,109 +2470,63 @@
             //reference to our parent(GEMS), because some of the actionlisteners would not
             //work unless they were declared in GEMS, and I need a way to reference GEMS
-            
 	    GEMSRef = g;
 	    
-	    //create the MenuItems
-	    
-	    //set related popups
-	    menuAddSet = new JMenuItem();
-            
+	    //Create the menu items
+	    menuAddAttributeSet = new JMenuItem();
+	    Dictionary.setText(menuAddAttributeSet, "GEMS.Popup.menuAddAttribute");
+	    menuAddElement =new JMenuItem();
+	    Dictionary.setText(menuAddElement,"GEMS.Popup.menuAddElement");
 	    menuRenameSet = new JMenuItem();
 	    Dictionary.setText(menuRenameSet,"GEMS.Popup.menuRenameSet");
-	    
-	    menuAddElement =new JMenuItem();
-	   // Dictionary.setText(menuAddElement,"GEMS.Popup.menuAddElement");
-	    Dictionary.setText(menuAddElement,"GEMS.Add_Element_Tooltip");
-	    
-	    menuAddAttributeSet = new JMenuItem();
-	   // Dictionary.setText(menuAddAttributeSet, "GEMS.Popup.menuAddAttribute");
-	    Dictionary.setText(menuAddAttributeSet, "GEMS.Add_Attribute_Tooltip");
-	    
-            
             menuRemoveSet = new JMenuItem();
-	   Dictionary.setText(menuRemoveSet,"GEMS.Remove_Set_Tooltip");
-	    
-            //subelement related GEMS.Popups
-            menuRenameSubelement = new JMenuItem();
-            Dictionary.setText(menuRenameSubelement,"GEMS.Popup.menuRenameSubelement");
-            
-            menuDeleteSubelement=new JMenuItem();
-            Dictionary.setText(menuDeleteSubelement,"GEMS.Popup.menuRemoveSubelement");
-            
-            menuAddAttributeSubelement=new JMenuItem();
-           // Dictionary.setText(menuAddAttributeSubelement,"GEMS.Popup.menuAddAttribute");
-             Dictionary.setText(menuAddAttributeSubelement,"GEMS.Add_Attribute_Tooltip");
-            
-            //element related GEMS.Popups
+	    Dictionary.setText(menuRemoveSet, "GEMS.Popup.menuRemoveSet");
+            
+            menuAddAttributeElement=new JMenuItem();
+            Dictionary.setText(menuAddAttributeElement,"GEMS.Popup.menuAddAttribute");
+	    menuAddSubelement=new JMenuItem();
+            Dictionary.setText(menuAddSubelement,"GEMS.Popup.menuAddSubelement");
             menuRenameElement=new JMenuItem();
             Dictionary.setText(menuRenameElement,"GEMS.Popup.menuRenameElement");
-	    // Dictionary.setText(menuRenameElement,"GEMS.Rename_Element_Tooltip");
-            
             menuDeleteElement=new JMenuItem();
-           // Dictionary.setText(menuDeleteElement,"GEMS.Popup.menuRemoveElement");
-            Dictionary.setText(menuDeleteElement,"GEMS.Remove_Element_Tooltip");
-            
-            menuAddAttributeElement=new JMenuItem();
-            //Dictionary.setText(menuAddAttributeElement,"GEMS.Popup.menuAddAttribute");
-            Dictionary.setText(menuAddAttributeElement,"GEMS.Add_Attribute_Tooltip");
-            
-            menuAddSubelement=new JMenuItem();
-            Dictionary.setText(menuAddSubelement,"GEMS.Popup.menuAddSubelement");
-             //Dictionary.setText(menuAddSubelement,"GEMS.Add_Subelement");
-	    menuAddSubelementCopy = new JMenuItem(); //A copy of menuAddSubelement
-	    Dictionary.setText(menuAddSubelementCopy, "GEMS.Popup.menuAddSubelement");
-        
-            //attribute related GEMS.Popups
+	    Dictionary.setText(menuDeleteElement,"GEMS.Popup.menuRemoveElement");
+
+	    menuAddAttributeAttribute=new JMenuItem();
+	    Dictionary.setText(menuAddAttributeAttribute,"GEMS.Popup.menuAddAttribute");
             menuEditValue=new JMenuItem();
-            //Dictionary.setText(menuEditValue,"GEMS.Popup.menuEditValue");
-            Dictionary.setText(menuEditValue,"GEMS.Edit_Value_Tooltip");
-            
+            Dictionary.setText(menuEditValue,"GEMS.Popup.menuEditValue");
             menuDeleteAttribute=new JMenuItem();
-           // Dictionary.setText(menuDeleteAttribute,"GEMS.Popup.menuRemoveAttribute");
-            Dictionary.setText(menuDeleteAttribute,"GEMS.Remove_Attribute_Tooltip");
-            
-            menuAddAttributeAttribute=new JMenuItem();
-           // Dictionary.setText(menuAddAttributeAttribute,"GEMS.Popup.menuAddAttribute");
-             Dictionary.setText(menuAddAttributeAttribute,"GEMS.Add_Attribute_Tooltip");
+	    Dictionary.setText(menuDeleteAttribute,"GEMS.Popup.menuRemoveAttribute");
              
-             //start Associate the menu items with the appropriate popups:
-	     setPopup.add(menuAddAttributeSet);
-	     setPopup.add(menuAddElement);
-             setPopup.add(menuRenameSet);
-	     setPopup.add(menuRemoveSet);
-            
-	     elementPopup.add(menuAddAttributeElement);
-	     elementPopup.add(menuAddSubelement);
-             elementPopup.add(menuRenameElement);
-             elementPopup.add(menuDeleteElement);
-             
-	     subelementPopup.add(menuAddAttributeSubelement);
-	     //subelementPopup.add(menuAddSubelementCopy);
-             subelementPopup.add(menuRenameSubelement);
-             subelementPopup.add(menuDeleteSubelement);
-            
-	     attributePopup.add(menuAddAttributeAttribute);
-             attributePopup.add(menuEditValue);
-             attributePopup.add(menuDeleteAttribute);
-             //end Associate the menu items with the appropriate popups:
-             
-             menuRemoveSet.addActionListener(new RemoveSetActionListener());
-             menuAddElement.addActionListener(new AddElementActionListener());
-             menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener());
-             menuRenameSubelement.addActionListener(new RenameSubelementActionListener());
-             menuDeleteSubelement.addActionListener(new RemoveSubelementActionListener());
-             menuAddAttributeSubelement.addActionListener(new AddOrEditAttributeActionListener());
-             
-	     menuRenameSet.addActionListener(new RenameSetActionListener());
-             menuRenameElement.addActionListener(new RenameElementActionListener());
-             menuDeleteElement.addActionListener(new RemoveElementActionListener());
-             menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener());
-             menuAddSubelement.addActionListener(new AddSubelementActionListener());
-	     menuAddSubelementCopy.addActionListener(new AddSubelementActionListener());
-             menuEditValue.addActionListener(new AddOrEditAttributeActionListener());
-             menuDeleteAttribute.addActionListener(new RemoveAttributeActionListener());
-             menuAddAttributeAttribute.addActionListener(new AddOrEditAttributeActionListener());
-            
+	    //Associate the menu items with the appropriate popups:
+	    setPopup.add(menuAddAttributeSet);
+	    setPopup.add(menuAddElement);
+	    setPopup.add(menuRenameSet);
+	    setPopup.add(menuRemoveSet);
+            
+	    elementPopup.add(menuAddAttributeElement);
+	    elementPopup.add(menuAddSubelement);
+	    elementPopup.add(menuRenameElement);
+	    elementPopup.add(menuDeleteElement);
+            
+	    attributePopup.add(menuAddAttributeAttribute);
+	    attributePopup.add(menuEditValue);
+	    attributePopup.add(menuDeleteAttribute);
+	    
+	    //Add appropriate action listeners to the menu items.
+	    menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener());
+	    menuAddElement.addActionListener(new AddElementActionListener());
+	    menuRenameSet.addActionListener(new RenameSetActionListener());
+	    menuRemoveSet.addActionListener(new RemoveSetActionListener());
+	    
+	    menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener());
+	    menuAddSubelement.addActionListener(new AddSubelementActionListener());
+	    menuRenameElement.addActionListener(new RenameElementActionListener());
+	    menuDeleteElement.addActionListener(new RemoveElementActionListener());
+	   
+	    menuEditValue.addActionListener(new AddOrEditAttributeActionListener());
+	    menuDeleteAttribute.addActionListener(new RemoveAttributeActionListener());
+	    menuAddAttributeAttribute.addActionListener(new AddOrEditAttributeActionListener());            
         }
+
         public void mouseClicked(MouseEvent e) {
             maybeShowPopup(e);
@@ -3541,6 +2534,5 @@
         public void mousePressed(MouseEvent e){
         maybeShowPopup(e);
-       
-   }
+	}
         public void mouseReleased(MouseEvent e) {
             maybeShowPopup(e);
@@ -3548,84 +2540,44 @@
 
         private void maybeShowPopup(MouseEvent e) {
-           
-         int selRow = mds_tree.getRowForLocation(e.getX(), e.getY());
-	 TreePath selPath = mds_tree.getPathForLocation(e.getX(), e.getY());
-	 Point p = null;
+	    TreePath selPath = mds_tree.getPathForLocation(e.getX(), e.getY());
+	    Point p = null;
             if (e.isPopupTrigger()) {
-               
-             if(e.getSource() == mds_tree) {
-                try {
-                
-                    GEMSNode t = (GEMSNode)selPath.getLastPathComponent();
-		    
-		    mds_tree.setSelectionPath(selPath); //Select node right-clicked on
-		    
-		    if(t.type == T_ELEMENT){
+		
+		if(e.getSource() == mds_tree) {
+		    try {
+			GEMSNode t = (GEMSNode)selPath.getLastPathComponent();
 			
-			elementPopup.show(e.getComponent(),
-					  e.getX(), e.getY());
+			mds_tree.setSelectionPath(selPath); //Select node right-clicked on
+			
+			if(t.type == T_ELEMENT){
+			    elementPopup.show(e.getComponent(), e.getX(), e.getY());
+			}
+			else if(t.type == T_SET){
+			    setPopup.show(e.getComponent(), e.getX(), e.getY());
+			}
 		    }
-
-		    else if(t.type == T_SUBELEMENT)
-			{
-			    subelementPopup.show(e.getComponent(), e.getX(), e.getY());
-			}
-
-		    else if(t.type == T_ROOT){
-			
-			setPopup.show(e.getComponent(),
-				      e.getX(), e.getY());
+		    catch(Exception NullPointerException) {
+			//Right-clicked in tree area, but no item to select. Do nothing.
 		    }
-		    else if(t.type == T_SET){
-			
-			setPopup.show(e.getComponent(),
-				      e.getX(), e.getY());
-		    }
-                }
-		catch(Exception NullPointerException) {
-		    //Right-clicked in tree area, but no item to select. Do nothing.
-		}
-
-                finally {
-                    ;
-                    
-                }
-                
-                    
-             }
-             else if(e.getSource() == set_attributes){ //When right-click on table of set attributes
-		 
-		 //Select the table row that was right-clicked on.
-		 p = e.getPoint();
-		 set_attributes.changeSelection(set_attributes.rowAtPoint(p), set_attributes.columnAtPoint(p), false, false);
-
-                 attributePopup.show(e.getComponent(),
-                           e.getX(), e.getY());  
-             }
-             else if(e.getSource() == element_attributes)  { //When right-click on table of element attributes
-                
-		 //Select the table row that was right-clicked on.
-		 p = e.getPoint();
-		 element_attributes.changeSelection(element_attributes.rowAtPoint(p), element_attributes.columnAtPoint(p), false, false);
-
-		 attributePopup.show(e.getComponent(),
-                           e.getX(), e.getY());
-             }
-	     else if(e.getSource() == subelement_attributes)  { //When right-click on table of subelement attributes
-		 
-		 //Select the table row that was right-clicked on.
-		 p = e.getPoint();
-		 subelement_attributes.changeSelection(subelement_attributes.rowAtPoint(p), subelement_attributes.columnAtPoint(p), false, false);
-
-		 attributePopup.show(e.getComponent(),
-				     e.getX(), e.getY());
-             }
+		}
+		else if(e.getSource() == set_attributes){ //When right-click on table of set attributes
+		    //Select the table row that was right-clicked on.
+		    p = e.getPoint();
+		    set_attributes.changeSelection(set_attributes.rowAtPoint(p), set_attributes.columnAtPoint(p), false, false);
+		    attributePopup.show(e.getComponent(), e.getX(), e.getY());  
+		}
+		else if(e.getSource() == element_attributes)  { //When right-click on table of element attributes
+		    //Select the table row that was right-clicked on.
+		    p = e.getPoint();
+		    element_attributes.changeSelection(element_attributes.rowAtPoint(p), element_attributes.columnAtPoint(p), false, false);
+		    attributePopup.show(e.getComponent(), e.getX(), e.getY());
+		}
             }  
         }
-     
-        public void actionPerformed(ActionEvent e) {
-	    //This should never happen!!
-            System.out.println("NO way hose");
-        }
+      
+      public void actionPerformed(ActionEvent e) {
+	  //This should never happen!!
+	  System.err.println("Error: actionPerformed was called in class PopupListener. This should never happen!");
+      }
     }
   
Index: /trunk/gli/src/org/greenstone/gatherer/gems/GEMSLanguageManager.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/GEMSLanguageManager.java	(revision 8970)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/GEMSLanguageManager.java	(revision 8971)
@@ -1,6 +1,37 @@
-/*
- * GEMSLanguageManager.java
+ /**
+ *#########################################################################
  *
- * Created on October 27, 2004, 3:31 PM
+ * A component of the Gatherer application, part of the Greenstone digital
+ * library suite from the New Zealand Digital Library Project at th * University of Waikato, New Zealand.
+ *
+ * <BR><BR>
+ *
+ * Author: John Thompson, Greenstone Digital Library, University of Waikato
+ *
+ * <BR><BR>
+ *
+ * Copyright (C) 1999 New Zealand Digital Library Project
+ *
+ * <BR><BR>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * <BR><BR>
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * <BR><BR>
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *############################################## ##########################
  */
 
@@ -35,92 +66,86 @@
  * @author John Thompson, Greenstone Digital Library, University of Waikato
  * @version 2.3
+ * Created on October 27, 2004, 3:31 PM
+ * Modified 1/02/05 by Matthew Whyte
  */
  public class GEMSLanguageManager {
-              private Document document;
-              private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-              private Vector languageCodes;
-            public GEMSLanguageManager(String languagexml_location) {
-                
-               this.languageCodes = new Vector();
+     private Document document;
+     private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+     private Vector languageCodes;
+     private Vector languageCodesAndNames;
+     public GEMSLanguageManager(String languagexml_location) {
+	 
+	 this.languageCodes = new Vector();
+	 this.languageCodesAndNames = new Vector();
 
-            try {
-               
-               File f = new File(languagexml_location);
-               
-               DocumentBuilder builder = factory.newDocumentBuilder();
-               document = builder.parse(f);
-               org.w3c.dom.Element docelement = document.getDocumentElement();
-               
-               //get all language nodes
-               NodeList mynodelist = docelement.getChildNodes();
-               
-               //get a single language text
-               //System.out.println(mynodelist.item(1).getChildNodes().item(0).getNodeValue());
-               
-               for(int j = 1; j < mynodelist.getLength(); j++){
-                   
-                   //read text value for the element
-                  
-                   NodeList childnodesofelement = mynodelist.item(j).getChildNodes();
-                   
-                      
-                   NamedNodeMap nnm = mynodelist.item(j).getAttributes();
-               
-                   
-                    if(childnodesofelement.getLength() == 1){
-                        
-                            String code = nnm.item(0).getNodeValue();
-                            String name = nnm.item(4).getNodeValue();
-                            String name_value = childnodesofelement.item(0).getNodeValue();
-                            //language_box.addItem(code.toLowerCase());
-                            this.languageCodes.add(code.toLowerCase());
-                    }
-                    
-                   
-               
-            
-                   
-               }//end for
-       
-           }
-           catch(SAXException sxe) {
-               
-               System.out.println("sxe exception\n");
-           }
-           catch(ParserConfigurationException pce) {
+	 try {
+	     
+	     File f = new File(languagexml_location);
+	     
+	     DocumentBuilder builder = factory.newDocumentBuilder();
+	     document = builder.parse(f);
+	     org.w3c.dom.Element docelement = document.getDocumentElement();
+	     
+	     //get all language nodes
+	     NodeList mynodelist = docelement.getChildNodes();
+	     
+	     //get a single language text
+	     //System.out.println(mynodelist.item(1).getChildNodes().item(0).getNodeValue()); //debug
+	     
+	     for(int j = 1; j < mynodelist.getLength(); j++){
+		 
+		 //read text value for the element
+		 NodeList childnodesofelement = mynodelist.item(j).getChildNodes();
+		 NamedNodeMap nnm = mynodelist.item(j).getAttributes();
+		 
+		 if(childnodesofelement.getLength() == 1)
+		     {
+			 String code = nnm.item(0).getNodeValue();
+			 String name = nnm.item(4).getNodeValue();
+			 String name_value = childnodesofelement.item(0).getNodeValue();
+			 //language_box.addItem(code.toLowerCase());
+			 this.languageCodes.add(code.toLowerCase());
+			 this.languageCodesAndNames.add(name.toLowerCase() + "               \t(" + code.toLowerCase() + ")");
+		     } //end if
+	     }//end for
+	 } //end try
+	 catch(SAXException sxe) {
+	     System.out.println("sxe exception\n");
+	 }
+	 catch(ParserConfigurationException pce) {
              System.out.println("pce exception\n");
-               
-           }
-           catch(IOException ioe){
-               
-               System.out.println("ioe exc\n");
-               
-           }
-            
-            //end create dom object for language_box
-                
-            }
-           public Vector getLanguageCodes() { 
-               return languageCodes;
-           }
-           public Object[] getLanguageCodesToArray() { 
-               return languageCodes.toArray();
-           }
-           public String getEnabledLanguageCodes() {
-            String enabled_languages =  Configuration.getString("Gems.Preferences.Selected_Languages", true);
-           return enabled_languages;   
-           }
-            public String[] getEnabledLanguageCodesToArray() {
-            String enabled_languages =  Configuration.getString("Gems.Preferences.Selected_Languages", true); 
-            String [] enabled_languages_split = enabled_languages.split(",");
-           // String [] trimmed_enabled_lang_split = null;
-            
-          //  for(int p = 0; p < enabled_languages_split.length; p++) {
-                //trimmed_enabled_lang_split[p] = enabled_languages_split[p].trim(); 
-              //  System.out.println("gemslang: trimm: " + trimmed_enabled_lang_split[p] + " orig: "+ enabled_languages_split[p].trim());
-           // }//for p < enabled lang split
-            
-            return enabled_languages_split;
-           }
-            
-        }
+	 }
+	 catch(IOException ioe){
+	     System.out.println("ioe exception\n");
+	 }
+	 
+	 //end create dom object for language_box
+	 
+     }
+     public Vector getLanguageCodesAndNames() {
+	 return languageCodesAndNames;
+     }
+
+     public Vector getLanguageCodes() { 
+	 return languageCodes;
+     }
+     public Object[] getLanguageCodesToArray() { 
+	 return languageCodes.toArray();
+     }
+     public String getEnabledLanguageCodes() {
+	 String enabled_languages =  Configuration.getString("Gems.Preferences.Selected_Languages", true);
+	 return enabled_languages;   
+     }
+     public String[] getEnabledLanguageCodesToArray() {
+	 String enabled_languages =  Configuration.getString("Gems.Preferences.Selected_Languages", true); 
+	 String [] enabled_languages_split = enabled_languages.split(",");
+	 // String [] trimmed_enabled_lang_split = null;
+	 
+	 //  for(int p = 0; p < enabled_languages_split.length; p++) {
+	 //trimmed_enabled_lang_split[p] = enabled_languages_split[p].trim(); 
+	 //  System.out.println("gemslang: trimm: " + trimmed_enabled_lang_split[p] + " orig: "+ enabled_languages_split[p].trim());
+	 // }//for p < enabled lang split
+	 
+	 return enabled_languages_split;
+     }  
+ }
Index: /trunk/gli/src/org/greenstone/gatherer/gems/GEMSModel.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/GEMSModel.java	(revision 8970)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/GEMSModel.java	(revision 8971)
@@ -66,59 +66,4 @@
     }
 
-    public void remove(String name, int type) {
-	GEMSNode current = (GEMSNode) root;
-	for(int i = 0; i < current.getChildCount(); i++) {
-	    GEMSNode child = (GEMSNode) current.getChildAt(i);
-	    if(child.toString().equals(name) && type == GEMSNode.SET) {
-		// Place on AWT event thread to avoid errors.
-		SynchronizedTreeModelTools.removeNodeFromParent(this, child);
-		return;
-	    }
-	    // This may be the profiler root node, in which case we descend into its children if we're looking for collection file matches. 
-	    else if(type == GEMSNode.COLLECTION && child.getType() == GEMSNode.PROFILER) {
-		for(int j = 0; j < child.getChildCount(); j++) {
-		    GEMSNode inner_child = (GEMSNode) child.getChildAt(j);
-		    if(inner_child.toString().equals(name)) {
-			// Place on AWT event thread to avoid errors.
-			SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
-			return;
-		    }
-		}
-	    }
-	    // If this is a set and we are looking for an element or subelement, then iterate through its children. Can't really do this recursively.
-	    else if((type == GEMSNode.ELEMENT || type == GEMSNode.SUBELEMENT) && child.getType() == GEMSNode.SET) {
-		for(int j = 0; j < child.getChildCount(); j++) {
-		    GEMSNode inner_child = (GEMSNode) child.getChildAt(j);
-		    //Go through looking for element
-		    if(type == GEMSNode.ELEMENT)
-			{
-			    if(inner_child.toString().equals(name)) {
-				// Place on AWT event thread to avoid errors.
-				SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
-				return;
-			    }
-			}
-		    //Go through element looking for subelement
-		    else if(type == GEMSNode.SUBELEMENT)
-			{
-			    for(int k = 0; k < inner_child.getChildCount(); k++)
-				{
-				    //the subelements
-				    GEMSNode innermost_child = (GEMSNode)inner_child.getChildAt(k);
-				    if(innermost_child.toString().equals(name))
-					{
-					    // Place on AWT event thread to avoid errors.
-					    SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
-					    return;
-					}
-				}
-			}
-		}
-	    }
-	}
-
-	System.err.println("Tried to remove \'" + name + "\' from the tree, but could not find it!"); //This should not happen!
-    }
-
     /**
        Remove a node from the tree.
Index: /trunk/gli/src/org/greenstone/gatherer/gems/GEMSNode.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/GEMSNode.java	(revision 8970)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/GEMSNode.java	(revision 8971)
@@ -51,4 +51,5 @@
  * @author John Thompson, Greenstone Digital Library, University of Waikato
  * @version 2.3
+ * Modified 2/02/05 by Matthew Whyte
  */
 public class GEMSNode
@@ -62,9 +63,8 @@
     static final public int ROOT       = 3; 
     static final public int SET        = 4;
-    static final public int SUBELEMENT = 5;
+    //static final public int SUBELEMENT = 5; 
 
     public GEMSNode() {
 	this.type = ROOT;
-        
     }
 
@@ -107,12 +107,4 @@
     }
 
-    public ElementWrapper getSubelement() {
-	ElementWrapper result = null;
-	if(type == SUBELEMENT) {
-	    result = (ElementWrapper) userObject;
-	}
-	return result;
-    }
-
     public int getIndex(TreeNode node) {
 	if(children == null) {
@@ -147,62 +139,26 @@
     }
 
-    public String toString() {
-	if(text == null) {
-	    if(userObject != null) {
-		if(userObject instanceof ElementWrapper) {
-		    text = ((ElementWrapper)userObject).getName();
-		}
-		// In the case of a 'collection' source path we need to examine the path closely. If it is a descendant of the greenstone collections path then supress everything but the collection name
-// 		else if(type == COLLECTION) {
-// 		    try {
-// 			boolean is_descendant = false;
-// 			File source_path = new File((String)userObject);
-// 			File collect_path;
-// 			if (Gatherer.GS3) {
-// 			    collect_path = new File(Utility.getCollectDir(Configuration.gsdl3_path, Configuration.site_name));
-// 			}  else {
-// 			    collect_path = new File(Utility.getCollectDir(Configuration.gsdl_path));
-// 			}
-// 			File current_path = source_path;
-// 			while(!is_descendant && current_path != null) {
-// 			    is_descendant = current_path.equals(collect_path);
-// 			    current_path = current_path.getParentFile();
-// 			}
-// 			current_path = null;
-// 			collect_path = null;
-// 			// We've either found we are a descendant, or run out of path
-// 			if(is_descendant) {
-// 			    // Create a basic config class
-// 			    File config_file = new File(source_path, Utility.CONFIG_FILE);
-// 			    if (config_file.exists()) {
-// 				BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
-// 				text = config.toString();
-// 				config = null;
-// 			    } else {
-// 				text = source_path.getAbsolutePath();
-// 			    }
-// 			    config_file = null;
-// 			}
-// 			else {
-// 			    text = source_path.getAbsolutePath();
-// 			}
-// 		    }
-// 		    catch(Exception exception) {
-// 			DebugStream.println("Exception in GEMSNode.toString() - exception is unexpected");
-// 			DebugStream.printStackTrace(exception);
-// 			text = userObject.toString();
-// 		    }
-// 		}
-		else {
-		    text = userObject.toString();
-		}
+    public String toString()
+    {
+	if(text == null)
+	    {
+		if(userObject != null)
+		    {
+			if(userObject instanceof ElementWrapper)
+			    {
+				text = ((ElementWrapper)userObject).getName();
+			    }
+			else
+			    {
+				text = userObject.toString();
+			    }
+		    }
+		else
+		    {
+			text = "error";
+		    }
 	    }
-	    else {
-		text = "error";
-	    }
-	}
 	return text;
     }
-
 
     public void mapChildren()
@@ -221,29 +177,23 @@
 		    }
 	    }
-	if (type == ELEMENT) //Add subelements. This will need to be changed to cope with multiple levels of subelements.
+	if (type == ELEMENT) //Add subelements. As elements and subelements are identical, this process continues.
 	    {
 		ArrayList subelements = this.getElement().getSubelements();
 		for(int j = 0; j < subelements.size(); j++)
 		    {
-			children.add(new GEMSNode(SUBELEMENT, new ElementWrapper((Element)subelements.get(j)), this));
+			children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element)subelements.get(j)), this));
 		    }
 	    }
-
     }
     
    class GemsNodeMouseAdapter
     extends MouseAdapter {
-        
-        
-        
+       
       public void mouseClicked(MouseEvent e) {
         JPopupMenu setPopup = new JPopupMenu("asdf");
-         if (e.isPopupTrigger()) {
-                         
-                     setPopup.show(e.getComponent(),
+         if (e.isPopupTrigger()) {       
+	     setPopup.show(e.getComponent(),
                            e.getX(), e.getY());
-                    
-                
-            }
+	 }
     }    
     
@@ -256,26 +206,17 @@
     public void mousePressed(MouseEvent e) {
          JPopupMenu setPopup = new JPopupMenu("asdf");
-         if (e.isPopupTrigger()) {
-                         
-                     setPopup.show(e.getComponent(),
+         if (e.isPopupTrigger()) {               
+	     setPopup.show(e.getComponent(),
                            e.getX(), e.getY());
-                    
-                
-            }
-    }
-    
+	 }
+    }
+       
     public void mouseReleased(MouseEvent e) {
          JPopupMenu setPopup = new JPopupMenu("asdf");
-         if (e.isPopupTrigger()) {
-                         
-                     setPopup.show(e.getComponent(),
-                           e.getX(), e.getY());
-                    
-                
-            }
+         if (e.isPopupTrigger()) {                  
+	     setPopup.show(e.getComponent(),
+                           e.getX(), e.getY());     
+	 }
     }  
-        
-        
    }
-    
 }
Index: /trunk/gli/src/org/greenstone/gatherer/gems/GEMSPreferences.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/GEMSPreferences.java	(revision 8970)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/GEMSPreferences.java	(revision 8971)
@@ -35,4 +35,5 @@
 import javax.swing.*;
 import javax.swing.event.*;
+import javax.swing.border.*;
 import org.greenstone.gatherer.Configuration;
 import org.greenstone.gatherer.Dictionary;
@@ -51,21 +52,13 @@
     static final public String CONNECTION_PREFS = "connection";
     static final public String GENERAL_PREFS = "general";
-
-
     static final private Dimension LABEL_SIZE = new Dimension(280, 25);
-    static final private Dimension ROW_SIZE = new Dimension(640, 25);
     static final private Dimension SIZE = new Dimension(640, 345);
-    static final private String TRUE = "true";
-
-    // private CheckList warning_preferences_check_list;
-    private EmailField email_field;
+
+    //private EmailField email_field;
     private JButton apply_button;
     private JButton cancel_button;
     private JButton ok_button;
-    private JCheckBox use_subfields_checkbox;
-    
+
     private JCheckBox use_proxy_checkbox;
-    private JCheckBox view_extracted_metadata_checkbox;
-    
     private JCheckBox workflow_create;
     private JCheckBox workflow_mirror;
@@ -74,36 +67,25 @@
     private JCheckBox workflow_design;
     private JCheckBox workflow_export;
+
     private JComboBox language_combobox;
-    private JList language_limited_jlist;
-    
-    private JComboBox servlet_combobox; // GS3
-    private JComboBox site_combobox; // GS3
+    private JList language_limited_jlist;  
+    private JList language_code_jlist; 
+    private JComboBox servlet_combobox;
+    private JComboBox site_combobox;
     private JLabel interface_language_label;
     private JLabel language_label;
-    private JLabel library_path_label;
-    private JLabel predefined_label;
-    private JLabel program_label;
-    private JLabel proxy_host_label;
-    private JLabel proxy_port_label;
-    private JLabel title_label;
-    private JPanel servlet_pane;
+
     private JRadioButton assistant_mode_radio_button;
     private JRadioButton expert_mode_radio_button;
-    private JRadioButton librarian_mode_radio_button;
     private JRadioButton systems_mode_radio_button;
     private JSpinner proxy_port_field;
     private JTabbedPane tab_pane;
     private JTextArea mode_description_textarea;
-    private JTextField library_path_field;
-    private JTextField program_field;
     private JTextField proxy_host_field;
     private GEMSPreferences self;
 
     private String current_site_selection;
+
     public GEMSPreferences() {
-	this(GENERAL_PREFS);
-    }
-
-    public GEMSPreferences(String initial_view) {
 	// Initialize
 	super(Gatherer.g_man, true);
@@ -118,10 +100,4 @@
 	JPanel general_preferences = createGeneralPreferences();
 	tab_pane.add("Preferences.General", general_preferences);
-	//tab_pane.add("Preferences.Mode", createModePreferences());
-	// !! Temporarily disabled for the UNESCO CD-ROM !!
-	// tab_pane.add("Preferences.Workflow", createWorkflowPreferences());
-	//JPanel connection_preferences = createConnectionPreferences();
-	//tab_pane.add("Preferences.Connection", connection_preferences);
-	//tab_pane.add("Preferences.Warnings", createWarningPreferences());
         
 	Dictionary.register(tab_pane);
@@ -155,20 +131,9 @@
 	content_pane.add(button_pane, BorderLayout.SOUTH);
 
-	Dimension frame_size;// = Gatherer.g_man.getSize();
-	Point frame_location;// = Gatherer.g_man.getLocation();
-	//setLocation(frame_location.x + ((frame_size.width - SIZE.width) / 2), frame_location.y + ((frame_size.height - SIZE.height)));
-	//setLocation(((frame_size.width - SIZE.width) / 2), ((frame_size.height - SIZE.height)));
         setLocation(400, 300);
-
-	
 	tab_pane.setSelectedComponent(general_preferences);
-	
-
 	
 	// Clean up
 	general_preferences = null;
-	//connection_preferences = null;
-	frame_location = null;
-	frame_size = null;
 	cancel_button = null;
 	ok_button = null;
@@ -185,47 +150,4 @@
 	// Build the model of available languages
 	ArrayList dictionary_model = new ArrayList();
-
-	// Old method for determining what languages should be available in the combobox
-	/*
-	dictionary_model.add(new DictionaryEntry(Locale.ENGLISH));
-	File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER);
-	File[] possible_dictionaries = classes_folder.listFiles();
-	for(int i = 0; i < possible_dictionaries.length; i++) {
-	    String filename = possible_dictionaries[i].getName();
-	    if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) {
-		StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER);
-		Locale locale = null;
-		switch(tokenizer.countTokens()) {
-		case 1:
-		    locale = new Locale(tokenizer.nextToken().toLowerCase());
-		    break;
-		case 2:
-		    locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase());
-		    break;
-		}
-		tokenizer = null;
-		// Open the file and read the first line
-		String description = null;
-		try {
-		    BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i]));
-		    String first_line = br.readLine();
-		    br.close();
-		    description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1);
-		}
-		catch(Exception error) {
-		}
-		DictionaryEntry entry = new DictionaryEntry(description, locale);
-		description = null;
-		locale = null;
-		if(!dictionary_model.contains(entry)) {
-		    dictionary_model.add(entry);
-		}
-		entry = null;
-	    }
-	    filename = null;
-	}
-	possible_dictionaries = null;
-	classes_folder = null;
-	*/
 
 	// The new method makes use of the successor to the languages.dat file, classes/xml/languages.xml
@@ -254,31 +176,8 @@
 	interface_language_label.setPreferredSize(LABEL_SIZE);
         
-        
 	Dictionary.registerText(interface_language_label, "GEMS.Preferences.Selected_Languages_Tooltip");
-	email_field = new EmailField(Configuration.getColor("coloring.error_background", false));
-	email_field.setText(Configuration.getEmail());
-	Dictionary.registerTooltip(email_field, "GEMS.Preferences.Selected_Languages_Tooltip");
-
-	// Extracted metadata
-		
-	//Dictionary.registerBoth(view_extracted_metadata_checkbox, "Preferences.General.View_Extracted_Metadata", "Preferences.General.View_Extracted_Metadata_Tooltip");
-
-	
-	// Show file sizes
-	use_subfields_checkbox = new JCheckBox();
-        JLabel use_subfields_checkbox_label = new JLabel();
-        use_subfields_checkbox_label.setPreferredSize(new Dimension(225, 30));
-	use_subfields_checkbox.setSelected(false);
-        use_subfields_checkbox.setVisible(false);
-        use_subfields_checkbox_label.setVisible(false);
-      
-     //  String blah = Configuration.getString("coloring.workspace_tree_background",true);
-        //  System.out.println("before"+ blah);
-          
-	if (Configuration.get("GEMS.Preferences.Use_Subelements", true)) {
-         	use_subfields_checkbox.setSelected(true);
-	}
-	Dictionary.registerBoth(use_subfields_checkbox_label, "GEMS.Preferences.Use_Subelements", "GEMS.Preferences.Use_Subelements_Tooltip");
-	
+	//email_field = new EmailField(Configuration.getColor("coloring.error_background", false));
+	//email_field.setText(Configuration.getEmail());
+	//Dictionary.registerTooltip(email_field, "GEMS.Preferences.Selected_Languages_Tooltip");
 
 	// Language
@@ -286,5 +185,4 @@
 	language_label = new JLabel();
 	language_label.setPreferredSize(LABEL_SIZE);
-        
    
 	Dictionary.registerText(language_label, "Preferences.General.Interface_Language");
@@ -299,30 +197,27 @@
 	    }
 	}
-    
-        //create language_limited_jlist
-        //String [] newer = {"blah", "asfd", "dfjdddd", "blee11" ,"asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","safd", "safd", "safd", "safd"};
-        
-        
         
         //create language selected box, and high light the apprpropate ones
-         int [] selectedLanguages = new int[300];
-         int selectedLanguagesLength = 0;
-     
-            
-        //GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml");
+	int [] selectedLanguages = new int[300];
+	int selectedLanguagesLength = 0;
+                 
+	//GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml");
         GEMSLanguageManager gemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml");
-        
-         
-         language_limited_jlist = new JList(gemsLangManager.getLanguageCodesToArray());     
+
+	//Create the visible JList, and then another one with just the language codes. 
+	language_code_jlist = new JList(gemsLangManager.getLanguageCodesToArray());  
+	language_limited_jlist = new JList(gemsLangManager.getLanguageCodesAndNames());
+
+	//Set the list up to display tabs properly
+  	TabListCellRenderer renderer = new TabListCellRenderer();
+	renderer.setTabs(new int[] {50, 200, 300});
+	language_limited_jlist.setCellRenderer(renderer);
+
         String enabled_languages =  Configuration.getString("GEMS.Preferences.Selected_Languages", true);
-	//we have a string : enabled_languages that contains an array of strings delimited by comma's
+	//we have a string: enabled_languages that contains an array of strings delimited by comma's
         String []enabled_languages_split = enabled_languages.split(",");
         Object []language_codes_array = gemsLangManager.getLanguageCodesToArray();
         
-        //System.out.println("before: " +enabled_languages_split[0].toString() + " meh: " + enabled_languages);
-        Vector selected = new Vector();
-        
-        //for each enabled_languages_split
-            //check which languages match, and store the index in selectedLanguages
+        //for each enabled_languages_split, check which languages match, and store the index in selectedLanguages
         for(int k = 0; k < enabled_languages_split.length; k++) {
             
@@ -331,44 +226,17 @@
                 //if the codes  match, then include the index p into the vector selectedLanguages
                 if (language_codes_array[p].toString().toLowerCase().trim().compareTo(enabled_languages_split[k].toLowerCase().trim()) == 0)
-              {
-                 // System.out.println(language_codes_array[p].toString().toLowerCase().trim() + " " + enabled_languages_split[k].toLowerCase().trim());
-              
-               //  selected.add(p);
-                   selectedLanguages[selectedLanguagesLength] = p;
-                   selectedLanguagesLength++;
-                   language_limited_jlist.addSelectionInterval(p,p);
-              }
-             
-                
-            }
-            
-            
+		    {
+			selectedLanguages[selectedLanguagesLength] = p;
+			selectedLanguagesLength++;
+			language_limited_jlist.addSelectionInterval(p,p);
+		    }   
+            }   
         }
        
-        //selectedLanguages should contain the indices of the languages that should be selected as
-        //stated in enabled_languages
-     
-        //language_limited_jlist.setSelectedIndices(selectedLanguages);
-       // language_limited_jlist.addSelectionInterval(1,1);
-        //language_limited_jlist.setSelectedIndex(1);
-               
-        //because the very first language(index 0) gets chosen no matter what... 
-        //then I unselected the 0 index, and then check the config file to see if that particular language is
-        //indeed selected
-     //  language_limited_jlist.set
-        
- 
-        
-
 	// Connect
 	language_combobox.addActionListener(new LanguageComboboxListener());
 
 	// Layout
-        
         JScrollPane langScrollPane = new JScrollPane(language_limited_jlist);
-      
-        //langScrollPane.getViewport().setView(language_limited_jlist);
-        
-       // langScrollPane.setSize(175, 100);
         langScrollPane.setPreferredSize(new Dimension(100, 100));
 	lang_limited_pane.setLayout(new GridLayout(1,3));
@@ -376,5 +244,4 @@
 	lang_limited_pane.add(langScrollPane);
         
-        
 	language_pane.setLayout(new BorderLayout());
 	language_pane.add(language_label, BorderLayout.WEST);
@@ -382,12 +249,8 @@
         
 	general_pane.setBorder(org.greenstone.gatherer.gui.BorderFactory.createEmptyBorder(5,5,5,5));
-	//general_pane.setLayout(new GridLayout(4,1,0,5));
 	general_pane.setLayout(null);
-	
-         general_pane.add(lang_limited_pane);
+	general_pane.add(lang_limited_pane);
 	general_pane.add(language_pane);
 	//general_pane.add(view_extracted_metadata_checkbox);
-	general_pane.add(use_subfields_checkbox);
-        general_pane.add(use_subfields_checkbox_label);
         Insets general_pane_insets = general_pane.getInsets();
         
@@ -397,10 +260,4 @@
         language_pane.setBounds(20+general_pane_insets.left, 130+general_pane_insets.top, 
                             language_pane.getPreferredSize().width, language_pane.getPreferredSize().height);
-        
-        use_subfields_checkbox_label.setBounds(20+general_pane_insets.left, 200+general_pane_insets.top, 
-                            use_subfields_checkbox_label.getPreferredSize().width, use_subfields_checkbox_label.getPreferredSize().height);
-       
-        use_subfields_checkbox.setBounds(295+general_pane_insets.left, 200+general_pane_insets.top, 
-                            use_subfields_checkbox.getPreferredSize().width, use_subfields_checkbox.getPreferredSize().height);
        
 	return general_pane;
@@ -416,46 +273,5 @@
 	public void actionPerformed(ActionEvent event) {
 	    // Submit the various changes
-	    // Connection preferences
-	 /*   String program_str = program_field.getText();
-	    if(program_str.length() > 0 && program_str.indexOf("%1") == -1) {
-		program_str = program_str + " %1";
-	    }
-	    Configuration.setPreviewCommand(program_str);
-
-	    boolean site_changed = false;
-	    if (Gatherer.GS3) {
-		String current_site = Configuration.site_name;
-		String new_site =(String)site_combobox.getSelectedItem() ;
-		if (!new_site.equals(current_site)) {
-		    site_changed = true;
-		}
-		Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem());
-	    }
-		
-	    Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
-	    Configuration.setString("general.proxy_host", true, proxy_host_field.getText());
-	    Configuration.setString("general.proxy_port", true, proxy_port_field.getValue() + "");
-	    Gatherer.setProxy();
-
-	    // General preferences
-	    Configuration.setEmail(email_field.getText());
-
-	    Configuration.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, use_subfields_checkbox.isSelected());
-	    // Force both workspace and collection trees to redraw
-	    if (Gatherer.g_man != null) {
-		Gatherer.g_man.refreshWorkspaceTree(DragTree.TREE_DISPLAY_CHANGED);
-		Gatherer.g_man.refreshCollectionTree(DragTree.TREE_DISPLAY_CHANGED);
-	    }
-*/
-            //save selected languages list box
-            
-            //goes here
-            
-            //save subfield checkbox
-            
-	    Configuration.set("Gems.Preferences.Use_Subelements", true, use_subfields_checkbox.isSelected());
-	  //  Gatherer.g_man.enrich_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table
-
-            
+
             //save interface language
 	    String current_lang = Configuration.getLanguage();
@@ -465,83 +281,20 @@
 	    }
             
-            
-            
-            //////////////////////save language limited jlist selections
-            
-             Vector stringVector = new Vector();
-        
-             Object[] selectedValues = language_limited_jlist.getSelectedValues();
-             String concatString = new String();
-             
-             for(int k = 0; k < selectedValues.length; k++) {
-                // System.out.println(language_limited_jlist.getComponent(0).toString());//allSelectedLanguages[k]
-                 
-                 //System.out.println(selectedValues[k]);
-                 
-                 if(selectedValues.length-k > 1) 
-                 concatString = concatString.concat(selectedValues[k].toString() +",");
-                 else
-                 concatString = concatString.concat(selectedValues[k].toString());
-                   
+	    //Set language_code_jlist to have the same selections as the language_limited_jlist.
+	    //(before, there was only one JList, and it only contained the language codes).
+	    int[] selection = language_limited_jlist.getSelectedIndices();
+	    language_code_jlist.setSelectedIndices(selection);
+	    Object[] selectedValues = language_code_jlist.getSelectedValues();
+	    String concatString = new String();
+	    
+	    for(int k = 0; k < selectedValues.length; k++) { 
+		if(selectedValues.length-k > 1) 
+		    concatString = concatString.concat(selectedValues[k].toString() +",");
+		else
+		    concatString = concatString.concat(selectedValues[k].toString());
              }
             
-            
-           // System.out.println("final cat string: "+ concatString);
-            
-        
             Configuration.setString("GEMS.Preferences.Selected_Languages",true, concatString);
             
-            ///////////////////
-/*
-	    // Mode preferences
-	    int current_mode = Configuration.getMode();
-	    int new_mode;
-	    if(assistant_mode_radio_button.isSelected()) {
-		new_mode = Configuration.ASSISTANT_MODE;
-	    }
-	    else if(systems_mode_radio_button.isSelected()) {
-		new_mode = Configuration.SYSTEMS_MODE;
-	    }
-	    else if(expert_mode_radio_button.isSelected()) {
-		new_mode = Configuration.EXPERT_MODE;
-	    }
-	    else  {
-		new_mode = Configuration.LIBRARIAN_MODE;
-	    }
-	    // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know
-	    if(new_mode != current_mode) {
-		Configuration.setMode(new_mode);
-		Collection collection = Gatherer.c_man.getCollection();
-		if (collection != null) {
-		    collection.cdm.modeChanged(new_mode);
-		}
-		Gatherer.g_man.modeChanged(new_mode);
-	    }
-	    // Warning preferences
-	    for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {
-		Entry entry = warning_preferences_check_list.get(i);
-		Configuration.set(entry.getProperty(), true, entry.isSelected());
-	    }
-
-	    if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection()!=null) {
-		// shut down the collection
-		System.err.println("shutting down teh collection");
-		Gatherer.g_man.closeCurrentCollection();
-	    }
-*/
-	    // Workflow preferences
-	    // Configuration.set("workflow.mirror", false, workflow_mirror.isSelected());
-	    // Configuration.set("workflow.gather", false, workflow_gather.isSelected());
-	    // Configuration.set("workflow.enrich", false, workflow_enrich.isSelected());
-	    // Configuration.set("workflow.design", false, workflow_design.isSelected());
-	    // Configuration.set("workflow.export", false, workflow_export.isSelected());
-	    // Configuration.set("workflow.create", false, workflow_create.isSelected());
-	    // Gatherer.g_man.workflowUpdate("Mirror", workflow_mirror.isSelected());
-	    // Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());
-	    // Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());
-	    // Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Configuration.getMode() > Configuration.ASSISTANT_MODE));
-	    // Gatherer.g_man.workflowUpdate("Export", workflow_export.isSelected());
-	    // Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
-
 	    // Always save configuration changes immediately (in case the GLI crashes)
 	    Configuration.save();
@@ -592,50 +345,4 @@
     }
 
-    /** This listener updates the mode description depending on what mode is selected. */
-    private class ModeRadioButtonListener
-	implements ActionListener {
-	public void actionPerformed(ActionEvent event) {
-	    Object source = event.getSource();
-	    if(source == assistant_mode_radio_button) {
-		mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
-	    }
-	    else if(source == expert_mode_radio_button) {
-		mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
-	    }
-	    else if(source == systems_mode_radio_button) {
-		mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
-	    }
-	    else {
-		mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
-	    }
-	    source = null;
-	}
-    }
-
-    private class PredefinedActionListener
-	implements ActionListener {
-	public void actionPerformed(ActionEvent event) {
-	    JComboBox cb = (JComboBox) event.getSource();
-	    WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();
-	    CheckboxUpdater task = new CheckboxUpdater(element);
-	    SwingUtilities.invokeLater(task);
-	}
-
-	private class CheckboxUpdater
-	    implements Runnable {
-	    private WorkflowElementWrapper element;
-	    public CheckboxUpdater(WorkflowElementWrapper element) {
-		this.element = element;
-	    }
-	    public void run() {
-		workflow_create.setSelected(element.getEnabled("create"));
-		workflow_mirror.setSelected(element.getEnabled("mirror"));
-		workflow_gather.setSelected(element.getEnabled("gather"));
-		workflow_enrich.setSelected(element.getEnabled("enrich"));
-		workflow_design.setSelected(element.getEnabled("design"));
-		workflow_export.setSelected(element.getEnabled("export"));
-	    }
-	}
-    }
 
     private class LanguageComboboxListener
@@ -651,62 +358,94 @@
 	}
     }
-
-    private class SiteComboboxListener
-	implements ActionListener {
-	private boolean ignore_event=false;
-	public void actionPerformed(ActionEvent event) {
-	    System.err.println("event occurred "+event.paramString());
-	    String site = (String) site_combobox.getSelectedItem();
-	    System.err.println("new site = "+site);
-	    if (!site.equals(current_site_selection)) {
-		current_site_selection = site;
-		System.err.println("changed the current selection");
-		ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
-		if (servlet_options == null) {
-		    System.err.println("no servlets for this site");
-		    servlet_combobox.setModel(new DefaultComboBoxModel());
-		    Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip2");
-		    servlet_combobox.setEnabled(false);
-
-		} else {
-		    System.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
-		    servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
-		    Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip");
-		    servlet_combobox.setEnabled(true);
-		}
-	    }
-	}    
-    }
-
-    private class UseProxyListener
-	implements ActionListener {
-	public void actionPerformed(ActionEvent event) {
-	    boolean enabled = use_proxy_checkbox.isSelected();
-	    Configuration.set("general.use_proxy", true, enabled);
-	    // Fortunately this is already driven by the event thread.
-	    proxy_host_field.setEnabled(enabled);
-	    proxy_port_field.setEnabled(enabled);
-	}
-    }
-
-    private class WorkflowElementWrapper {
-	private Element element;
-	private String text;
-	public WorkflowElementWrapper(Element element) {
-	    this.element = element;
-	}
-	public boolean getEnabled(String name) {
-	    boolean result = true;
-	    if(element.getAttribute(name).equalsIgnoreCase("false")) {
-		result = false;
-	    }
-	    return result;
-	}
-	public String toString() {
-	    if(text == null) {
-		text = element.getFirstChild().getNodeValue();
-	    }
-	    return text;
-	}
-    }
 }
+
+
+/**
+   A custom list renderer, to display tabs in the JList properly.
+
+   @see http://manning.com/sbe/files/uts2/Chapter10html/Chapter10.htm
+   Added by Matthew Whyte
+   Date last modified: 1/02/05
+ */
+class TabListCellRenderer extends JLabel implements ListCellRenderer
+{
+    protected static Border m_noFocusBorder;
+    protected FontMetrics m_fm = null;
+    protected Insets m_insets = new Insets(0, 0, 0, 0);
+    
+    protected int m_defaultTab = 50;
+    protected int[] m_tabs = null;
+    
+    public TabListCellRenderer()
+    {
+	super();
+	m_noFocusBorder = new EmptyBorder(1, 1, 1, 1);
+	setOpaque(true);
+	setBorder(m_noFocusBorder);
+    }
+
+    public Component getListCellRendererComponent(JList list,
+						  Object value, int index, boolean isSelected, boolean cellHasFocus)     
+    {         
+	setText(value.toString());
+	
+	setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
+	setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
+	
+	setFont(list.getFont());
+	setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : m_noFocusBorder);
+	
+	return this;
+    }
+    
+    public void setDefaultTab(int defaultTab) { m_defaultTab = defaultTab; }
+    
+    public int getDefaultTab() { return m_defaultTab; }
+
+    public void setTabs(int[] tabs) { m_tabs = tabs; }
+
+    public int[] getTabs() { return m_tabs; }
+
+    public int getTab(int index)
+    {
+	if (m_tabs == null)
+	    return m_defaultTab*index;
+		
+	int len = m_tabs.length;
+	if (index >= 0 && index < len)
+	    return m_tabs[index];
+
+	return m_tabs[len-1] + m_defaultTab*(index-len+1);
+    }
+
+
+    public void paint(Graphics g)
+    {
+	m_fm = g.getFontMetrics();
+	
+	g.setColor(getBackground());
+	g.fillRect(0, 0, getWidth(), getHeight());
+	getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());
+
+	g.setColor(getForeground());
+	g.setFont(getFont());
+	m_insets = getInsets();
+	int x = m_insets.left;
+	int y = m_insets.top + m_fm.getAscent();
+
+	StringTokenizer	st = new StringTokenizer(getText(), "\t");
+	while (st.hasMoreTokens()) 
+	{
+	      String sNext = st.nextToken();
+	      g.drawString(sNext, x, y);
+		x += m_fm.stringWidth(sNext);
+
+		if (!st.hasMoreTokens())
+		    break;
+		int index = 0;
+		while (x >= getTab(index))
+		    index++;
+		x = getTab(index);
+	}
+    }   
+}
Index: /trunk/gli/src/org/greenstone/gatherer/gems/MSMUtils.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/MSMUtils.java	(revision 8970)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/MSMUtils.java	(revision 8971)
@@ -44,4 +44,5 @@
 import org.greenstone.gatherer.util.StaticStrings;
 import org.greenstone.gatherer.util.Utility;
+import org.greenstone.gatherer.util.XMLTools;
 import org.w3c.dom.*;
 /** This class contains a plethora of methods associated with handling the content of <strong>MetadataSet</strong>s and the <strong>Element</strong>s within. For example this is where you will find methods for comparing various parts of two <strong>MetadataSet</strong>s for equality. It also has methods for extracting common and useful data from <strong>Element</strong>s such as the AssignedValue nodes.
@@ -93,11 +94,13 @@
 	attribute_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, attribute_name_str);
 	MSMUtils.setValue(attribute_element, value_str);
+
 	// Start off by determining if we have to add this node in the new multilingual optimized way
 	if(isAttributeLanguageDependant(document, attribute_name_str)) {
 	    boolean found = false;
 	    // Try to retrieve a language element for the given language code
-	    NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
-	    for(int i = 0; i < language_elements.getLength(); i++) {
-		Element language_element = (Element) language_elements.item(i);
+	    //NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
+	    ArrayList language_elements = XMLTools.getChildElementsByTagName(element_element, StaticStrings.LANGUAGE_ELEMENT);
+	    for(int i = 0; i < language_elements.size(); i++) {
+		Element language_element = (Element) language_elements.get(i);
 		if(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).equals(language_code_str)) {
 		    found = true;
@@ -736,9 +739,22 @@
      * @param attribute_name_str the name of the attribute we a testing as a String
      * @see org.greenstone.gatherer.util.StaticStrings#LANGUAGEDEPENDANT_ATTRIBUTE
+     * Modified by Matthew Whyte 4/02/05
      */
     static private boolean isAttributeLanguageDependant(Document document, String attribute_name_str)
     {
+	//gives a list of comma seperated language specific attributes.
 	String language_specific_attributes = document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE).toLowerCase();
-	return language_specific_attributes.indexOf(attribute_name_str) != -1;
+	//System.err.println("lang_specific: " + language_specific_attributes); //debug
+
+	//Seperate out language_specific_attributes
+	String[] attributes_split = language_specific_attributes.split(",");
+
+	//Compare each to attribute_name_str
+	for(int i = 0; i < attributes_split.length; i++)
+	    {
+		if(attributes_split[i].trim().compareTo(attribute_name_str.toLowerCase()) == 0)
+		    return true;
+	    }
+	return false;
     }
 
@@ -802,45 +818,67 @@
      */
     static public boolean removeElementAttribute(Element element_element, String attribute_name_str, String language_code_str, String value_str) {
-	// Multilingual Optimized version
-	// 1. Determine the if this is one of the language specific attributes
-	if(isAttributeLanguageDependant(element_element.getOwnerDocument(), attribute_name_str)) {
-	    // Retrieve the language elements, and determine the correct one
-	    NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
-	    for(int i = 0; i < language_elements.getLength(); i++) {
-		Element language_element = (Element) language_elements.item(i);
-		if(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).equalsIgnoreCase(language_code_str)) {
-		    NodeList attribute_elements = language_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT);
-		    for(int j = 0; j < attribute_elements.getLength(); j++) {
-			Element attribute_element = (Element) attribute_elements.item(j);
-			String target_name_str = attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
-			String target_value_str = MSMUtils.getValue(attribute_element);
-			if(attribute_name_str.equals(target_name_str) && value_str.equals(target_value_str)) {
-			    language_element.removeChild(attribute_element);
-			    if(attribute_elements.getLength() == 0) {
-				element_element.removeChild(language_element);
-			    }
-			    target_value_str = null;
-			    target_name_str = null;
-			    attribute_element = null;
-			    attribute_elements = null;
-			    language_element = null;
-			    language_elements = null;
-			    return true;
+	//Determine the if this is one of the language specific attributes.
+	//This can sometimes give a false result, if an attribute is made language specific half way through creation of a metadata set (or vice versa).
+	if(isAttributeLanguageDependant(element_element.getOwnerDocument(), attribute_name_str))
+	    {
+		/*
+		Multilingual Optimized version, eg:
+		<Language code="en">
+		    <Attribute name="identifier">second</Attribute>
+		</Language>
+		*/
+		return removeElementAttributeNew(element_element, attribute_name_str, language_code_str, value_str, false);
+	    }
+	else
+	    {
+		/*
+		The old way, eg:
+		<Attribute language="en" name="identifier">second</Attribute>
+		*/
+		return removeElementAttributeOld(element_element, attribute_name_str, language_code_str, value_str, false);
+	    }
+	
+    }
+    static final private boolean removeElementAttributeNew(Element element_element, String attribute_name_str, String language_code_str, String value_str, boolean run_once)
+    {
+	// Retrieve the language elements, and determine the correct one
+	NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
+	for(int i = 0; i < language_elements.getLength(); i++) {
+	    Element language_element = (Element) language_elements.item(i);
+	    if(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).equalsIgnoreCase(language_code_str)) {
+		NodeList attribute_elements = language_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT);
+		for(int j = 0; j < attribute_elements.getLength(); j++) {
+		    Element attribute_element = (Element) attribute_elements.item(j);
+		    String target_name_str = attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
+		    String target_value_str = MSMUtils.getValue(attribute_element);
+		    if(attribute_name_str.equals(target_name_str) && value_str.equals(target_value_str)) {
+			language_element.removeChild(attribute_element);
+			if(attribute_elements.getLength() == 0) {
+			    element_element.removeChild(language_element);
 			}
 			target_value_str = null;
 			target_name_str = null;
-			attribute_element = null;			
+			attribute_element = null;
+			attribute_elements = null;
+			language_element = null;
+			language_elements = null;
+			return true;
 		    }
-		    attribute_elements = null;
-		}
-		language_element = null;
-	    }
-	    language_elements = null;
-	    // Not found
-	    //System.err.println("new optimised way failed."); //debug
-	    return false;
-	} // end if
-	// Otherwise just use the old method
-
+		    target_value_str = null;
+		    target_name_str = null;
+		    attribute_element = null;			
+		}
+		attribute_elements = null;
+	    }
+	    language_element = null;
+	}
+	language_elements = null;
+	// Not found. Try the old way before failing.
+	if(!run_once)
+	    return removeElementAttributeOld(element_element, attribute_name_str, language_code_str, value_str, true);
+	return false;
+    }
+    static final private boolean removeElementAttributeOld(Element element_element, String attribute_name_str, String language_code_str, String value_str, boolean run_once)
+    {
 	// Find the attribute to remove
 	NodeList attribute_elements = element_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT);
@@ -858,6 +896,7 @@
 	}
 	attribute_elements = null;
-	// No match found
-	//System.err.println("Old method failed."); //debug
+	// No match found. Try the new way before failing.
+	if(!run_once)
+	    return removeElementAttributeNew(element_element, attribute_name_str, language_code_str, value_str, true);
 	return false;
     }
Index: /trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java	(revision 8970)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java	(revision 8971)
@@ -496,10 +496,7 @@
     /** Method to remove the given element from this metadata set.
      * @param element The <strong>Element</strong> to be removed.
-     * @param parent The parent element, as an <strong>Element</strong>. If null, the parent is root.
-     */
-    public void removeElement(Element element, Element parent) {
-	// we need to remove the value tree too!!
-	//System.err.println("removeElement in MetadataSet: element is: " + element); //Debug
-
+     * @param parent The parent element (wrapped, so can access its subelement list), as an <strong>ElementWrapper</strong>. If null, the parent is root.
+     */
+    public void removeElement(Element element, ElementWrapper parent) {
 	try {
 	    ElementWrapper element_wrapped = new ElementWrapper(element);
@@ -508,10 +505,12 @@
 	    if(parent == null)
 		{
-		    parent = root;
+		    elements.remove(element);
+		    root.removeChild(element);
 		}
-	    
-	    //Want to remove subelement.
-	    //System.err.println("Wanna remove subelement"); //debug
-	    parent.removeChild(element);
+	    else
+		{
+		    parent.removeSubelementFromList(element);
+		    parent.getElement().removeChild(element);
+		}
 	    
 	} catch(Exception DOMException) { //The element does not exist!!
Index: /trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java	(revision 8970)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java	(revision 8971)
@@ -405,5 +405,4 @@
            if(st.nextToken().compareTo("collect") == 0) {
             colName = st.nextToken();  
-	    System.err.println("colName is: " + colName); //debug
            // metadata_set.old_filename = metadata_set.getName();
            // metadata_set.setName(new String("(" + colName + ") " + metadata_set.getName()) );
@@ -431,4 +430,6 @@
        @return void
        Modified by Matthew Whyte 19/01/04
+
+       This should really be totally replaced by MetadataSet.removeElement --Matthew
      */
     public void removeElement(ElementWrapper element, ElementWrapper parent) {
@@ -439,12 +440,5 @@
 	if(set != null) {
 	    //Remove the element
-	    if(parent == null)
-		{
-		    set.removeElement(element.getElement(), null); //Let's not cause an exception!
-		}
-	    else
-		{
-		    set.removeElement(element.getElement(), parent.getElement());
-		}
+	    set.removeElement(element.getElement(), parent);
 	}
 	else {
@@ -463,6 +457,4 @@
     public void renameElement(ElementWrapper oldElement, String newName)
     {
-	GEMSNode node = null;
-
 	//Retrive the metadata set this element belongs to.
 	String namespace = oldElement.getNamespace();
@@ -491,5 +483,4 @@
 	    for(int i = 0; i < all_values.size(); i++) {
 		GValueNode node = (GValueNode)all_values.get(i);
-		TreePath path = new TreePath(node.getPath());
 		String full_value = node.getFullPath(false);
  		String index = model.getHIndex(full_value);
