Index: /trunk/gli/src/org/greenstone/gatherer/cdm/LanguageManager.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/cdm/LanguageManager.java	(revision 9562)
+++ /trunk/gli/src/org/greenstone/gatherer/cdm/LanguageManager.java	(revision 9563)
@@ -138,4 +138,5 @@
 	known_languages.clear();
 	known_languages = null;
+	default_language = null;
     }
 
@@ -192,4 +193,39 @@
     }
 
+   private int moveLanguage(Language lang, boolean move_up)
+    {
+	// Determine the current position of the language
+	int position = indexOf(lang);
+	int new_position;
+
+	// Attempt to move the language up
+	if (move_up) {
+	    // Check it's not already at the top
+	    if (position == 0) {
+		return position;
+	    }
+
+	    // This automatically removes the language first, as an Element can only exist once in a particular document
+	    new_position = position - 1;
+	    addBefore(lang, (Language) getElementAt(new_position));
+	}
+
+	// Attempt to move the language down
+	else {
+	    // Check it's not already at the bottom
+	    if (position == (getSize()) - 1) {
+		return position;
+	    }
+
+	    // This automatically removes the language first, as an Element can only exist once in a particular document
+	    new_position = position + 1;
+	    addAfter(lang, (Language) getElementAt(new_position));
+	}
+
+	// Schedule the collection for saving
+	Gatherer.c_man.configurationChanged();
+	return new_position;
+    }
+
     /** Method to remove a certain language.
      * @param language The <strong>Language</strong> to remove.
@@ -201,5 +237,4 @@
 	if(default_language != null && default_language.equals(language)) {
 	    default_language = null;
-	    ((LanguageControl)controls).clearDefaultLanguage();
 	}
 	Gatherer.c_man.configurationChanged();
@@ -243,18 +278,16 @@
 	/** The button to add a new language support. */
 	private JButton add_button = null;
-	/** The button to clear the current default language. */
-	private JButton clear_button = null;
 	/** The button to remove a supported language. */
 	private JButton remove_button = null;
+	/** button to move a language up in the list */
+	private JButton move_down_button;
+	/** button to move a language down in the list */
+	private JButton move_up_button;
 	/** The button to set the current language as the default one. */
-	private JButton set_button = null;
+	private JButton set_default_button = null;
 	/** A combobox listing the available supported languages. */
-	private JComboBox selector_combobox = null;
+	private JComboBox language_combobox = null;
 	/** A list of currently supported languages. */
