Index: trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java
===================================================================
--- trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java	(revision 10965)
+++ trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java	(revision 10966)
@@ -55,4 +55,5 @@
     static final private String MGPPINDEXES = "mgpp indexes";
 
+    static final private String ALLFIELDS = "allfields";
     /** The controls for editing the indexes. */
     private Control controls = null;
@@ -305,4 +306,32 @@
     }
 
+    /* replace an index in the list. new index may have the same sources but a
+       different name, or may be a new index altogether */
+    private void replaceIndex(Index old_index, Index new_index,
+			      CollectionMeta coll_meta) {
+	if (old_index == null || new_index == null || coll_meta == null) {
+	    return;
+	}
+	if (!old_index.getID().equals(new_index.getID()) && contains(new_index)) {
+	    // shoudl we output an error??
+	    System.err.println("new index is already in the list, but is not the old one");
+	    return;
+	}
+	// Remove the old index coll meta
+	CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + old_index.getID());
+	// Add the new coll meta
+	CollectionDesignManager.collectionmeta_manager.addMetadatum(coll_meta);
+
+	// get the position of the old one
+	int position = indexOf(old_index);
+	// remove it
+	remove(old_index);
+	// add the new one at that position
+	add(position, new_index);
+
+	// Schedule the collection for saving
+	Gatherer.c_man.configurationChanged();
+    }
+
     /** Method to set the default index.
      * @param index the new default Index
@@ -362,11 +391,8 @@
 		    if(0 <= level_int && level_int < 3) {
 			String level = Index.LEVEL[level_int];
-			if(!levels_list.contains(level)) {
-			    levels_list.add(level);
-			}
+			levels_list.add(level);
 			level = null;
 		    }
 		    ArrayList sources = default_index.getSources();
-		    sources.removeAll(sources_list);
 		    sources_list.addAll(sources);
 		}
@@ -435,4 +461,5 @@
 	    }
 	    else {
+		// we already have mgpp indexes assigned
 		// Replace mg element with mgpp element
 		setRoot(mgpp_element);
@@ -441,7 +468,8 @@
 	    mg_element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, CollectionConfiguration.FALSE_STR);
 	    mg_element = null;
-	    if(default_index != null) {
-		default_index.setAssigned(false);
-	    }
+ 	    if(default_index != null) {
+ 		//default_index.setAssigned(false);
+		default_index.setLevel(-1);
+ 	    }
 	}
 	// change MGPP -> MG
@@ -453,7 +481,8 @@
 	    if(default_index != null) {
 		default_index.setAssigned(true);
+		default_index.setLevel(1); // for now
 	    }
 	    // If mg element has no indexes, and the current mgpp index include a text one, then generate text indexes for each of the registered levels.
-	    NodeList indexes = mgpp_element.getElementsByTagName(CollectionConfiguration.INDEX_ELEMENT);
+	    NodeList indexes = mg_element.getElementsByTagName(CollectionConfiguration.INDEX_ELEMENT);
 	    if(indexes.getLength() == 0) {
 		Index index = getIndex(CollectionConfiguration.TEXT_STR);
@@ -502,24 +531,39 @@
 	implements Control {
 
-	private CardLayout card_layout;
-	private CheckList source_list;
-	private JButton add_button;
+	private JTextArea instruction_textarea; 
+
+	private JList index_list;
+
 	private JButton move_down_button;
 	private JButton move_up_button;
+	private JButton set_default_button;
+
+	private JTextField name_textfield ;
+	private CheckList source_list;
+	// mg uses a level box
+	private JComboBox level_combobox;
+	// mgpp has a allfields selector
+	private JCheckBox allfields_box;
+
+	private JButton add_button;
+	private JButton add_all_button;
 	private JButton remove_button;
 	private JButton replace_button;
-	private JButton set_default_button;
-	private JComboBox level_combobox;
-	private JList index_list;
-	private JTextArea instruction_textarea;
-	private JTextField name_textfield ;
-	// when we are in mgpp mode, we want to remove the mg listener 
-	// the underlying model is the same between the two JLists, and
-	// both listeners get notified when the model changes, but the mg
-	// listener doesn't care about mgpp events
-	private ListSelectionListener index_list_listener;
- 	
-	private MGPPControl mgppindexes_control;
-
+
+	// soem panels that we need to manipulate later on
+	private JPanel boxes_pane;
+	private JPanel labels_pane;
+	private JLabel level_label;
+	private JPanel allfields_pane;
+	
+	// we add in a tabbed pane for mgpp mode
+	private JTabbedPane tabbed_pane;
+	// the main index set up pane
+	private JPanel main_index_pane;
+
+	// for the levels tab in mgpp mode
+	private MGPPLevelsPanel mgpplevels_pane;
+
+	private boolean mgpp_enabled = false;
 	/** Constructor.
 	 * @see org.greenstone.gatherer.Configuration
@@ -537,12 +581,6 @@
 	    new_data.add(CollectionConfiguration.TEXT_STR);
 	    new_data.addAll(MetadataSetManager.getEveryMetadataSetElement());
+	    
 	    // Creation
-	    JPanel mgindexes_panel = new JPanel();
-	    card_layout = new CardLayout();
-
-	    // MG Index Controls
-
-	    JPanel mg_indexes_pane = new JPanel();
-
 	    JPanel instruction_pane = new JPanel();
 	    JLabel title_label = new JLabel();
@@ -556,5 +594,5 @@
 	    instruction_textarea.setWrapStyleWord(true);
 	    Dictionary.registerText(instruction_textarea, "CDM.IndexManager.Instructions");
-
+	    
 	    JPanel assigned_indexes_pane = new JPanel();
 	    JLabel index_label = new JLabel();
@@ -563,6 +601,8 @@
 	    index_list.setCellRenderer(new IndexListRenderer());
 	    index_list.setVisibleRowCount(2);
+	    index_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+	    
+	    
 	    JPanel movement_pane = new JPanel();
-
 	    move_up_button = new JButton("", JarTools.getImage("arrow-up.gif"));
 	    move_up_button.setEnabled(false);
@@ -574,5 +614,5 @@
 	    move_down_button.setMnemonic(KeyEvent.VK_D);
 	    Dictionary.registerBoth(move_down_button, "CDM.Move.Move_Down", "CDM.Move.Move_Down_Tooltip");
-
+	    
 	    set_default_button = new GLIButton();
 	    set_default_button.setEnabled(false);
@@ -580,9 +620,9 @@
 	    Dictionary.registerBoth(set_default_button, "CDM.IndexManager.Set_Default", "CDM.IndexManager.Set_Default_Tooltip");
 
-	    JPanel index_pane = new JPanel();
+	    JPanel new_index_pane = new JPanel();
 	    JPanel details_pane = new JPanel();
-	    JPanel labels_pane = new JPanel();
-	    JPanel boxes_pane = new JPanel();
-	    JPanel content_pane = new JPanel();
+	    labels_pane = new JPanel();
+	    boxes_pane = new JPanel();
+	    main_index_pane = new JPanel();
 
 	    JLabel name_label = new JLabel();
@@ -598,5 +638,5 @@
 	    Dictionary.registerTooltip(source_list, "CDM.IndexManager.Source_Tooltip");
 
-	    JLabel level_label = new JLabel();
+	    level_label = new JLabel();
 	    Dictionary.registerText(level_label, "CDM.IndexManager.Level");
 	    level_combobox = new JComboBox();
@@ -614,4 +654,9 @@
 	    Dictionary.registerBoth(add_button, "CDM.IndexManager.Add_Index", "CDM.IndexManager.Add_Index_Tooltip");
 
+	    add_all_button = new GLIButton();
+	    add_all_button.setEnabled(true);
+	    add_all_button.setMnemonic(KeyEvent.VK_L);
+	    Dictionary.registerBoth(add_all_button, "CDM.IndexManager.MGPP.Add_All_Metadata", "CDM.IndexManager.MGPP.Add_All_Metadata_Tooltip");
+
 	    remove_button = new GLIButton();
 	    remove_button.setEnabled(false);
@@ -623,25 +668,33 @@
 	    Dictionary.registerBoth(replace_button, "CDM.IndexManager.MGPP.Replace_Index", "CDM.IndexManager.MGPP.Replace_Index_Tooltip");
 
-	    // This class is getting a little crowded, so I'll generate the many mgpp controls in a inner class.
-	    mgppindexes_control = new MGPPControl();
-
+	    allfields_pane = new JPanel();
+	    allfields_box = new JCheckBox();
+	    JLabel allfields_label = new JLabel();
+	    Dictionary.registerText(allfields_label, "CDM.IndexManager.Allfields_Index");
+	    allfields_pane.setLayout(new BorderLayout());
+	    allfields_pane.add(allfields_box, BorderLayout.WEST);
+	    allfields_pane.add(allfields_label, BorderLayout.CENTER);
+	    
 	    // Listeners
 	    add_button.addActionListener(new AddListener());
 	    add_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
+	    add_all_button.addActionListener(new AddAllActionListener());
+	    add_all_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
+	    remove_button.addActionListener(new RemoveListener());
+	    remove_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
+	    replace_button.addActionListener(new ReplaceListener());
+	    replace_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
 	    move_down_button.addActionListener(new MoveListener(false));
 	    move_down_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
 	    move_up_button.addActionListener(new MoveListener(true));
 	    move_up_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
-	    remove_button.addActionListener(new RemoveListener());
-	    remove_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
-	    replace_button.addActionListener(new ReplaceListener());
-	    replace_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
 	    set_default_button.addActionListener(new SetDefaultListener());
 	    set_default_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
+
 	    name_textfield.getDocument().addDocumentListener(new NameListener());
 	    level_combobox.addItemListener(new LevelListener());
-	    // Create the index_list_listener but don't add in to the list - this gets done in gainFocus, we don't want it twice.
-	    index_list_listener = new IndexListListener();
+	    index_list.addListSelectionListener(new IndexListListener());
 	    source_list.addListSelectionListener(new SourceListListener());
+	    allfields_box.addItemListener(new AllfieldsCheckBoxListener());
 
 	    // Layout
@@ -678,25 +731,25 @@
 	    details_pane.add(boxes_pane, BorderLayout.CENTER);
 
-	    button_pane.setLayout(new GridLayout(1,3));
+	    button_pane.setLayout(new GridLayout(2,2,5,0));
 	    button_pane.add(add_button);
+	    button_pane.add(add_all_button);
 	    button_pane.add(replace_button);
 	    button_pane.add(remove_button);
 
-	    index_pane.setLayout(new BorderLayout());
-	    index_pane.add(details_pane, BorderLayout.CENTER);
-	    index_pane.add(button_pane, BorderLayout.SOUTH);
-
-	    content_pane.setLayout(new BorderLayout());
-	    content_pane.add(assigned_indexes_pane, BorderLayout.NORTH);
-	    content_pane.add(index_pane, BorderLayout.CENTER);
-
-	    mgindexes_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
-	    mgindexes_panel.setLayout(new BorderLayout());
-	    mgindexes_panel.add(instruction_pane, BorderLayout.NORTH);
-	    mgindexes_panel.add(content_pane, BorderLayout.CENTER);
-
-	    setLayout(card_layout);
-	    add(mgindexes_panel, MGINDEXES);
-	    add(mgppindexes_control, MGPPINDEXES);
+	    new_index_pane.setLayout(new BorderLayout());
+	    new_index_pane.add(details_pane, BorderLayout.CENTER);
+	    new_index_pane.add(button_pane, BorderLayout.SOUTH);
+
+	    main_index_pane.setLayout(new BorderLayout());
+	    main_index_pane.add(assigned_indexes_pane, BorderLayout.NORTH);
+	    main_index_pane.add(new_index_pane, BorderLayout.CENTER);
+
+	    setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+	    setLayout(new BorderLayout());
+	    add(instruction_pane, BorderLayout.NORTH);
+	    add(main_index_pane, BorderLayout.CENTER);
+
+	    // for later, if we go to MGPP mode
+	    tabbed_pane = new JTabbedPane();
 	}
 
@@ -705,47 +758,58 @@
 	 */
 	public void destroy() {
-	    mgppindexes_control.destroy();
-	    mgppindexes_control = null;
 	}
 
 	public void gainFocus() {
-	    boolean mgpp_enabled = CollectionDesignManager.searchtype_manager.isSearchTypeEnabled();
+	    boolean old_mgpp_enabled = mgpp_enabled;
+	    mgpp_enabled = CollectionDesignManager.searchtype_manager.isSearchTypeEnabled();
+	    boolean changed_state = (old_mgpp_enabled != mgpp_enabled);
+	    if (changed_state) {
+		// reset the underlying indexes and levels elements
+		setMGPPEnabled(mgpp_enabled);
+	    }
 	    if(instruction_textarea != null) {
 		instruction_textarea.setCaretPosition(0);
 	    }
+	    /* reset the source list - may have built between then and now */
+	    ArrayList new_data = new ArrayList();
+	    new_data.add(CollectionConfiguration.TEXT_STR);
+	    new_data.addAll(MetadataSetManager.getEveryMetadataSetElement());
+	    source_list.setListData(new_data);
+	    new_data = null;
+	    
 	    if(mgpp_enabled) {
-		// remove the mg index list listener first
-		index_list.removeListSelectionListener(index_list_listener);
-		mgppindexes_control.gainFocus();
+		if (changed_state) {
+		    // switch the variable bits
+		    boxes_pane.remove(level_combobox);
+		    labels_pane.remove(level_label);
+		    boxes_pane.add(allfields_pane, BorderLayout.SOUTH);
+		    //put back the tabbed pane
+		    remove(main_index_pane);
+		    add(tabbed_pane, BorderLayout.CENTER);
+		    tabbed_pane.insertTab(Dictionary.get("CDM.IndexManager.MGPP.Indexes"), null, main_index_pane, null, 0);
+		    if (mgpplevels_pane == null) {
+			mgpplevels_pane = new MGPPLevelsPanel();
+			tabbed_pane.insertTab(Dictionary.get("CDM.IndexManager.MGPP.Levels"), null, mgpplevels_pane, null, 1);
+		    }
+		    
+		}
 	    }
 	    else {
-		// remove the mgpp listener first
-		mgppindexes_control.removeIndexListListener();
-		// add the mg listener back in
-		index_list.addListSelectionListener(index_list_listener);
-		// Reload the assigned indexes list.
-		ArrayList new_data = new ArrayList();
-		new_data.add(CollectionConfiguration.TEXT_STR);
-		new_data.addAll(MetadataSetManager.getEveryMetadataSetElement());
-		// reset the model in the list and combobox
-		source_list.setListData(new_data);
-		new_data = null;
-		// refresh the indexList
-		index_list.updateUI();
-		// if there is one selected, fill in the controls
-		updateControlsWithSelectedIndex();
-	    }
-	    // Bring the appropriate card to the front
-	    if(mgpp_enabled) {
-		card_layout.show(this, MGPPINDEXES);
-	    }
-	    else {
-		card_layout.show(this, MGINDEXES);
-	    }
+		if (changed_state) {
+		    boxes_pane.remove(allfields_pane);
+		    boxes_pane.add(level_combobox, BorderLayout.SOUTH);
+		    labels_pane.add(level_label, BorderLayout.SOUTH);
+		    remove(tabbed_pane);
+		    tabbed_pane.remove(0);
+		    add(main_index_pane, BorderLayout.CENTER);
+		}
+	    }
+	    updateControlsWithSelectedIndex();
+	    
 	}
 
 	public void loseFocus() {
 	}
