Index: /trunk/gli/src/org/greenstone/gatherer/mem/MetadataEditorManager.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/mem/MetadataEditorManager.java	(revision 4435)
+++ /trunk/gli/src/org/greenstone/gatherer/mem/MetadataEditorManager.java	(revision 4436)
@@ -77,4 +77,6 @@
     /** 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;
@@ -84,4 +86,5 @@
     private MetadataEditorManager self = null;
     private int current_attribute = -1;
+    private int current_attribute_type = -1;
     private JButton add_attribute = null;
     private JButton add_element = null;
@@ -104,4 +107,5 @@
     private JScrollPane set_attributes_scroll = null;
     private JPanel details_pane = null;
+    private JPanel element_values_pane = null;
     private KeepTreeRootExpandedListener keep_root_expanded_listener = null;
     private MEMModel model = null;
@@ -129,4 +133,5 @@
     static final private String PROFILE = "profile";
     static final private String SET = "set";
+    static final private String VALUES = "values";
     /** Constructor. */
     public MetadataEditorManager() {
@@ -225,5 +230,6 @@
 	element_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
-	JPanel element_values_pane = new JPanel();
+	element_values_layout = new CardLayout();
+	element_values_pane = new JPanel();
 	element_values_pane.setOpaque(false);
 	element_values = new SmarterTree();
@@ -233,4 +239,6 @@
 	element_values.setSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false));
 	element_values.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false));
+
+	JPanel element_novalues_pane = new JPanel();
 	    
 	keep_root_expanded_listener = new KeepTreeRootExpandedListener();