-	private JList language_list = null;
-	/** A description of the language currently selected. */
-	private JTextArea description_textarea = null;
-	/** The text field showing the currently name of the default language. Non-editable. */
-	private JTextField default_language_field = null;
+	private JList selected_languages_list = null;
 	/** Constructor.
 	 * @see org.greenstone.gatherer.cdm.LanguageManager.LanguageControl.AddListener
@@ -270,35 +303,37 @@
 	    JPanel center_panel = new JPanel();
 
-	    JLabel language_list_label = new JLabel();
-	    Dictionary.registerText(language_list_label, "CDM.LanguageManager.Assigned_Languages");
-	    language_list = new JList(model);
-
+	    JLabel selected_languages_list_label = new JLabel();
+	    Dictionary.registerText(selected_languages_list_label, "CDM.LanguageManager.Assigned_Languages");
+	    selected_languages_list = new JList(model);
+	    selected_languages_list.setCellRenderer(new MyLanguageListCellRenderer());
+	    selected_languages_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+	    selected_languages_list.setVisibleRowCount(5);
 	    JPanel details_panel = new JPanel();
 
-	    JPanel default_panel = new JPanel();
-
-	    JLabel default_label = new JLabel();
-	    default_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
-	    Dictionary.registerText(default_label, "CDM.LanguageManager.Default_Language");
-
-	    if(default_language == null) {
-		default_language_field = new JTextField();
-	    }
-	    else {
-		default_language_field = new JTextField(default_language.toString());
-	    }
-	    default_language_field.setPreferredSize(COMPONENT_SIZE);
-	    default_language_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
-	    default_language_field.setEditable(false);
 	    JPanel control_panel = new JPanel();
-
 	    JLabel selector_label = new JLabel();
 	    Dictionary.registerText(selector_label, "CDM.LanguageManager.Selector");
 
-	    selector_combobox = new JComboBox(getLanguageCodes().toArray());
-	    selector_combobox.setPreferredSize(COMPONENT_SIZE);
-	    selector_combobox.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
-	    selector_combobox.setRenderer(new LanguageListCellRenderer());
-	    Dictionary.registerTooltip(selector_combobox, "CDM.LanguageManager.Selector_Tooltip");
+	    language_combobox = new JComboBox(getLanguageCodes().toArray());
+	    language_combobox.setPreferredSize(COMPONENT_SIZE);
+	    language_combobox.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
+	    language_combobox.setRenderer(new LanguageListCellRenderer());
+	    Dictionary.registerTooltip(language_combobox, "CDM.LanguageManager.Selector_Tooltip");
+
+	    JPanel movement_pane = new JPanel();
+	    move_up_button = new JButton("", Utility.getImage("arrow-up.gif"));
+	    move_up_button.setEnabled(false);
+	    move_up_button.setMnemonic(KeyEvent.VK_U);
+	    Dictionary.registerBoth(move_up_button, "CDM.Move.Move_Up", "CDM.Move.Move_Up_Tooltip");
+
+	    move_down_button = new JButton("", Utility.getImage("arrow-down.gif"));
+	    move_down_button.setEnabled(false);
+	    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);
+	    set_default_button.setMnemonic(KeyEvent.VK_S);
+	    Dictionary.registerBoth(set_default_button, "CDM.LanguageManager.Set_Default", "CDM.LanguageManager.Set_Default_Tooltip");
 
 	    JPanel button_panel = new JPanel();
@@ -307,5 +342,9 @@
 	    add_button.setMnemonic(KeyEvent.VK_A);
 	    Dictionary.registerBoth(add_button, "CDM.LanguageManager.Add", "CDM.LanguageManager.Add_Tooltip");
-
+	    if (getLanguage((String)language_combobox.getItemAt(0))==null) {
+		add_button.setEnabled(true);
+	    } else {
+		add_button.setEnabled(false);
+	    }
 	    remove_button = new GLIButton();
 	    remove_button.setMnemonic(KeyEvent.VK_R);
@@ -313,60 +352,52 @@
 	    Dictionary.registerBoth(remove_button, "CDM.LanguageManager.Remove", "CDM.LanguageManager.Remove_Tooltip");
 
-	    clear_button = new GLIButton();
-	    clear_button.setMnemonic(KeyEvent.VK_C);
-	    // If there is a default language, then this is enabled
-	    clear_button.setEnabled(default_language != null && default_language.isAssigned());
-	    Dictionary.registerBoth(clear_button, "CDM.LanguageManager.Clear_Default", "CDM.LanguageManager.Clear_Default_Tooltip");
-
-	    set_button = new GLIButton();
-	    set_button.setMnemonic(KeyEvent.VK_S);
-	    set_button.setEnabled(false);
-	    Dictionary.registerBoth(set_button, "CDM.LanguageManager.Set_Default", "CDM.LanguageManager.Set_Default_Tooltip");
-
 	    // Set up and connect listeners.
 	    add_button.addActionListener(new AddListener());
-	    clear_button.addActionListener(new ClearDefaultListener());
+	    move_down_button.addActionListener(new MoveListener(false));
+	    move_up_button.addActionListener(new MoveListener(true));
 	    remove_button.addActionListener(new RemoveListener());
-	    selector_combobox.addActionListener(new SelectorListener());
-	    set_button.addActionListener(new SetDefaultListener());
-	    language_list.addListSelectionListener(new ListListener());
+	    language_combobox.addActionListener(new SelectorListener());
+	    set_default_button.addActionListener(new SetDefaultListener());
+	    selected_languages_list.addListSelectionListener(new ListListener());
 
 	    // Layout components
-	    default_panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createEmptyBorder(2,0,2,2)));
-	    default_panel.setLayout(new BorderLayout());
-	    default_panel.add(default_label, BorderLayout.WEST);
-	    default_panel.add(default_language_field, BorderLayout.CENTER);
+	    movement_pane.setBorder(BorderFactory.createEmptyBorder(0,2,0,0));
+	    movement_pane.setLayout(new GridLayout(3,1));
+	    movement_pane.add(move_up_button);
+	    movement_pane.add(move_down_button);
+	    movement_pane.add(set_default_button);
 
 	    control_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
 	    control_panel.setLayout(new BorderLayout());
 	    control_panel.add(selector_label, BorderLayout.WEST);
-	    control_panel.add(selector_combobox, BorderLayout.CENTER);
-
-	    details_panel.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
-	    details_panel.setLayout(new BorderLayout());
-	    details_panel.add(default_panel, BorderLayout.CENTER);
-	    details_panel.add(control_panel, BorderLayout.SOUTH);
+	    control_panel.add(language_combobox, BorderLayout.CENTER);
 
 	    center_panel.setLayout(new BorderLayout());
-	    center_panel.add(language_list_label, BorderLayout.NORTH);
-	    center_panel.add(new JScrollPane(language_list), BorderLayout.CENTER);
-	    center_panel.add(details_panel, BorderLayout.SOUTH);
-
-	    button_panel.setLayout(new GridLayout(2,2));
+	    center_panel.add(selected_languages_list_label, BorderLayout.NORTH);
+	    center_panel.add(new JScrollPane(selected_languages_list), BorderLayout.CENTER);
+	    center_panel.add(movement_pane, BorderLayout.EAST);
+	    center_panel.add(control_panel, BorderLayout.SOUTH);
+
+	    button_panel.setLayout(new GridLayout(1,2));
 	    button_panel.add(add_button);
 	    button_panel.add(remove_button);
-	    button_panel.add(set_button);
-	    button_panel.add(clear_button);
-
+// 	    button_panel.add(set_button);
+// 	    button_panel.add(clear_button);
+
+	    //when we go to a multi list, remove inner_panel and empty_panel
+	    JPanel empty_panel = new JPanel();
+	    JPanel inner_panel = new JPanel();
+
+	    inner_panel.setLayout(new BorderLayout());
+	    inner_panel.add(center_panel, BorderLayout.CENTER);
+	    inner_panel.add(button_panel, BorderLayout.SOUTH);
 	    setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
 	    setLayout(new BorderLayout());
-	    add(center_panel, BorderLayout.CENTER);
-	    add(button_panel, BorderLayout.SOUTH);
+	    //add(center_panel, BorderLayout.CENTER);
+	    //add(button_panel, BorderLayout.SOUTH);
+	    add(inner_panel, BorderLayout.NORTH);
+	    add(empty_panel, BorderLayout.CENTER);
 	}
 	
-	public void clearDefaultLanguage() {
-	    clear_button.doClick();
-	}
-
 	/** Destructor.	*/
 	public void destroy() {
@@ -387,22 +418,15 @@
 	     */
 	    public void actionPerformed(ActionEvent event) {
-		String language_code = (String) selector_combobox.getSelectedItem();
+		String language_code = (String) language_combobox.getSelectedItem();
 		if(language_code != null) {
 		    addLanguage(new Language(language_code));
 		}
+		// add some collectionmeta
+		String lang_name = getLanguageName(language_code);
+		CollectionMeta metadatum = new CollectionMeta("." + language_code);
+		metadatum.setValue(lang_name);
+		CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
+
 		add_button.setEnabled(false);
-	    }
-	}
-
-	/** Listens for actions apon the 'clear default' button in the LanguageManager controls, and if detected calls the setDefault method of the manager with <i>null</i>. */
-	private class ClearDefaultListener
-	    implements ActionListener {
-	    /** Clear the default index.
-	     * @param event An <strong>ActionEvent</strong>.
-	     */
-	    public void actionPerformed(ActionEvent event) {
-		setDefault(null);
-		clear_button.setEnabled(false);
-		default_language_field.setText("");
 	    }
 	}