-
+	
 	private void updateControlsWithSelectedIndex() {
 	    
@@ -760,5 +824,8 @@
 	    String name = CollectionDesignManager.collectionmeta_manager.getMetadatum("." + id).getValue(true);
 	    name_textfield.setText(name);
-	    level_combobox.setSelectedIndex(selected_index.getLevel());
+	    if (!mgpp_enabled) {
+		level_combobox.setSelectedIndex(selected_index.getLevel());
+	    }
+	    // TODO: need to set all fields if necessary
 	    source_list.clearTicked();
 	    ArrayList sources = selected_index.getSources();
@@ -767,56 +834,71 @@
 	}
 	
-	private void validateAddButton()
-	{
+	private void validateAddButton() {
+
+	    String new_index_name = name_textfield.getText();
+	    // indexes must have a name
+	    if (new_index_name.length() == 0) {
+		add_button.setEnabled(false);
+		replace_button.setEnabled(false);
+		return;
+	    }
+	    
 	    boolean add_enabled = false;
 	    boolean replace_enabled = false;
-
-	    // Indexes must have a name
-	    if (name_textfield.getText().length() == 0) {
-		add_enabled = false;
-	    }
-	    // Can't add a new index if no sources are selected
-	    else if (source_list.isNothingTicked()) {
-		add_enabled = false;
-	    }
-	    // If we get this far, create a dummy index and see if it's already assigned in the collection
-	    else {
+	    
+	    Index index;
+	    ArrayList sources;
+	    if (mgpp_enabled && allfields_box.isSelected()) {
+		sources = new ArrayList();
+		sources.add(ALLFIELDS);
+		index = new Index(sources);
+
+	    } else if (!source_list.isNothingTicked()) {
 		Object object[] = source_list.getTicked().toArray();
-		ArrayList sources = new ArrayList();
+		sources = new ArrayList();
 		for(int i = 0; i < object.length; i++) {
 		    sources.add(object[i]);
 		}
 		object = null;
-		Index index = new Index(level_combobox.getSelectedIndex(), sources);
-		sources = null;
-		if (model.contains(index)) {
-		    add_enabled = false;
-
-		    // Here we need to check if we have changed the name - if so, we can enable the replace button
-		    if (index_list.getSelectedIndex() != -1) {
-			Index selected_index = (Index)index_list.getSelectedValue();
-			String name = name_textfield.getText();
-			String index_name = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER+selected_index.getID()).getValue(true);
-			if (!index_name.equals(name)){
+		
+		if (mgpp_enabled) {
+		    index = new Index(sources);
+		} else {
+		    index = new Index(level_combobox.getSelectedIndex(), sources);
+		}
+	    } else {
+		add_button.setEnabled(false);
+		replace_button.setEnabled(false);
+		return;
+	    }
+	    sources = null;
+	    if (model.contains(index)) {
+		add_enabled = false;
+		// may be able to replace if the index selected is the same but with a different name
+		if (index_list.getSelectedIndex() != -1) {
+		    String id = index.getID();
+		    
+		    String selected_index_id = ((Index)index_list.getSelectedValue()).getID();
+		    if (id.equals(selected_index_id)) {
+			// check the name
+			String existing_index_name = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER+id).getValue(true);
+			if (!existing_index_name.equals(new_index_name)) {
 			    replace_enabled = true;
 			}
 		    }
 		}
-		else {
-		    add_enabled = true;
-
-		    // We have a new index, do we have something selected in the index list? if so, enable the replace button
-		    if (index_list.getSelectedIndex() != -1) {
-			replace_enabled = true;
-		    }
-		}
-	    }
-
-	    // We should now know the add_button state
+	    } else {
+		add_enabled = true;
+		if (index_list.getSelectedIndex() != -1) {
+		    // there is something selected, so we can replace
+		    replace_enabled = true;
+		}
+	    }
+	    
+	    // We should now know the button state
 	    add_button.setEnabled(add_enabled);
 	    replace_button.setEnabled(replace_enabled);
 	}
-
-
+	
 	private class AddListener
 	    implements ActionListener
@@ -825,597 +907,61 @@
 	    {
 		String name = name_textfield.getText();
-		if (!source_list.isNothingTicked() && name.length() != 0) {
+		if (name.length() == 0) return;
+		Index index;
+		if (mgpp_enabled && allfields_box.isSelected()) {
+		    ArrayList sources = new ArrayList();
+		    sources.add(ALLFIELDS);
+		    index = new Index(sources);
+		}
+		else if (!source_list.isNothingTicked()) {
 		    ArrayList sources = source_list.getTicked();
-		    Index index = new Index(level_combobox.getSelectedIndex(), sources);
-
-		    // Before we add the index to the model, we have to add the collection metadata for this
-		    CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
-		    metadatum.setValue(name);
-
-		    // Finally, add the index
-		    addIndex(index, metadatum);
-		    index_list.setSelectedValue(index, true);
-		}
-	    }
-	}
-
-
-	/** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */
-	private class IndexListListener
-	    implements ListSelectionListener
-	{
-	    /** This method is called whenever the source list selection changes. When it does we need to fill in the various parts of the list description panel
-	     * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
-	     */
-	    public void valueChanged(ListSelectionEvent event)
-	    {
-		if (event.getValueIsAdjusting()) {
+		    if(mgpp_enabled) {
+			index = new Index(sources);
+		    } else {
+			index = new Index(level_combobox.getSelectedIndex(), sources);
+		    }
+		} else {
 		    return;
 		}
-
-		Object value = index_list.getSelectedValue();
-		if (value == null) {
-		    move_down_button.setEnabled(false);
-		    move_up_button.setEnabled(false);
-		    remove_button.setEnabled(false);
-		    replace_button.setEnabled(false);
-		    set_default_button.setEnabled(false);
-		    return;
-		}
-
-		// Enable the buttons appropriately
-		remove_button.setEnabled(true);
-		set_default_button.setEnabled(default_index == null || !default_index.equals(value));
-		int i = index_list.getSelectedIndex();
-		int size = index_list.getModel().getSize();
-		if (i > 0) {
-		    move_up_button.setEnabled(true);
-		}
-		else {
-		    move_up_button.setEnabled(false);
-		}
-		if (i < size-1){
-		    move_down_button.setEnabled(true);
-		}
-		else {
-		    move_down_button.setEnabled(false);
-		}
-
-		// Need to fill in the rest of the bits
-		updateControlsWithSelectedIndex();		
-	    }
-	}
-
-	private class IndexListRenderer
-	    extends DefaultListCellRenderer {
-
-	    /** Return a component that has been configured to display the specified value. */
-	    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
-		JLabel component = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
-		if(default_index != null && default_index.equals(value)) {
-		    component.setText(component.getText() + " " + Dictionary.get("CDM.IndexManager.Default_Index_Indicator"));
-		}
-		return component;
-	    }
-
-	}
-
-	private class LevelListener
-	    implements ItemListener {
-	    public void itemStateChanged(ItemEvent event) {
-		if(event.getStateChange() == ItemEvent.SELECTED) {
-		    // just want to validate the add button
-		    validateAddButton();
-
-		}
-	    }
-	}
-
-	private class MoveListener
-	    implements ActionListener {
-
-	    private boolean move_up;
-
-	    public MoveListener(boolean move_up) {
-		this.move_up = move_up;
-	    }
-
-	    public void actionPerformed(ActionEvent event) {
-		// Retrieve the selected index
-		Index index = (Index) index_list.getSelectedValue();
-		if(index != null) {
-		    moveIndex(index, move_up);
-		    // Ensure the index that moved is still selected
-		    index_list.setSelectedValue(index, true);
-		    index = null;
-		}
-	    }
-	}
-
-
-	/** Listens for key presses within the name field, and enabled or disables controls as appropriate. */
-	private class NameListener
-	    implements DocumentListener
-	{
-	    public void changedUpdate(DocumentEvent e)
-	    {
-		validateAddButton();
-	    }
-
-	    public void insertUpdate(DocumentEvent e)
-	    {
-		validateAddButton();
-	    }
-
-	    public void removeUpdate(DocumentEvent e)
-	    {
-		validateAddButton();
-	    }
-	}
-
-
-	private class RemoveListener
-	    implements ActionListener
-	{
-	    public void actionPerformed(ActionEvent event)
-	    {
-		int i = index_list.getSelectedIndex();
-		if (i != -1) {
-		    removeIndex((Index) index_list.getSelectedValue());
-		}
-		int size = index_list.getModel().getSize();
-		if (i == size) {
-		    i--;
-		}
-		index_list.setSelectedIndex(i);
-
-		// This will produce an event on the list, updating the other buttons
-		if (size == 0) {
-		    // We have removed the last index, should be able to add what's filled in currently, if valid
-		    validateAddButton();
-		}
-	    }
-	}
-
-
-	private class ReplaceListener
-	    implements ActionListener
-	{
-	    public void actionPerformed(ActionEvent event)
-	    {
-		if (index_list.isSelectionEmpty()) {
-		    // This should never happen, but just in case...
-		    replace_button.setEnabled(false);
-		    return;
-		}
-
-		// We'll just remove the old one and add the new one
-		removeIndex((Index) index_list.getSelectedValue());
-		replace_button.setEnabled(false);
-		add_button.setEnabled(true);
-		add_button.doClick();
+		 
+		// Before we add the index to the model, we have to add the collection metadata for this
+		CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
+		metadatum.setValue(name);
+		
+		// Finally, add the index
+		addIndex(index, metadatum);
+		index_list.setSelectedValue(index, true);
 		add_button.setEnabled(false);
-	    }
-	}
-
-
-	private class SetDefaultListener
-	    implements ActionListener {
-
-	    public void actionPerformed(ActionEvent event) {
-		Index index = (Index) index_list.getSelectedValue();
-		if(index != null) {
-		    setDefault(index);
-		    // This should cause a repaint of just the desired row
-		    index_list.setSelectedValue(index, true);
-		}
-		set_default_button.setEnabled(false);
-	    }
-	}
-
-
-	private class SourceListListener
-	    implements ListSelectionListener
-	{
-	    public void valueChanged(ListSelectionEvent event)
-	    {
-		validateAddButton();
-	    }
-	}
-    }
-
-    private class MGPPControl
-	extends JPanel {
-
-	private GComboBox index_combobox;
-	private GComboBox level_combobox;
-	private JButton add_index_button;
-	private JButton add_all_button;
-	private JButton add_level_button;
-	private JButton move_index_down_button;
-	private JButton move_level_down_button;
-	private JButton move_index_up_button;
-	private JButton move_level_up_button;
-	private JButton replace_index_button;
-	private JButton remove_index_button;
-	private JButton remove_level_button;
-	private JLabel current_levels_label;
-	private JLabel current_indexes_label;
-	private JLabel index_label;
-	private JLabel index_name_label;
-	private JLabel level_label;
-	private JLabel level_name_label;
-	private JLabel move_index_down_label;
-	private JLabel move_level_down_label;
-	private JLabel move_index_up_label;
-	private JLabel move_level_up_label;
-	private JLabel title_label;
-	private JList current_levels_list;
-	private JList current_indexes_list;
-	private JTabbedPane tabbed_pane;
-	private JTextArea instructions_textarea;
-	private JTextField index_name_field;
-	private JTextField level_name_field;
-	
-	// when we are in mg mode, we want to remove the mgpp listener 
-	// the underlying model is the same between the two JLists, and
-	// both listeners get notified when the model changes, but the mgpp
-	// listener doesn't care about mg events
-	private ListSelectionListener mgpp_index_list_listener;
-	
-	public MGPPControl() {
-	    // Create Indexes
-	    JPanel indexes_panel = new JPanel();
-
-	    JPanel current_indexes_panel = new JPanel();
-
-	    current_indexes_label = new JLabel();
-	    Dictionary.registerText(current_indexes_label, "CDM.IndexManager.MGPP.Current_Indexes");
-	    current_indexes_list = new JList(model);
-	    current_indexes_list.setVisibleRowCount(5);
-	    current_indexes_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-
-	    JPanel index_movement_panel = new JPanel();
-
-	    move_index_up_button = new JButton("", JarTools.getImage("arrow-up.gif"));
-	    move_index_up_button.setEnabled(false);
-	    move_index_up_button.setMnemonic(KeyEvent.VK_U);
-	    Dictionary.registerBoth(move_index_up_button, "CDM.Move.Move_Up", "CDM.Move.Move_Up_Tooltip");
-
-	    move_index_down_button = new JButton("", JarTools.getImage("arrow-down.gif"));
-	    move_index_down_button.setEnabled(false);
-	    move_index_down_button.setMnemonic(KeyEvent.VK_D);
-	    Dictionary.registerBoth(move_index_down_button, "CDM.Move.Move_Down", "CDM.Move.Move_Down_Tooltip");
-
-	    JPanel index_spacer_panel = new JPanel();
-	    JPanel index_body_panel = new JPanel();
-	    JPanel index_details_panel = new JPanel();
-	    JPanel index_labels_panel = new JPanel();
-
-	    index_name_label = new JLabel();
-	    Dictionary.registerText(index_name_label, "CDM.IndexManager.Index_Name");
-
-	    index_name_field = new JTextField();
-	    index_name_field.setPreferredSize(FIELD_SIZE);
-	    Dictionary.registerTooltip(index_name_field, "CDM.IndexManager.Index_Name_Tooltip");
-
-	    JPanel index_boxes_panel = new JPanel();
-
-	    index_label = new JLabel("CDM.IndexManager.MGPP.Index");
-	    Dictionary.registerText(index_label, "CDM.IndexManager.MGPP.Index");
-
-	    index_combobox = new GComboBox();
-	    index_combobox.setPreferredSize(FIELD_SIZE);
-	    index_combobox.setBackgroundNonSelectionColor(Configuration.getColor("coloring.editable_background", false));
-	    index_combobox.setBackgroundSelectionColor(Configuration.getColor("coloring.collection_selection_background", false));
-	    index_combobox.setEditable(false);  // Warning: setting this to true opens a big can of worms
-	    index_combobox.setTextNonSelectionColor(Configuration.getColor("coloring.workspace_tree_foreground", false));
-	    index_combobox.setTextSelectionColor(Configuration.getColor("coloring.collection_selection_foreground", false));
-	    Dictionary.registerTooltip(index_combobox, "CDM.IndexManager.MGPP.Index_Tooltip");
-
-	    JPanel index_button_panel = new JPanel();
-
-	    add_index_button = new GLIButton();
-	    add_index_button.setEnabled(false);
-	    add_index_button.setMnemonic(KeyEvent.VK_A);
-	    Dictionary.registerBoth(add_index_button, "CDM.IndexManager.Add_Index", "CDM.IndexManager.Add_Index_Tooltip");
-
-	    add_all_button = new GLIButton();
-	    add_all_button.setEnabled(true);
-	    add_all_button.setMnemonic(KeyEvent.VK_L);
-	    Dictionary.registerBoth(add_all_button, "CDM.IndexManager.MGPP.Add_All_Metadata", "CDM.IndexManager.MGPP.Add_All_Metadata_Tooltip");
-
-	    replace_index_button = new GLIButton();
-	    replace_index_button.setEnabled(false);
-	    replace_index_button.setMnemonic(KeyEvent.VK_C);
-	    Dictionary.registerBoth(replace_index_button, "CDM.IndexManager.MGPP.Replace_Index", "CDM.IndexManager.MGPP.Replace_Index_Tooltip");
-
-	    remove_index_button = new GLIButton();
-	    remove_index_button.setEnabled(false);
-	    remove_index_button.setMnemonic(KeyEvent.VK_A);
-	    Dictionary.registerBoth(remove_index_button, "CDM.IndexManager.Remove_Index", "CDM.IndexManager.Remove_Index_Tooltip");
-
-	    JPanel index_empty_panel = new JPanel();
-
-	    // Connect Indexes
-	    EnableAddIndexListener index_eal = new EnableAddIndexListener();
-	    add_index_button.addActionListener(new AddIndexActionListener());
-	    add_all_button.addActionListener(new AddAllActionListener());
-	    
-	    // Create the index_list_listener but don't add in to the list - this gets done in gainFocus, we don't want it twice.
-	    mgpp_index_list_listener = new CurrentIndexesListSelectionListener();
-	    index_combobox.addActionListener(index_eal);
-	    ((JTextField)index_combobox.getEditor().getEditorComponent()).getDocument().addDocumentListener(index_eal);
-	    index_name_field.getDocument().addDocumentListener(index_eal);
-	    move_index_down_button.addActionListener(new MoveIndexDownListener());
-	    move_index_up_button.addActionListener(new MoveIndexUpListener());
-	    replace_index_button.addActionListener(new ReplaceIndexActionListener());
-	    remove_index_button.addActionListener(new RemoveIndexActionListener(index_eal));
-
-	    // Layout Indexes
-	    index_movement_panel.setLayout(new GridLayout(2,1));
-	    index_movement_panel.add(move_index_up_button);
-	    index_movement_panel.add(move_index_down_button);
-
-	    current_indexes_panel.setLayout(new BorderLayout());
-	    current_indexes_panel.add(current_indexes_label, BorderLayout.NORTH);
-	    current_indexes_panel.add(new JScrollPane(current_indexes_list), BorderLayout.CENTER);
-	    current_indexes_panel.add(index_movement_panel, BorderLayout.EAST);
-
-
-	    index_labels_panel.setLayout(new GridLayout(2,1));
-	    index_labels_panel.add(index_name_label);
-	    index_labels_panel.add(index_label);
-
-	    index_boxes_panel.setLayout(new GridLayout(2,1));
-	    index_boxes_panel.add(index_name_field);
-	    index_boxes_panel.add(index_combobox);
-
-	    index_details_panel.setLayout(new BorderLayout(5,0));
-	    index_details_panel.add(index_labels_panel, BorderLayout.WEST);
-	    index_details_panel.add(index_boxes_panel, BorderLayout.CENTER);
-
-	    index_button_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
-	    index_button_panel.setLayout(new GridLayout(2,2,5,0));
-	    index_button_panel.add(add_index_button);
-	    index_button_panel.add(add_all_button);
-	    index_button_panel.add(replace_index_button);
-	    index_button_panel.add(remove_index_button);
-
-	    index_body_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
-	    index_body_panel.setLayout(new BorderLayout());
-	    index_body_panel.add(index_details_panel, BorderLayout.CENTER);
-	    index_body_panel.add(index_button_panel, BorderLayout.SOUTH);
-
-	    index_spacer_panel.setLayout(new BorderLayout());
-	    index_spacer_panel.add(index_body_panel, BorderLayout.NORTH);
-	    index_spacer_panel.add(index_empty_panel, BorderLayout.CENTER);
-
-	    indexes_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
-	    indexes_panel.setLayout(new BorderLayout());
-	    indexes_panel.add(current_indexes_panel, BorderLayout.NORTH);
-	    indexes_panel.add(index_spacer_panel, BorderLayout.CENTER);
-
-	    // Create Levels
-	    JPanel levels_panel = new JPanel();
-
-	    JPanel current_levels_panel = new JPanel();
-
-	    current_levels_label = new JLabel();
-	    Dictionary.registerText(current_levels_label, "CDM.IndexManager.MGPP.Current_Levels");
-
-	    current_levels_list = new JList(levels_model);
-	    current_levels_list.setVisibleRowCount(5);
-	    current_levels_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-	    JPanel level_movement_panel = new JPanel();
-
-	    move_level_up_button = new JButton("", JarTools.getImage("arrow-up.gif"));
-	    move_level_up_button.setEnabled(false);
-	    move_level_up_button.setMnemonic(KeyEvent.VK_U);
-	    Dictionary.registerBoth(move_level_up_button, "CDM.Move.Move_Up", "CDM.Move.Move_Up_Tooltip");
-
-	    move_level_down_button = new JButton("", JarTools.getImage("arrow-down.gif"));
-	    move_level_down_button.setEnabled(false);
-	    move_level_down_button.setMnemonic(KeyEvent.VK_D);
-	    Dictionary.registerBoth(move_level_down_button, "CDM.Move.Move_Down", "CDM.Move.Move_Down_Tooltip");
-
-	    JPanel level_spacer_panel = new JPanel();
-	    JPanel level_body_panel = new JPanel();
-	    JPanel level_details_panel = new JPanel();
-	    JPanel level_labels_panel = new JPanel();
-	    JPanel level_boxes_panel = new JPanel();
-
-	    level_name_label = new JLabel();
-	    Dictionary.registerText(level_name_label, "CDM.IndexManager.MGPP.Level_Name");
-
-	    level_name_field = new JTextField();
-	    level_name_field.setPreferredSize(FIELD_SIZE);
-	    Dictionary.registerTooltip(level_name_field, "CDM.IndexManager.MGPP.Level_Name_Tooltip");
-
-
-	    level_label = new JLabel();
-	    Dictionary.registerText(level_label, "CDM.IndexManager.MGPP.Level");
-
-	    level_combobox = new GComboBox(Index.LEVEL);
-	    level_combobox.setPreferredSize(FIELD_SIZE);
-	    level_combobox.setBackgroundNonSelectionColor(Configuration.getColor("coloring.editable_background", false));
-	    level_combobox.setBackgroundSelectionColor(Configuration.getColor("coloring.collection_selection_background", false));
-	    level_combobox.setEditable(false);
-	    level_combobox.setTextNonSelectionColor(Configuration.getColor("coloring.workspace_tree_foreground", false));
-	    level_combobox.setTextSelectionColor(Configuration.getColor("coloring.collection_selection_foreground", false));
-	    Dictionary.registerTooltip(level_combobox, "CDM.IndexManager.Level_Tooltip");
-
-	    JPanel level_button_panel = new JPanel();
-
-	    add_level_button = new GLIButton("CDM.IndexManager.MGPP.Add_Level");
-	    add_level_button.setEnabled(false);
-	    add_level_button.setMnemonic(KeyEvent.VK_A);
-	    Dictionary.registerBoth(add_level_button, "CDM.IndexManager.MGPP.Add_Level", "CDM.IndexManager.MGPP.Add_Level_Tooltip");
-
-	    remove_level_button = new GLIButton("CDM.IndexManager.MGPP.Remove_Level");
-	    remove_level_button.setEnabled(false);
-	    remove_level_button.setMnemonic(KeyEvent.VK_A);
-	    Dictionary.registerBoth(remove_level_button, "CDM.IndexManager.MGPP.Remove_Level", "CDM.IndexManager.MGPP.Remove_Level_Tooltip");
-
-	    JPanel level_empty_panel = new JPanel();
-
-	    // Connect Levels
-	    EnableAddLevelListener level_eal = new EnableAddLevelListener();
-	    add_level_button.addActionListener(new AddLevelActionListener());
-	    current_levels_list.addListSelectionListener(new CurrentLevelsListSelectionListener());
-	    level_combobox.addActionListener(level_eal);
-	    ((JTextField)level_combobox.getEditor().getEditorComponent()).getDocument().addDocumentListener(level_eal);
-	    level_name_field.getDocument().addDocumentListener(level_eal);
-	    move_level_down_button.addActionListener(new MoveLevelDownListener());
-	    move_level_up_button.addActionListener(new MoveLevelUpListener());
-	    remove_level_button.addActionListener(new RemoveLevelActionListener(level_eal));
-	    // Layout Levels
-
-	    level_movement_panel.setLayout(new GridLayout(2,1));
-	    level_movement_panel.add(move_level_up_button);
-	    level_movement_panel.add(move_level_down_button);
-
-	    current_levels_panel.setLayout(new BorderLayout());
-	    current_levels_panel.add(current_levels_label, BorderLayout.NORTH);
-	    current_levels_panel.add(new JScrollPane(current_levels_list), BorderLayout.CENTER);
-	    current_levels_panel.add(level_movement_panel, BorderLayout.EAST);
-
-	    level_labels_panel.setLayout(new GridLayout(2,1));
-	    level_labels_panel.add(level_name_label);
-	    level_labels_panel.add(level_label);
-
-	    level_boxes_panel.setLayout(new GridLayout(2,1));
-	    level_boxes_panel.add(level_name_field);
-	    level_boxes_panel.add(level_combobox);
-
-	    level_details_panel.setLayout(new BorderLayout(5,0));
-	    level_details_panel.add(level_labels_panel, BorderLayout.WEST);
-	    level_details_panel.add(level_boxes_panel, BorderLayout.CENTER);
-
-	    level_button_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
-	    level_button_panel.setLayout(new GridLayout(1,2,5,0));
-	    level_button_panel.add(add_level_button);
-	    level_button_panel.add(remove_level_button);
-
-	    level_body_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
-	    level_body_panel.setLayout(new BorderLayout());
-	    level_body_panel.add(level_details_panel, BorderLayout.CENTER);
-	    level_body_panel.add(level_button_panel, BorderLayout.SOUTH);
-
-	    level_spacer_panel.setLayout(new BorderLayout());
-	    level_spacer_panel.add(level_body_panel, BorderLayout.NORTH);
-	    level_spacer_panel.add(level_empty_panel, BorderLayout.CENTER);
-
-	    levels_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
-	    levels_panel.setLayout(new BorderLayout());
-	    levels_panel.add(current_levels_panel, BorderLayout.NORTH);
-	    levels_panel.add(level_spacer_panel, BorderLayout.CENTER);
-
-	    // Create General
-	    JPanel header_panel = new JPanel();
-
-	    title_label = new JLabel();
-	    title_label.setHorizontalAlignment(JLabel.CENTER);
-	    Dictionary.registerText(title_label, "CDM.IndexManager.MGPP.Title");
-
-	    instructions_textarea = new JTextArea();
-	    instructions_textarea.setEditable(false);
-	    instructions_textarea.setLineWrap(true);
-	    instructions_textarea.setRows(6);
-	    instructions_textarea.setWrapStyleWord(true);
-	    Dictionary.registerText(instructions_textarea, "CDM.IndexManager.MGPP.Instructions");
-
-	    tabbed_pane = new JTabbedPane();
-
-	    // Layout General
-	    header_panel.setBorder(BorderFactory.createEmptyBorder(0,0,2,0));
-	    header_panel.setLayout(new BorderLayout());
-	    header_panel.add(title_label, BorderLayout.NORTH);
-	    header_panel.add(new JScrollPane(instructions_textarea), BorderLayout.CENTER);
-
-	    tabbed_pane.add(Dictionary.get("CDM.IndexManager.MGPP.Indexes"), indexes_panel);
-	    tabbed_pane.add(Dictionary.get("CDM.IndexManager.MGPP.Levels"), levels_panel);
-
-	    setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
-	    setLayout(new BorderLayout());
-	    add(header_panel, BorderLayout.NORTH);
-	    add(tabbed_pane, BorderLayout.CENTER);
-	}
-
-	public void destroy() {
-	}
-
-	public void gainFocus() {
-	    // add in the mgpp listener
-	    current_indexes_list.addListSelectionListener(mgpp_index_list_listener);
-	    // Reload the assigned indexes list.
-	    index_combobox.removeAllItems();
-	    index_combobox.addItem(CollectionConfiguration.ALLFIELDS_STR);
-	    index_combobox.addItem(CollectionConfiguration.METADATA_STR);
-	    index_combobox.addItem(CollectionConfiguration.TEXT_STR);
-	    ArrayList every_metadata_set_element = MetadataSetManager.getEveryMetadataSetElement();
-	    for(int i = 0; i < every_metadata_set_element.size(); i++) {
-		index_combobox.addItem(every_metadata_set_element.get(i));
-	    }
-	    // Ensure the level manager has at least documents assigned
-	    if(levels_model.getSize() == 0) {
-		Level level = new Level(CollectionConfiguration.DOCUMENT_STR);
-		// Create new metadatum
-		CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + CollectionConfiguration.DOCUMENT_STR);
-		metadatum.setValue(CollectionConfiguration.DOCUMENT_STR);
-		// Assign new level
-		addLevel(level, metadatum);	    
-		level = null;
-	    }
-
-	    // refresh
-	    current_indexes_list.updateUI();
-	}
-	
-	public void removeIndexListListener() {
-
-	    current_indexes_list.removeListSelectionListener(mgpp_index_list_listener);
-	}
-	
-	private class AddIndexActionListener
-	    implements ActionListener {
-	    public void actionPerformed(ActionEvent event) {
-		// Retrieve the name
-		String name = index_name_field.getText();
-		// Retrieve the source
-		Object source = index_combobox.getSelectedItem();
-
-		// If this object isn't yet in the combobox add it.
-		if(index_combobox.getSelectedIndex() == -1) {
-		    index_combobox.insertItemAt(source, index_combobox.getItemCount());
-		}
-		// Create new index
-		ArrayList sources = new ArrayList();
-		sources.add(source);
-		Index index = new Index(sources);
-		if(!model.contains(index)) {
-		    // Create new metadatum
-		    CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
-		    metadatum.setValue(name);
-		    // Assign new index
-		    addIndex(index, metadatum);
-		    current_indexes_list.setSelectedValue(index, true);
-		}
-		// Done. Disable add
-		add_index_button.setEnabled(false);
-	    }
-	}
-
+		
+	    }
+	}
+
+	/** add all sources as indexes. for MG, this adds them in one combined
+	    index, for MGPP this adds them as individual indexes (fields) */
 	private class AddAllActionListener
 	    implements ActionListener {
 
 	    public void actionPerformed(ActionEvent event) {
-		for(int i = 0; i < index_combobox.getItemCount(); i++) {
-		    Object source = index_combobox.getItemAt(i);
+		ArrayList all_sources = source_list.getAll();
+		if (!mgpp_enabled) {
+		    Index index = new Index(level_combobox.getSelectedIndex(), all_sources);
+		    if (!model.contains(index)) {
+			CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
+			metadatum.setValue("all fields"); // need a good name
+			addIndex(index, metadatum);
+		    }
+		    all_sources = null;
+		    index = null;
+		    return;
+		}
+		
+		ArrayList new_sources = new ArrayList();
+		for(int i = 0; i < all_sources.size(); i++) {
+		    Object source = all_sources.get(i);
+
 		    // Create new index
-		    ArrayList sources = new ArrayList();
-		    sources.add(source);
-		    Index index = new Index(sources);
-		    sources = null;
+		    new_sources.clear();
+		    new_sources.add(source);
+		    Index index = new Index(new_sources);
 		    if(!model.contains(index)) {
 			// Determine the metadatum value
@@ -1434,6 +980,363 @@
 		    index = null;
 		}
+		new_sources = null;
 		// Done. Disable add
-		add_index_button.setEnabled(false);
+		add_button.setEnabled(false);
+	    }
+	}
+
+	private class AllfieldsCheckBoxListener
+	    implements ItemListener
+	{
+	    public void itemStateChanged(ItemEvent event) {
+		if (event.getStateChange() == ItemEvent.SELECTED) {
+		    source_list.setEnabled(false);
+		} else if (event.getStateChange() == ItemEvent.DESELECTED) {
+		    source_list.setEnabled(true);
+		}
+		validateAddButton();
+	    }
+
+	}
+	/** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */
+	private class IndexListListener
+	    implements ListSelectionListener
+	{
+	    /** This method is called whenever the source list selection changes. When it does we need to fill in the various parts of the list description panel
+	     * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
+	     */
+	    public void valueChanged(ListSelectionEvent event)
+	    {
+		if (event.getValueIsAdjusting()) {
+		    return;
+		}
+
+		Object value = index_list.getSelectedValue();
+		if (value == null) {
+		    move_down_button.setEnabled(false);
+		    move_up_button.setEnabled(false);
+		    remove_button.setEnabled(false);
+		    replace_button.setEnabled(false);
+		    set_default_button.setEnabled(false);
+		    return;
+		}
+
+		// Enable the buttons appropriately
+		remove_button.setEnabled(true);
+		set_default_button.setEnabled(default_index == null || !default_index.equals(value));
+		int i = index_list.getSelectedIndex();
+		int size = index_list.getModel().getSize();
+		move_up_button.setEnabled((i>0));
+		move_down_button.setEnabled((i<size-1));
+
+		// Need to fill in the rest of the bits
+		updateControlsWithSelectedIndex();		
+	    }
+	}
+
+	private class IndexListRenderer
+	    extends DefaultListCellRenderer {
+
+	    /** Return a component that has been configured to display the specified value. */
+	    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+		JLabel component = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+		if(default_index != null && default_index.equals(value)) {
+		    component.setText(component.getText() + " " + Dictionary.get("CDM.IndexManager.Default_Index_Indicator"));
+		}
+		return component;
+	    }
+
+	}
+
+	private class LevelListener
+	    implements ItemListener {
+	    public void itemStateChanged(ItemEvent event) {
+		if(event.getStateChange() == ItemEvent.SELECTED) {
+		    // just want to validate the add button
+		    validateAddButton();
+
+		}
+	    }
+	}
+
+	private class MoveListener
+	    implements ActionListener {
+
+	    private boolean move_up;
+
+	    public MoveListener(boolean move_up) {
+		this.move_up = move_up;
+	    }
+
+	    public void actionPerformed(ActionEvent event) {
+		// Retrieve the selected index
+		Index index = (Index) index_list.getSelectedValue();
+		if(index != null) {
+		    moveIndex(index, move_up);
+		    // Ensure the index that moved is still selected
+		    index_list.setSelectedValue(index, true);
+		    index = null;
+		}
+	    }
+	}
+
+
+	/** Listens for key presses within the name field, and enabled or disables controls as appropriate. */
+	private class NameListener
+	    implements DocumentListener
+	{
+	    public void changedUpdate(DocumentEvent e)
+	    {
+		validateAddButton();
+	    }
+
+	    public void insertUpdate(DocumentEvent e)
+	    {
+		validateAddButton();
+	    }
+
+	    public void removeUpdate(DocumentEvent e)
+	    {
+		validateAddButton();
+	    }
+	}
+
+
+	private class RemoveListener
+	    implements ActionListener
+	{
+	    public void actionPerformed(ActionEvent event)
+	    {
+		int i = index_list.getSelectedIndex();
+		if (i != -1) {
+		    removeIndex((Index) index_list.getSelectedValue());
+		}
+		int size = index_list.getModel().getSize();
+		if (i == size) {
+		    i--;
+		}
+		index_list.setSelectedIndex(i);
+
+		// This will produce an event on the list, updating the other buttons
+		if (size == 0) {
+		    // We have removed the last index, should be able to add what's filled in currently, if valid
+		    validateAddButton();
+		}
+	    }
+	}
+
+
+	private class ReplaceListener
+	    implements ActionListener
+	{
+	    public void actionPerformed(ActionEvent event)
+	    {
+		if (index_list.isSelectionEmpty()) {
+		    // This should never happen, but just in case...
+		    replace_button.setEnabled(false);
+		    return;
+		}
+		
+		String name = name_textfield.getText();
+		if (!source_list.isNothingTicked() && name.length() != 0) {
+		    ArrayList sources = source_list.getTicked();
+		    Index index;
+		    if (mgpp_enabled) {
+			index = new Index(sources);
+		    } else {
+			index = new Index(level_combobox.getSelectedIndex(), sources);
+		    }
+		    // Create the new collection meta
+		    CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
+		    metadatum.setValue(name);
+
+		    // replace the index
+		    replaceIndex((Index) index_list.getSelectedValue(), index, metadatum);
+		    index_list.setSelectedValue(index, true);
+
+		}
+		add_button.setEnabled(false);
+		replace_button.setEnabled(false);
+	    }
+	}
+
+
+	private class SetDefaultListener
+	    implements ActionListener {
+
+	    public void actionPerformed(ActionEvent event) {
+		Index index = (Index) index_list.getSelectedValue();
+		if(index != null) {
+		    setDefault(index);
+		    // This should cause a repaint of just the desired row
+		    index_list.setSelectedValue(index, true);
+		}
+		set_default_button.setEnabled(false);
+	    }
+	}
+
+
+	private class SourceListListener
+	    implements ListSelectionListener
+	{
+	    public void valueChanged(ListSelectionEvent event)
+	    {
+		validateAddButton();
+	    }
+	}
+    }
+
+    private class MGPPLevelsPanel
+	extends JPanel {
+
+	private JList current_levels_list;
+	
+	private JButton move_level_down_button;
+	private JButton move_level_up_button;
+
+	private GComboBox level_combobox;
+	private JTextField level_name_field;
+
+	private JButton add_level_button;
+	private JButton remove_level_button;
+			
+	public MGPPLevelsPanel() {
+
+	    JPanel current_levels_panel = new JPanel();
+
+	    JLabel current_levels_label = new JLabel();
+	    Dictionary.registerText(current_levels_label, "CDM.IndexManager.MGPP.Current_Levels");
+
+	    current_levels_list = new JList(levels_model);
+	    current_levels_list.setVisibleRowCount(5);
+	    current_levels_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+	    JPanel level_movement_panel = new JPanel();
+
+	    move_level_up_button = new JButton("", JarTools.getImage("arrow-up.gif"));
+	    move_level_up_button.setEnabled(false);
+	    move_level_up_button.setMnemonic(KeyEvent.VK_U);
+	    Dictionary.registerBoth(move_level_up_button, "CDM.Move.Move_Up", "CDM.Move.Move_Up_Tooltip");
+
+	    move_level_down_button = new JButton("", JarTools.getImage("arrow-down.gif"));
+	    move_level_down_button.setEnabled(false);
+	    move_level_down_button.setMnemonic(KeyEvent.VK_D);
+	    Dictionary.registerBoth(move_level_down_button, "CDM.Move.Move_Down", "CDM.Move.Move_Down_Tooltip");
+
+	    JPanel level_spacer_panel = new JPanel();
+	    JPanel level_body_panel = new JPanel();
+	    JPanel level_details_panel = new JPanel();
+	    JPanel level_labels_panel = new JPanel();
+	    JPanel level_boxes_panel = new JPanel();
+
+	    JLabel level_name_label = new JLabel();
+	    Dictionary.registerText(level_name_label, "CDM.IndexManager.MGPP.Level_Name");
+
+	    level_name_field = new JTextField();
+	    level_name_field.setPreferredSize(FIELD_SIZE);
+	    Dictionary.registerTooltip(level_name_field, "CDM.IndexManager.MGPP.Level_Name_Tooltip");
+
+
+	    JLabel level_label = new JLabel();
+	    Dictionary.registerText(level_label, "CDM.IndexManager.MGPP.Level");
+
+	    level_combobox = new GComboBox(Index.LEVEL);
+	    level_combobox.setPreferredSize(FIELD_SIZE);
+	    level_combobox.setBackgroundNonSelectionColor(Configuration.getColor("coloring.editable_background", false));
+	    level_combobox.setBackgroundSelectionColor(Configuration.getColor("coloring.collection_selection_background", false));
+	    level_combobox.setEditable(false);
+	    level_combobox.setTextNonSelectionColor(Configuration.getColor("coloring.workspace_tree_foreground", false));
+	    level_combobox.setTextSelectionColor(Configuration.getColor("coloring.collection_selection_foreground", false));
+	    Dictionary.registerTooltip(level_combobox, "CDM.IndexManager.Level_Tooltip");
+
+	    JPanel level_button_panel = new JPanel();
+
+	    add_level_button = new GLIButton("CDM.IndexManager.MGPP.Add_Level");
+	    add_level_button.setEnabled(false);
+	    add_level_button.setMnemonic(KeyEvent.VK_A);
+	    Dictionary.registerBoth(add_level_button, "CDM.IndexManager.MGPP.Add_Level", "CDM.IndexManager.MGPP.Add_Level_Tooltip");
+
+	    remove_level_button = new GLIButton("CDM.IndexManager.MGPP.Remove_Level");
+	    remove_level_button.setEnabled(false);
+	    remove_level_button.setMnemonic(KeyEvent.VK_A);
+	    Dictionary.registerBoth(remove_level_button, "CDM.IndexManager.MGPP.Remove_Level", "CDM.IndexManager.MGPP.Remove_Level_Tooltip");
+
+	    JPanel level_empty_panel = new JPanel();
+
+	    // Connect Levels
+	    EnableAddLevelListener level_eal = new EnableAddLevelListener();
+	    add_level_button.addActionListener(new AddLevelActionListener());
+	    current_levels_list.addListSelectionListener(new CurrentLevelsListSelectionListener());
+	    level_combobox.addActionListener(level_eal);
+	    // not editable
+	    //((JTextField)level_combobox.getEditor().getEditorComponent()).getDocument().addDocumentListener(level_eal);
+	    level_name_field.getDocument().addDocumentListener(level_eal);
+	    move_level_down_button.addActionListener(new MoveLevelDownListener());
+	    move_level_up_button.addActionListener(new MoveLevelUpListener());
+	    remove_level_button.addActionListener(new RemoveLevelActionListener());
+	    // Layout Levels
+
+	    level_movement_panel.setLayout(new GridLayout(2,1));
+	    level_movement_panel.add(move_level_up_button);
+	    level_movement_panel.add(move_level_down_button);
+
+	    current_levels_panel.setLayout(new BorderLayout());
+	    current_levels_panel.add(current_levels_label, BorderLayout.NORTH);
+	    current_levels_panel.add(new JScrollPane(current_levels_list), BorderLayout.CENTER);
+	    current_levels_panel.add(level_movement_panel, BorderLayout.EAST);
+
+	    level_labels_panel.setLayout(new GridLayout(2,1));
+	    level_labels_panel.add(level_name_label);
+	    level_labels_panel.add(level_label);
+
+	    level_boxes_panel.setLayout(new GridLayout(2,1));
+	    level_boxes_panel.add(level_name_field);
+	    level_boxes_panel.add(level_combobox);
+
+	    level_details_panel.setLayout(new BorderLayout(5,0));
+	    level_details_panel.add(level_labels_panel, BorderLayout.WEST);
+	    level_details_panel.add(level_boxes_panel, BorderLayout.CENTER);
+
+	    level_button_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
+	    level_button_panel.setLayout(new GridLayout(1,2,5,0));
+	    level_button_panel.add(add_level_button);
+	    level_button_panel.add(remove_level_button);
+
+	    level_body_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
+	    level_body_panel.setLayout(new BorderLayout());
+	    level_body_panel.add(level_details_panel, BorderLayout.CENTER);
+	    level_body_panel.add(level_button_panel, BorderLayout.SOUTH);
+
+	    level_spacer_panel.setLayout(new BorderLayout());
+	    level_spacer_panel.add(level_body_panel, BorderLayout.NORTH);
+	    level_spacer_panel.add(level_empty_panel, BorderLayout.CENTER);
+
+	    setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+	    setLayout(new BorderLayout());
+	    add(current_levels_panel, BorderLayout.NORTH);
+	    add(level_spacer_panel, BorderLayout.CENTER);
+	}
+	
+	public void gainFocus() {
+	    // Ensure the level manager has at least documents assigned
+	    if(levels_model.getSize() == 0) {
+		Level level = new Level(CollectionConfiguration.DOCUMENT_STR);
+		// Create new metadatum
+		CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + CollectionConfiguration.DOCUMENT_STR);
+		metadatum.setValue(CollectionConfiguration.DOCUMENT_STR);
+		// Assign new level
+		addLevel(level, metadatum);	    
+		level = null;
+	    }
+	}
+
+	/** Change the enable state of the add button depending on the current value in the search type combobox. */
+	public void validateAddButtonLevel() {
+	    String name = level_name_field.getText();
+	    Object selected_object = level_combobox.getSelectedItem();
+	    if(name.length() > 0 && selected_object != null) {
+		add_level_button.setEnabled(getLevel((String)selected_object) == null);
+	    }
+	    else {
+		add_level_button.setEnabled(false);
 	    }
 	}
