Index: /trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java	(revision 10876)
+++ /trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java	(revision 10877)
@@ -1408,4 +1408,6 @@
         private JComboBox existingSetJComboBox = new JComboBox();
             
+	private String DO_NOT_INHERIT = Dictionary.get("GEMS.Add_Set.No_Inherit");
+	
 	public AddSetActionListener() {
 	    super(self);
@@ -1488,5 +1490,5 @@
             Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit");
             
-            existingSetJComboBox.addItem("Do not inherit");
+	    existingSetJComboBox.addItem(DO_NOT_INHERIT);
             existingSetJComboBox.setSelectedIndex(getSetsLen);
             boxes_pane.add(existingSetJComboBox);
@@ -1535,15 +1537,18 @@
 		String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
 		
-                if (existingSetJComboBox.getSelectedItem().toString().trim().compareTo("Do not inherit") == 0){
-
-		// Ensure the set doesn't already exist
-                if(a_set_exists_with_this_namespace(namespace_str) == false){
-	   
+		// first check whether the namespace is valid, i.e. hasn't been used before
+		if(a_set_exists_with_this_namespace(namespace_str)) {
+		    JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
+		    return; // return back to the dialog
+		}
+		
+		//not based on another set
+		if (existingSetJComboBox.getSelectedItem().toString().equals(DO_NOT_INHERIT)){			
 		    MetadataSet set = msm.addSet(namespace_str, name_str);
-                    
-                    //mark as set changed = true
-                    set.setSetChanged(true);
-                    atLeastOneSetChanged = true;
-                    
+		    
+		    //mark as set changed = true
+		    set.setSetChanged(true);
+		    atLeastOneSetChanged = true;
+			
 		    // Update tree.
 		    model.add(null, set, GEMSNode.SET);
@@ -1551,13 +1556,6 @@
 		    set = null;
 		    setVisible(false);
-                    
-		}
-                else{
-                       JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
-                }
-                
-		name_str = null;
-		namespace_str = null;
-                }//end do not inherit
+		    
+		}
                 else {
 		    //Should change this to use XML parsing utilites --Matthew
@@ -1565,49 +1563,47 @@
                     String anitem = existingSetJComboBox.getSelectedItem().toString();
                    
-                    if(a_set_exists_with_this_namespace(namespace_field.getText()) == false){
-                        //setup to read the filename from mds file
-			String [] items = anitem.split("#%");
-                        try {
-			    FileInputStream fstream = new FileInputStream(items[1].trim());
-			    BufferedReader in = new BufferedReader(new InputStreamReader(fstream, "UTF8"));
+		    //setup to read the filename from mds file
+		    String [] items = anitem.split("#%");
+		    try {
+			FileInputStream fstream = new FileInputStream(items[1].trim());
+			BufferedReader in = new BufferedReader(new InputStreamReader(fstream, "UTF8"));
 			    
-			    FileOutputStream out;
-			    PrintWriter p;
-			    //setup to write to filename from existing file
-			    try {
-				out = new FileOutputStream(getGLIMetadataDirectoryPath() + namespace_str + ".mds");
-				OutputStreamWriter pout = new OutputStreamWriter(out, "UTF8");
-				p = new PrintWriter(pout);
+			FileOutputStream out;
+			PrintWriter p;
+			//setup to write to filename from existing file
+			try {
+			    out = new FileOutputStream(getGLIMetadataDirectoryPath() + namespace_str + ".mds");
+			    OutputStreamWriter pout = new OutputStreamWriter(out, "UTF8");
+			    p = new PrintWriter(pout);
+			    
+			    while(in.ready()){
+				String nextline = in.readLine();
 				
-				while(in.ready()){
-				    String nextline = in.readLine();
-				    
-				    if(nextline.matches(".+namespace=\".+\".*") == true) {
-					nextline = nextline.replaceFirst("namespace=\".+\"","namespace=\"" + namespace_str+ "\"");                          
-				    }
-				    else {
-					nextline = nextline.replaceFirst(">.+</Name>",">" + name_str + "</Name>");
-				    }
-				    p.print(nextline + "\n");
+				if(nextline.matches(".+namespace=\".+\".*") == true) {
+				    nextline = nextline.replaceFirst("namespace=\".+\"","namespace=\"" + namespace_str+ "\"");                          
 				}
-				p.close();
-				
-				MetadataSet loadedset = msm.loadMetadataSet(new File(getGLIMetadataDirectoryPath() + namespace_str + ".mds"));
-				model.add(null, loadedset, GEMSNode.SET);
+				else {
+				    nextline = nextline.replaceFirst(">.+</Name>",">" + name_str + "</Name>");
+				}
+				p.print(nextline + "\n");
 			    }
-			    catch(Exception e){
-				System.out.println("Print file error");
-			    }
-                        }
-                        catch(Exception e){
-                            System.out.println("File Input error");
-                        }
-                   
-                    }//msm.getset(namespacE) == null
-                    else{
-			JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
-                    }
-		    setVisible(false);
-                }
+			    p.close();
+			    
+			    MetadataSet loadedset = msm.loadMetadataSet(new File(getGLIMetadataDirectoryPath() + namespace_str + ".mds"));
+			    model.add(null, loadedset, GEMSNode.SET);
+			}
+			catch(Exception e){
+			    System.out.println("Print file error");
+			}
+		    }
+		    catch(Exception e){
+			System.out.println("File Input error");
+		    }
+		    
+		}
+		
+		name_str = null;
+		namespace_str = null;
+		setVisible(false);
 	    } //if(source == ok_button)
 	    else if(source == cancel_button) {