@@ -416,11 +440,13 @@
 	     */
 	    public void actionPerformed(ActionEvent event) {
-		Language delete_me = (Language)language_list.getSelectedValue();
+		Language delete_me = (Language)selected_languages_list.getSelectedValue();
 		if(delete_me != null) {
+		    // Remove any current metadata for this language
+		    CollectionDesignManager.collectionmeta_manager.removeMetadata("." + delete_me.getCode());
 		    removeLanguage(delete_me);
 		    if(default_language != null && default_language.equals(delete_me)) {
 			setDefault(null);
-			clear_button.setEnabled(false);
-			default_language_field.setText("");
+			//clear_button.setEnabled(false);
+			//default_language_field.setText("");
 		    }
 		}
@@ -436,5 +462,6 @@
 	     */
 	    public void actionPerformed(ActionEvent event) {
-		if(selector_combobox.getSelectedItem() != null) {
+		String language_code = (String) language_combobox.getSelectedItem();
+		if(language_code != null && getLanguage(language_code) == null) {
 		    add_button.setEnabled(true);
 		}
@@ -453,11 +480,37 @@
 	     */
 	    public void actionPerformed(ActionEvent event) {
-		if(!language_list.isSelectionEmpty()) {
-		    setDefault((Language)language_list.getSelectedValue());
-		    clear_button.setEnabled(true);
-		    default_language_field.setText(default_language.toString());
-		}
-	    }
-	}
+		Language selected_language = (Language) selected_languages_list.getSelectedValue();
+		if(selected_language != null) {
+		    setDefault(selected_language);
+		    //clear_button.setEnabled(true);
+		    // This should cause a repaint of just the desired row
+		    selected_languages_list.setSelectedValue(selected_language, true);
+		}
+		set_default_button.setEnabled(false);
+	    }
+	}
+
+	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 language
+		Language language = (Language) selected_languages_list.getSelectedValue();
+		if (language != null) {
+		    int new_position = moveLanguage(language, move_up);
+		    // Ensure the language that moved is still selected
+		    selected_languages_list.setSelectedIndex(new_position);
+		}
+	    }
+	}
+
 
 	/** Listens for selections within the list on the LanguageManager controls, and if a change is detected enables, or disables, controls appropriately. */