@@ -1458,33 +1361,4 @@
 	}
 
-	private class CurrentIndexesListSelectionListener
-	    implements ListSelectionListener {
-	    public void valueChanged(ListSelectionEvent event) {
-		if(event.getValueIsAdjusting()) {
-		    return;
-		}
-		
-		Index index = (Index)current_indexes_list.getSelectedValue();
-		if(index != null) {
-		    String full_text = index.toString();
-		    if(full_text.indexOf("\"") != -1) {
-			index_name_field.setText(index.getName());
-		    }
-		    ArrayList sources = index.getSources();
-		    index_combobox.setSelectedItem(sources.get(0));
-		    
-		    
-		    move_index_down_button.setEnabled((model.indexOf(index) < model.getSize() - 1));
-		    move_index_up_button.setEnabled((model.indexOf(index) > 0));
-		    remove_index_button.setEnabled(true);
-		}
-		else {
-		    move_index_down_button.setEnabled(false);
-		    move_index_up_button.setEnabled(false);
-		    remove_index_button.setEnabled(false);
-		}
-	    }	    
-	}
-
 	private class CurrentLevelsListSelectionListener
 	    implements ListSelectionListener {
@@ -1514,91 +1388,5 @@
 	    }
 	}
-
-	private class EnableAddIndexListener
-	    implements ActionListener, DocumentListener {
-	    /** Called whenever a selection action occurs on the combobox.
-	     * @param  event an ActionEvent containing information about the selection event
-	     */
-	    public void actionPerformed(ActionEvent event) {
-		validateAddButtonIndex();
-	    }
-
-	    /** Gives notification that an attribute or set of attributes changed.
-	     * @param  event a DocumentEvent containing information about the text changed
-	     */
-	    public void changedUpdate(DocumentEvent event) {
-		validateAddButtonIndex();
-	    }
-
-	    /** Gives notification that there was an insert into the document.
-	     * @param  event a DocumentEvent containing information about the text added
-	     */
-	    public void insertUpdate(DocumentEvent event) {
-		validateAddButtonIndex();
-	    }
-
-	    /** Gives notification that a portion of the document has been removed.
-	     * @param  event a DocumentEvent containing information about the text removed
-	     */
-	    public void removeUpdate(DocumentEvent event) {
-		validateAddButtonIndex();
-	    }
-
-	    /** Change the enable state of the add button depending on the current value in the search type combobox. */
-	    public void validateAddButtonIndex() {
-		String name = index_name_field.getText();
-		Object selected_object = index_combobox.getSelectedItem();
-		boolean add_enabled = false;
-		boolean replace_enabled = false;
-
-		if(name.length() > 0 && selected_object != null) {
-		    // Unfortunately we have to generate a valid id
-		    String id = null;
-		    // Special cases
-		    if (selected_object instanceof String && (selected_object.equals(CollectionConfiguration.ALLFIELDS_STR) || selected_object.equals(CollectionConfiguration.METADATA_STR) || selected_object.equals(CollectionConfiguration.TEXT_STR))) {
-			id = (String) selected_object;
-		    }
-		    else if (selected_object instanceof MetadataElement) {
-			id = ((MetadataElement) selected_object).getFullName();
-		    }
-		    else {
-			System.err.println("Internal Error: Unexpected selected_object in IndexManager.");
-			return;
-		    }
-		    if(id.startsWith(StaticStrings.EXTRACTED_NAMESPACE)) {
-			id = id.substring(StaticStrings.EXTRACTED_NAMESPACE.length());
-		    }
-		    
-		    Index index = getIndex(id);
-		    if(index == null) {
-			add_enabled = true;
-			// we have a new index. is something selected? if so, we can replace
-			if (current_indexes_list.getSelectedIndex() != -1) {
-			    replace_enabled = true;
-			}
-		    }
-		    else {
-			// the index is already there
-			add_enabled = false;
-			// but if the name is changed, we can do a replace
-			if(!name.equals(index.getName())) {
-			    replace_enabled = true;
-			}
-			
-		    }
-		}
-		else {
-		    add_enabled = false;
-		    replace_enabled = false;
-		    
-		}
-
-		// We should now know the button state
-		add_index_button.setEnabled(add_enabled);
-		replace_index_button.setEnabled(replace_enabled);
-		
-	    }
-	}
-
+	
 	private class EnableAddLevelListener
 	    implements ActionListener, DocumentListener {
@@ -1631,27 +1419,5 @@
 	    }
     
