Index: trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java
===================================================================
--- trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java	(revision 12165)
+++ trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java	(revision 12167)
@@ -641,15 +641,12 @@
 	    // mg uses a level box
 	    private JComboBox level_combobox;
-
-	    private JButton add_button;
-	    private JButton add_all_button;
-	    private JButton select_all_button;
-	    private JButton replace_button;
+	    // mgpp has a allfields selector
+	    private JCheckBox allfields_box;
+
+	    private JButton add_or_replace_button;
+	    private JButton add_or_select_all_button;
+	    //private JButton select_all_button;
+	    //private JButton replace_button;
 	    private JButton cancel_button;
-
-	    // some panels that we need to manipulate later on
-	    private JPanel boxes_pane;
-	    private JPanel labels_pane;
-	    private JLabel level_label;
 
 	    private boolean mgpp_enabled = false;
@@ -688,4 +685,5 @@
 
 		JPanel button_pane = new JPanel();
+		button_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
 		// three buttons for new index, or replace mg index, two buttons otherwise
 		if (existing_index == null || !mgpp_enabled) {
@@ -696,28 +694,29 @@
 
 		if (existing_index != null) {
-		    replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Replace_Index"), Dictionary.get("CDM.IndexManager.Replace_Index_Tooltip"));
-		    replace_button.setEnabled(false);
-		    replace_button.addActionListener(new ReplaceIndexListener());
-		    button_pane.add(replace_button);
+		    add_or_replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Replace_Index"), Dictionary.get("CDM.IndexManager.Replace_Index_Tooltip"));
+		    add_or_replace_button.addActionListener(new ReplaceIndexListener());
 		} else {
-		    add_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_Index"), Dictionary.get("CDM.IndexManager.Add_Index_Tooltip"));
-		    add_button.setEnabled(false);
-		    add_button.addActionListener(new AddIndexListener());
-		    button_pane.add(add_button);
-		}
+		    add_or_replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_Index"), Dictionary.get("CDM.IndexManager.Add_Index_Tooltip"));
+		    add_or_replace_button.addActionListener(new AddIndexListener());
+		}
+		
+		add_or_replace_button.setEnabled(false);
+		button_pane.add(add_or_replace_button);
 		
 		if (!mgpp_enabled) {
-		    select_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_All"), Dictionary.get("CDM.IndexManager.Select_All_Tooltip"));
-		    select_all_button.setEnabled(true);
-		    select_all_button.addActionListener(new SelectAllActionListener());
-		    button_pane.add(select_all_button);
+		    // its select all
+		    add_or_select_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_All"), Dictionary.get("CDM.IndexManager.Select_All_Tooltip"));
+		    add_or_select_all_button.setEnabled(true);
+		    add_or_select_all_button.addActionListener(new SelectAllActionListener());
+		    button_pane.add(add_or_select_all_button);
 		} else if (existing_index == null) {
 		    // mgpp, and new index
-		    add_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_All"), Dictionary.get("CDM.IndexManager.Add_All_Tooltip"));
-		    add_all_button.setEnabled(true);
-		    add_all_button.addActionListener(new AddAllIndexActionListener());	    
-		    button_pane.add(add_all_button);
+		    add_or_select_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_All"), Dictionary.get("CDM.IndexManager.Add_All_Tooltip"));
+		    add_or_select_all_button.setEnabled(true);
+		    add_or_select_all_button.addActionListener(new AddAllIndexActionListener());	    
+		    button_pane.add(add_or_select_all_button);
 		    
 		}
+		
 		// always have a cancel button
 		cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel"));
@@ -738,7 +737,15 @@
 
 		// do type specific stuff
-		if (!mgpp_enabled) {
-
-		    level_label = new JLabel(Dictionary.get("CDM.IndexManager.Level"));
+		if (mgpp_enabled) {
+		    // allfields
+		    allfields_box = new JCheckBox(Dictionary.get("CDM.IndexManager.Allfields_Index"));
+		    allfields_box.addItemListener(new AllFieldsBoxListener());
+		    //JLabel allfields_label = new JLabel(Dictionary.get("CDM.IndexManager.Allfields_Index"));
+		    details_pane.add(allfields_box, BorderLayout.SOUTH);
+		    
+		    
+		} else {
+		    // index level
+		    JLabel level_label = new JLabel(Dictionary.get("CDM.IndexManager.Level"));
 		    level_combobox = new JComboBox();
 		    level_combobox.setPreferredSize(FIELD_SIZE);
@@ -758,6 +765,11 @@
 		if (existing_index !=null) {
 		    ArrayList sources = existing_index.getSources();
-		    source_list.setTickedObjects(sources.toArray());
-		    source_list.setEnabled(true); 
+		    if (mgpp_enabled && sources.get(0).equals(ALLFIELDS)) {
+			allfields_box.setSelected(true);
+			source_list.setEnabled(false);
+		    } else {
+			source_list.setTickedObjects(sources.toArray());
+			source_list.setEnabled(true);
+		    } 
 		    if (!mgpp_enabled) {
 			level_combobox.setSelectedIndex(existing_index.getLevel());
@@ -789,4 +801,41 @@
 	    }
 
+	    // Checks that specified index not already in the collection
+	    private void validateAddOrReplaceButton() {
+		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();
+		    sources = new ArrayList();
+		    for(int i = 0; i < object.length; i++) {
+			sources.add(object[i]);
+		    }
+		    object = null;
+		    
+		    if (mgpp_enabled) {
+			index = new Index(sources);
+		    } else {
+			index = new Index(level_combobox.getSelectedIndex(), sources);
+		    }
+		} else {
+		    // nothing selected
+		    add_or_replace_button.setEnabled(false);
+		    return;
+		}
+		
+		sources = null;
+		if (index_model.contains(index)) {
+		    add_or_replace_button.setEnabled(false);
+		}
+		else {
+		    add_or_replace_button.setEnabled(true);
+		}
+		
+	    }
 	    private class AddIndexListener
 		implements ActionListener
@@ -795,5 +844,10 @@
 		{
 		    Index index;
-		    if (!source_list.isNothingTicked()) {
+		    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();
 			if(mgpp_enabled) {
@@ -853,4 +907,18 @@
 	    }
     
+	    private class AllFieldsBoxListener
+		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);
+		    }
+		    validateAddOrReplaceButton();
+		}
+		
+	    }
+
 	    private class SelectAllActionListener
 		implements ActionListener {
@@ -858,9 +926,5 @@
 		public void actionPerformed(ActionEvent event) {
 		    source_list.setAllTicked();
-		    if (editing) {
-			replace_button.setEnabled(true);
-		    } else { 
-			add_button.setEnabled(true);
-		    }
+		    validateAddOrReplaceButton();
 		}
 	    }
@@ -873,11 +937,5 @@
 			return;
 		    }
-		    boolean enabled = !source_list.isNothingTicked();
-		    if (editing) {
-			replace_button.setEnabled(enabled);
-		    } else { 
-			add_button.setEnabled(enabled);
-		    }
-		
+		    validateAddOrReplaceButton();
 		}
 	    }