@@ -468,12 +521,46 @@
 	     */
 	    public void valueChanged(ListSelectionEvent event) {
-		if(language_list.isSelectionEmpty()) {
+		if (event.getValueIsAdjusting()) {
+		    return;
+		}
+		if(selected_languages_list.isSelectionEmpty()) {
 		    remove_button.setEnabled(false);
-		    set_button.setEnabled(false);
-		}
-		else {
-		    remove_button.setEnabled(true);
-		    set_button.setEnabled(true);
-		}
+		    set_default_button.setEnabled(false);
+		    move_down_button.setEnabled(false);
+ 		    move_up_button.setEnabled(false);
+		    return;
+		}
+		
+		int i = selected_languages_list.getSelectedIndex();
+ 		int size = selected_languages_list.getModel().getSize();
+		Language selected_lang = (Language)selected_languages_list.getSelectedValue();
+		remove_button.setEnabled(true);
+		set_default_button.setEnabled(default_language == null || !default_language.equals(selected_lang));
+		
+		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);
+ 		}
+	    }
+	}
+
+	private class MyLanguageListCellRenderer
+	    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_language != null && default_language.equals(value)) {
+		    component.setText(component.getText() + " " + Dictionary.get("CDM.LanguageManager.Default_Language"));
+		}
+		return component;
 	    }
 	}