-	    /** Change the enable state of the add button depending on the current value in the search type combobox. */
-	    public void validateAddButtonLevel() {
-		String name = level_name_field.getText();
-		Object selected_object = level_combobox.getSelectedItem();
-		if(name.length() > 0 && selected_object != null) {
-		    add_level_button.setEnabled(getLevel((String)selected_object) == null);
-		}
-		else {
-		    add_level_button.setEnabled(false);
-		}
-	    }
-	}
-
-	private class MoveIndexDownListener
-	    implements ActionListener {
-	    public void actionPerformed(ActionEvent event) {
-		// Retrieve the first selected item
-		Index index = (Index) current_indexes_list.getSelectedValue();
-		moveIndex(index, false);
-		current_indexes_list.setSelectedValue(index, true);
-	    }
-	}
-
+	}
 	private class MoveLevelDownListener
 	    implements ActionListener {
@@ -1663,15 +1429,4 @@
 	    }
 	}
-
-	private class MoveIndexUpListener
-	    implements ActionListener {
-	    public void actionPerformed(ActionEvent event) {
-		// Retrieve the first selected item
-		Index index = (Index) current_indexes_list.getSelectedValue();
-		moveIndex(index, true);
-		current_indexes_list.setSelectedValue(index, true);
-	    }
-	}
-
 	private class MoveLevelUpListener
 	    implements ActionListener {
@@ -1683,107 +1438,6 @@
 	    }
 	}
-
-	/** Replace really only replaces the string. */
-	private class ReplaceIndexActionListener
-	    implements ActionListener {
-
-	    public void actionPerformed(ActionEvent event) {
-		// We'll just remove the old one and add the new one
-		removeIndex((Index) current_indexes_list.getSelectedValue());
-		replace_index_button.setEnabled(false);
-		add_index_button.setEnabled(true);
-		add_index_button.doClick(); // this adds the new one
-		add_index_button.setEnabled(false);
-		
-		//Object[] selected_objects = current_indexes_list.getSelectedValues();
-		//if(selected_objects.length == 1) {
-		Index index = (Index)current_indexes_list.getSelectedValue();
-		if (index != null) {
-		//Index index = (Index) selected_objects[0];
-		    // Remove old name
-		    CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + index.getID());
-		    // Enter new name
-		    String name = index_name_field.getText();
-		    // Create new metadatum
-		    CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
-		    //index = null;
-		    metadatum.setValue(name);
-		    name = null;
-		    // Assign new index
-		    CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
-		    metadatum = null;
-		}
-		//current_indexes_list.setSelectedValue(selected_objects[0], true);
-		current_indexes_list.setSelectedValue(index, true);
-		// Done. Disable add
-		add_index_button.setEnabled(false);
-		replace_index_button.setEnabled(false);
-	    }
-	}
-
-	private class RemoveIndexActionListener
-	    implements ActionListener {
-
-	    private EnableAddIndexListener eal = null;
-
-	    public RemoveIndexActionListener(EnableAddIndexListener eal) {
-		this.eal = eal;
-	    }
-
-	    public void actionPerformed(ActionEvent event) {
-		// Retrieve the selected items
-		//Object[] selected_objects = current_indexes_list.getSelectedValues();
-		// Clear selection
-		//current_indexes_list.clearSelection();
-		//for(int i = 0; i < selected_objects.length; i++) {
-		//    Index index = (Index) selected_objects[i];
-		    // Remove any related metadata
-		//    CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + index.getID());
-		    // Remove the index
-		//    removeIndex(index);
-		//}
-		// Disable remove button
-		//remove_index_button.setEnabled(false);
-		// Check if add should be reenabled
-		//eal.validateAddButtonIndex();
-		int i = current_indexes_list.getSelectedIndex();
-		if (i != -1) {
-		    Index index = (Index) current_indexes_list.getSelectedValue();
-		    // Remove any related metadata
-		    CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + index.getID());
-		    removeIndex(index);
-		    
-		//if (i != -1) {
-		//removeIndex((Index) index_list.getSelectedValue());
-		    //}
-		    int size = current_indexes_list.getModel().getSize();
-		    if (i == size) {
-			i--;
-		    }
-		    current_indexes_list.setSelectedIndex(i);
-		}
-		if (i==-1) {
-		    // empty list, disable remove button
-		    remove_index_button.setEnabled(false);
-		}
-		// Check if add should be reenabled
-		eal.validateAddButtonIndex();
-
-		// This will produce an event on the list, updating the other buttons
-		//if (size == 0) {
-		    // We have removed the last index, should be able to add what's filled in currently, if valid
-		// validateAddButton();
-		//	}
-	    }
-	}
-
 	private class RemoveLevelActionListener
 	    implements ActionListener {
-
-	    private EnableAddLevelListener eal = null;
-
-	    public RemoveLevelActionListener(EnableAddLevelListener eal) {
-		this.eal = eal;
-	    }
 
 	    public void actionPerformed(ActionEvent event) {
@@ -1798,37 +1452,15 @@
 		    }
 		    current_levels_list.setSelectedIndex(i);
-		}
-		// Retrieve the selected items
-		//Object[] selected_objects = current_levels_list.getSelectedValues();
-		// Clear selection
-		//current_levels_list.clearSelection();
-		//for(int i = 0; i < selected_objects.length; i++) {
-		
-		    //Level level = (Level) selected_objects[i];
-		    // Remove any related metadata
-		    //CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + level.getLevel());
-		    // Remove the index
-		    //removeLevel(level);
-		//}
-		
+		}		
 		if (i==-1) {
 		    // Disable remove button
 		    remove_level_button.setEnabled(false);
 		}
-		// If there are no levels left, put document back in
-// 		if(levels_model.getSize() == 0) {
-// 			Level level = new Level(CollectionConfiguration.DOCUMENT_STR);
-// 			// Create new metadatum
-// 			CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + CollectionConfiguration.DOCUMENT_STR);
-// 			metadatum.setValue(CollectionConfiguration.DOCUMENT_STR);
-// 			// Assign new level
-// 			addLevel(level, metadatum);	    
-// 			level = null;
-// 		}
-		// Check if add should be reenabled
-		eal.validateAddButtonLevel();
-	    }
-	}
-    } // MGPPControls
+		validateAddButtonLevel();
+	    }
+	}
+
+    }
 
 }
+