@@ -371,6 +379,9 @@
 		  
 	element_values_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(get("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(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 GridLayout(2,1));
@@ -531,5 +542,5 @@
 	    setSize(ADD_OR_EDIT_ATTRIBUTE_SIZE);
 	    name_to_values = new HashMap();
-				// Creation
+	    // Creation
 	    JPanel content_pane = (JPanel) getContentPane();
 	    content_pane.setBackground(Gatherer.config.getColor("coloring.collection_heading_background", false));
@@ -625,80 +636,88 @@
 	    if(source == ok_button) {
 		boolean cont = true;
+		AttributeTableModel model = null;
+		switch(current_attribute_type) {
+		case MEMNode.COLLECTION:
+		    model = (AttributeTableModel) profile_attributes.getModel();
+		    break;
+		case MEMNode.ELEMENT:
+		    model = (AttributeTableModel) element_attributes.getModel();
+		    break;
+		case MEMNode.SET:
+		    model = (AttributeTableModel) set_attributes.getModel();
+		    break;
+		}
 		// Now we add the new or improved values, removing old values if this is an edit.
 		// Depends on what we are adding the attribute to.
-		if(current_collection_file != null) {
-		    String name_str = name.getSelectedItem().toString();
-		    String value_str = value.getText();
-		    AttributeTableModel model = (AttributeTableModel) profile_attributes.getModel();
-		    // Remove the existing one if this is an edit.
-		    if(!add_type && current_attribute != -1) {
-			String old_source = (String) profile_attributes.getValueAt(current_attribute, 0);
-			Gatherer.c_man.msm.profiler.removeAction(current_collection_file, old_source);
-			old_source = null;
-			model.removeRow(current_attribute);
-		    }
-		    // First thing we check from profiles is that there isn't already an entry for this name.
-		    if(!model.contains(name_str, 0)) {
-			// Add profile
-			Gatherer.c_man.msm.profiler.addAction(current_collection_file, name_str, value_str);
-			// Update attribute table.
-			model.add(new Attribute(name_str, value_str));
-		    }
-		    else {
-			// Show an error message and do not proceed.
-			cont = false;
-			JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
+		if(model != null) {
+		    if(current_collection_file != null) {
+			String name_str = name.getSelectedItem().toString();
+			String value_str = value.getText();
+			// Remove the existing one if this is an edit.
+			if(!add_type && current_attribute != -1) {
+			    String old_source = (String) model.getValueAt(current_attribute, 0);
+			    Gatherer.c_man.msm.profiler.removeAction(current_collection_file, old_source);
+			    old_source = null;
+			    model.removeRow(current_attribute);
+			}
+			// First thing we check from profiles is that there isn't already an entry for this name.
+			if(!model.contains(name_str, 0)) {
+			    // Add profile
+			    Gatherer.c_man.msm.profiler.addAction(current_collection_file, name_str, value_str);
+			    // Update attribute table.
+			    model.add(new Attribute(name_str, value_str));
+			}
+			else {
+			    // Show an error message and do not proceed.
+			    cont = false;
+			    JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
+			}
+			value_str = null;
+			name_str = null;
+		    }
+		    else if(current_element != null) {
+			// Add the attribute, even if one of the same name already exists. Maybe one day someone would like to enforce the occurance rules but not me and not today.
+			String name_str = name.getSelectedItem().toString();
+			String language_code = ((Language)language_box.getSelectedItem()).getCode();
+			String value_str = value.getText();
+			// Remove the existing one if this is an edit.
+			if(!add_type && current_attribute != -1) {
+			    model.removeRow(current_attribute);
+			}
+			// Add attribute
+			current_element.addAttribute(name_str, language_code, value_str);
+			// Update the attribute table
+			model.add(new Attribute(name_str, language_code, value_str));
+			value_str = null;
+			language_code = null;
+			name_str = null;
+		    }
+		    else if(current_set != null) {
+			String name_str = name.getSelectedItem().toString();
+			String value_str = value.getText();						
+			// Remove the existing one if this is an edit.
+			if(!add_type && current_attribute != -1) {
+			    model.removeRow(current_attribute);
+			}
+			// First thing we check from profiles is that there isn't already an entry for this name.
+			if(!model.contains(name_str, 0)) {
+			    // Add profile
+			    current_set.addAttribute(name_str, value_str);
+			    // Update attribute table.
+			    model.add(new Attribute(name_str, value_str));
+			}
+			// Otherwise provide an error message and do not proceed.
+			else {
+			    cont = false;
+			    JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
+			}
+			value_str = null;
+			name_str = null;
+		    }
+		    // Hide dialog if we are allowed to continue.
+		    if(cont) {
+			setVisible(false);
 		    }
 		    model = null;
-		    value_str = null;
-		    name_str = null;
-		}
-		else if(current_element != null) {
-		    // Add the attribute, even if one of the same name already exists. Maybe one day someone would like to enforce the occurance rules but not me and not today.
-		    String name_str = name.getSelectedItem().toString();
-		    String language_code = ((Language)language_box.getSelectedItem()).getCode();
-		    String value_str = value.getText();
-		    AttributeTableModel model = (AttributeTableModel) element_attributes.getModel();
-		    // Remove the existing one if this is an edit.
-		    if(!add_type && current_attribute != -1) {
-			model.removeRow(current_attribute);
-		    }
-		    // Add attribute
-		    current_element.addAttribute(name_str, language_code, value_str);
-		    // Update the attribute table
-		    model.add(new Attribute(name_str, language_code, value_str));
-		    model = null;
-		    value_str = null;
-		    language_code = null;
-		    name_str = null;
-		}
-		else if(current_set != null) {
-		    String name_str = name.getSelectedItem().toString();
-		    String value_str = value.getText();						
-		    // First thing we check from profiles is that there isn't already an entry for this name.
-		    AttributeTableModel model = (AttributeTableModel) set_attributes.getModel();
-		    // Remove the existing one if this is an edit.
-		    if(!add_type && current_attribute != -1) {
-			model.removeRow(current_attribute);
-		    }
-		    // First thing we check from profiles is that there isn't already an entry for this name.
-		    if(!model.contains(name_str, 0)) {
-			// Add profile
-			current_set.addAttribute(name_str, value_str);
-			// Update attribute table.
-			model.add(new Attribute(name_str, value_str));
-		    }
-		    // Otherwise provide an error message and do not proceed.
-		    else {
-			cont = false;
-			JOptionPane.showMessageDialog(self, get("Attribute_Already_Exists"), get("General.Error"), JOptionPane.ERROR_MESSAGE);
-		    }
-		    model = null;
-		    value_str = null;
-		    name_str = null;
-		}
-		// Hide dialog if we are allowed to continue.
-		if(cont) {
-		    setVisible(false);
 		}
 	    }
@@ -825,8 +844,21 @@
 		}
 		else if(current_attribute != -1) {
+		    AttributeTableModel model = null;
+		    switch(current_attribute_type) {
+		    case MEMNode.COLLECTION:
+			model = (AttributeTableModel) profile_attributes.getModel();
+			break;
+		    case MEMNode.ELEMENT:
+			model = (AttributeTableModel) element_attributes.getModel();
+			break;
+		    case MEMNode.SET:
+			model = (AttributeTableModel) set_attributes.getModel();
+			break;
+		    }
 		    add_type = false;
 		    setTitle(get("EditAttribute"));
-		    String name_str = (String) profile_attributes.getValueAt(current_attribute, 0);
-		    String value_str = (String) profile_attributes.getValueAt(current_attribute, 1);
+		    String name_str = (String) model.getValueAt(current_attribute, 0);
+		    String value_str = (String) model.getValueAt(current_attribute, model.getColumnCount() - 1);
+		    model = null;
 		    // Retrieve the appropriate value model
 		    java.util.List values = (java.util.List) name_to_values.get(name_str);
@@ -838,5 +870,11 @@
 		    name_str = null;
 		    for(int i = 0; i < values.size(); i++) {
-			value.add(new NameElementWrapperEntry(values.get(i)));
+			Object temp_value = values.get(i);
+			if(temp_value instanceof ElementWrapper) {
+			    value.add(new NameElementWrapperEntry(temp_value));
+			}
+			else {
+			    value.add(temp_value);
+			}
 		    }
 		    values = null;
@@ -1678,12 +1716,14 @@
 	}
 	public void valueChanged(ListSelectionEvent event) {
-	    if((current_attribute = table.getSelectedRow()) != -1) {
-		edit_attribute.setEnabled(true);
-		remove_attribute.setEnabled(true);
-	    }
-	    else {
-		current_attribute = -1;
-		edit_attribute.setEnabled(false);
-		remove_attribute.setEnabled(false);
+	    if(!event.getValueIsAdjusting()) {
+		if((current_attribute = table.getSelectedRow()) != -1) {
+		    edit_attribute.setEnabled(true);
+		    remove_attribute.setEnabled(true);
+		}
+		else {
+		    current_attribute = -1;
+		    edit_attribute.setEnabled(false);
+		    remove_attribute.setEnabled(false);
+		}
 	    }
 	}
@@ -1722,5 +1762,6 @@
 		AttributeTableModel atm = null;
 		TreeSet attributes = null;
-		switch(current_node.getType()) {
+		current_attribute_type = current_node.getType();
+		switch(current_attribute_type) {
 		case MEMNode.COLLECTION:
 		    current_collection_file = current_node.toString();
@@ -1760,10 +1801,18 @@
 		    // Be careful not to add the keep_root_expanded_listener over and over!
 		    GValueModel value_model = Gatherer.c_man.msm.getValueTree(current_element);
-		    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);
+		    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);
+			// Meanwhile disable/enable controls depending on this Element selection.
+			setControls(true, false, false, false, false, true, true, false, false, true, false, false);
+		    }
+		    else {
+			element_values_layout.show(element_values_pane, BLANK);
+			// Meanwhile disable/enable controls depending on this Element selection.
+			setControls(true, false, false, false, false, false, true, false, false, false, false, false);
+		    }
 		    card_layout.show(details_pane, ELEMENT);
-		    // Meanwhile disable/enable controls depending on this Element selection.
-		    setControls(true, false, false, false, false, true, true, false, false, true, false, false);
 		    break;
 		case MEMNode.SET:
