Index: tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.java
===================================================================
--- tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.java	(revision 1245)
+++ tmp/org.txm.translate.rcp/src/org/txm/rcp/translate/i18n/PluginMessages.java	(revision 1246)
@@ -31,7 +31,6 @@
  *
  */
 public class PluginMessages {
-	
 	/**
 	 * Files encoding.
 	 */
@@ -46,21 +45,22 @@
 	 * Project root directory.
 	 */
 	protected File projectDirectory;
-	
+
 	/**
 	 * Java message file, eg.: TXMCoreMessages.java, ConcordanceUIMessages.java, etc.
 	 */
 	protected File javaMessageFile;
-	
+
 	/**
 	 * Source files of the project.
 	 */
 	protected ArrayList<File> srcFiles;
-	
+
 	/**
 	 * Extensions to use when creating the source files list.
 	 */
 	protected String[] srcFilesExtensions = new String[] {"java", "groovy"};
+
 	
 	/**
 	 * Global REGEX containing all keys to later use for search in files.
@@ -72,15 +72,26 @@
 	 */
 	protected HashMap<String, TreeSet<File>> usedKeysFilesIndex;
 	
+/**
+ * the XXXMessages.java messages keys
+ */
+	LinkedHashSet<String> messageKeys = new LinkedHashSet<String>();
+
+	/**
+	 * Stores the key modifications for further saves in the source files
+	 */
+	HashMap<String, String> keyModifications = new HashMap<String, String>();
 	
-	
-	LinkedHashSet<String> messageKeys = new LinkedHashSet<String>();
+	/**
+	 * The messages stored by properties file
+	 */
 	HashMap<File, BiHashMap<String, String>> langs = new HashMap<File, BiHashMap<String, String>>();
+
+	/**
+	 * the properties files langs
+	 */
 	BiHashMap<File, String> file2lang = new BiHashMap<File, String>();
 	
-	
-	
-
 	/**
 	 * 
 	 * @param projectDirectory
@@ -90,15 +101,15 @@
 	 * @throws IOException
 	 */
 	public PluginMessages(File projectDirectory, File javaMessageFile) throws UnsupportedEncodingException, FileNotFoundException, IOException {
-		
+
 		this.javaMessageFile = javaMessageFile;
 		this.projectDirectory = projectDirectory;
 		this.srcFiles = new ArrayList<File>();
-		
+
 		System.out.println("********************************************************************************************************************");
 		System.out.println("PluginMessages.PluginMessages(): project root directory = " + this.projectDirectory);
 		System.out.println("PluginMessages.PluginMessages(): java message file = " + this.javaMessageFile);
-		
+
 		File[] propFiles = javaMessageFile.getParentFile().listFiles();
 		for (File propFile : propFiles) {
 			String name = propFile.getName();
@@ -108,16 +119,16 @@
 			String lang = name.substring(8, name.indexOf(".properties"));
 			langs.put(propFile, new BiHashMap<String, String>());
 			file2lang.put(propFile, lang);
-			
+
 			BiHashMap<String, String> hash = langs.get(propFile);
-			
+
 			Properties props1 = new Properties();
 			props1.load(IOUtils.getReader(propFile, ENCODING));
 			for (Object k : props1.keySet()) {
 				hash.put(k.toString(), props1.get(k).toString());
 			}
 		}
-	
+
 		if (javaMessageFile != null) {
 			BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(javaMessageFile), ENCODING));
 			String line2 = reader2.readLine();
@@ -131,7 +142,7 @@
 			}
 			reader2.close();
 		}
-		
+
 		// create the project source files list
 		this.createSourceFilesList();
 		
@@ -243,7 +254,6 @@
 		return unusedKeys;
 	}
 
-	
 	/**
 	 * Gets the map of the messages keys and values for the specified language.
 	 * @param lang
@@ -253,53 +263,53 @@
 		File p = new File(javaMessageFile.getParentFile(), "messages" + lang + ".properties");
 		return langs.get(p);
 	}
+
 	
-	
 	public void put(String lang, String key, String message) {
 		messageKeys.add(key);
-		
+
 		File p = new File(javaMessageFile.getParentFile(), "messages"+lang+".properties");
-		
+
 		if (!langs.containsKey(p)) {
 			langs.put(p, new BiHashMap<String, String>());
 			file2lang.put(p, lang);
 		}
-		
+
 		if (message == null) {
 			langs.get(p).removeByKey(key);
 		} else {
 			langs.get(p).put(key, message);
 		}
 	}
-	
+
 	public String get(String lang, String key) {
 		File p = new File(javaMessageFile.getParentFile(), "messages"+lang+".properties");
-		
+
 		if (!file2lang.containsKey(p)) return null;
-		
+
 		return langs.get(p).get(key);
 	}
-	
+
 	public LinkedHashSet<String> getMessageKeys() {
 		return messageKeys;
 	}
-	
+
 	public File getMessageFile() {
 		return javaMessageFile;
 	}
-	
+
 	public String getMessageClassName() {
 		return javaMessageFile.getName().substring(0, javaMessageFile.getName().length()-5);
 	}
-	
+
 	public String getMessageFullClassName() {
 		return javaMessageFile.getAbsolutePath().substring(javaMessageFile.getAbsolutePath().lastIndexOf("org/txm/"), javaMessageFile.getAbsolutePath().length()-5).replace("/", ".");
 	}
-	
+
 	public String getMessageName() {
 		return javaMessageFile.getName().substring(0, javaMessageFile.getName().length()-5-8);
 	}
-	
+
 	public String getMessageFullName() {
 		return javaMessageFile.getAbsolutePath().substring(javaMessageFile.getAbsolutePath().lastIndexOf("org/txm/")+8, javaMessageFile.getAbsolutePath().length()-5-8).replace("/", ".");
 	}
@@ -312,26 +322,7 @@
 	public String getKeyFullName(String key)	{
 		return this.getMessageClassName() + "." + key;
 	}
-	
-//	public def getMissingsMessageKeys(String lang) {
-//		def missing = []
-//		for (String pKey : this.getKeys())
-//			if (!messageKeys.contains(pKey))
-//				missing << pKey
-//				
-//		return missing
-//	}
-//	
-//	public getMissingPropKeys(String lang) {
-//		def missing = []
-//		def pKeys = this.getKeys()
-//		for (String mKey : messageKeys)
-//			if (!pKeys.contains(mKey))
-//				missing << mKey
-//				
-//		return missing
-//	}
-	
+
 	public void saveChanges() throws IOException {
 
 		//Write prop File
@@ -342,67 +333,61 @@
 			for (String k : h.getKeys()) {
 				props.setProperty(k, h.get(k));
 			}
-			
-			if (propFile.exists()) {
-				File oldFile = new File(propFile.getParentFile(), propFile.getName()+".old");
-				if (oldFile.exists()) {
-					oldFile.delete();
-				}
-				propFile.renameTo(oldFile);
-			}
-			
-			props.store(IOUtils.getWriter(propFile, ENCODING),  "TXM messages generated by the PluginMessages class");
+
+			File newPropFile = new File(propFile.getParentFile(), propFile.getName()+".new");
+
+			props.store(IOUtils.getWriter(newPropFile, ENCODING), "TXM messages generated by the PluginMessages class");
 		}
-		
+
 		// write message File
 		if (javaMessageFile == null) return;
-		
-		File oldFile2 = new File(javaMessageFile.getParentFile(), javaMessageFile.getName()+".old");
-		javaMessageFile.renameTo(oldFile2); // back up
-		
+
+		File newJavaMessageFile = new File(javaMessageFile.getParentFile(), javaMessageFile.getName()+".new");
+
 		String className = getMessageClassName();
 		String name = getMessageName();
 		String classPackage = getMessageFullClassName().substring(0, getMessageFullClassName().length()- getMessageClassName().length());
-		
-		PrintWriter out = IOUtils.getWriter(javaMessageFile, ENCODING);
-		
-			// write start
-			out.println("package "+classPackage+";\n");
 
-			out.println("import org.eclipse.osgi.util.NLS;");
-			out.println("import org.txm.utils.messages.Utf8NLS;\n");
+		PrintWriter out = IOUtils.getWriter(newJavaMessageFile, ENCODING);
 
-			out.println("/** "+name+" messages. @author sjacquot, mdecorde **/");
+		// write start
+		out.println("package "+classPackage+";\n");
 
-			out.println("public class "+className+" extends NLS {");
+		out.println("import org.eclipse.osgi.util.NLS;");
+		out.println("import org.txm.utils.messages.Utf8NLS;\n");
 
-			out.println("	private static final String BUNDLE_NAME = \""+classPackage+".messages\"; //$NON-NLS-1$");
-			
-			//write keys
-			for (String key : this.getMessageKeys())
-				out.println("	public static String "+key+";");
-			
-			// write end
-			out.println("	static {");
-			out.println("		// initialize resource bundle");
-			out.println("		Utf8NLS.initializeMessages(BUNDLE_NAME, "+className+".class);");
-			out.println("	}");
+		out.println("/**\n * "+name+" messages.\n * @author sjacquot, mdecorde \n**/");
 
-			out.println("	private "+className+"() { }");
-			out.println("}");
-			
-			out.close();
+		out.println("public class "+className+" extends NLS {");
+
+		out.println("	private static final String BUNDLE_NAME = \""+classPackage+".messages\"; //$NON-NLS-1$");
+
+		//write keys
+		for (String key : this.getMessageKeys()) {
+			out.println("	public static String "+key+";");
+		}
+
+		// write end
+		out.println("	static {");
+		out.println("		// initialize resource bundle");
+		out.println("		Utf8NLS.initializeMessages(BUNDLE_NAME, "+className+".class);");
+		out.println("	}");
+
+		out.println("	private "+className+"() { }");
+		out.println("}");
+
+		out.close();
 	}
-	
+
 	public void summary() {
-		
+
 		System.out.println(getMessageClassName());
-		
+
 		System.out.println("Messages keys");
 		for (String key : messageKeys) {
 			System.out.println(key);
 		}
-		
+
 		System.out.println("Langs");
 		for (File lang : langs.keySet()) {
 			System.out.println("  ------------------------------------------------------------------------------------------------------------------------------");
@@ -415,7 +400,6 @@
 			}
 		}
 	}
-	
 
 	/**
 	 * Parses the project and stores a list of the source files. 
@@ -434,7 +418,7 @@
 			else if (!file.equals(this.javaMessageFile)
 					&& Arrays.asList(this.srcFilesExtensions).contains(FilenameUtils.getExtension(file.getName())) 
 					) {
-				
+
 				if(debug) {
 					System.out.println("PluginMessages.createSourceFilesList(): adding source files " + file + ".");
 				}
@@ -443,19 +427,58 @@
 			}
 		}
 	}
-	
+
 	/**
 	 * Parses the project and stores a list of the source files.
 	 */
 	public void createSourceFilesList()	{
 
 		System.out.println("PluginMessages.loadSourceFilesList(): creating source files list for extensions [" + StringUtils.join(this.srcFilesExtensions, ", ") + "]...");
-		
+
 		this.createSourceFilesList(this.projectDirectory);
+
+
+		if(debug) {
+			System.out.println("PluginMessages.loadSourceFilesList(): done. Source files count = " + this.srcFiles.size() + ".");
+		}
+	}
+
+	/**
+	 * Rename a key and update in the properties file the keys
+	 * 
+	 * stores the modification to rename the keys later in the Workspace source files
+	 * 
+	 * @param oldName
+	 * @param newName
+	 */
+	public void renameKey(String oldName, String newName) {
 		
-		System.out.println("PluginMessages.loadSourceFilesList(): done. Source files count = " + this.srcFiles.size() + ".");
+		if (!messageKeys.contains(oldName)) {
+			System.out.println("Missing key="+oldName+" aborting renaming to "+newName+".");
+			return;
+		}
+		
+		messageKeys.remove(oldName);
+		messageKeys.add(newName);
+		
+		for (File p : langs.keySet()) {
+			BiHashMap<String, String> h = langs.get(p);
+			if (h.containsKey(oldName)) {
+				h.put(newName, h.get(oldName));
+				h.removeByKey(oldName);
+			}
+		}
+		
+		keyModifications.put(oldName, newName);
 	}
 
+	/**
+	 * 
+	 * @return the renamed keys
+	 */
+	public HashMap<String, String> getKeyModifications() {
+		return keyModifications;
+	}
 	
 	public BiHashMap<File, String> getFile2lang() {
 		return file2lang;
@@ -469,11 +492,12 @@
 	 * Gets the project root directory.
 	 * @return the projectDirectory
 	 */
+
 	public File getProjectDirectory() {
 		return projectDirectory;
 	}
+
 	
-	
 	/**
      * Dumps the specified BiHashMap<String, String> to standard output.
      */
@@ -493,13 +517,14 @@
 	 * @throws IOException
 	 */
 	public static void main(String[] args) throws UnsupportedEncodingException, FileNotFoundException, IOException {
-		
+
 		File projectFile = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath() + "/org.txm.core");
 		File messageFile = new File(projectFile, "src/java/org/txm/core/messages/TXMCoreMessages.java");
-		
+
 		PluginMessages pmManager = new PluginMessages(projectFile, messageFile);
-		
+
 		// test to find files using the specified key
+
 		String key = "Base_0";
 		TreeSet<File> files = pmManager.getFilesUsingKey(key);
 	    System.out.println("getFilesUsingKey: files using key: " + key);
@@ -512,17 +537,16 @@
 	    for(File file : files)	{
 	    	System.out.println("   file: " + file);
 	    }
-		
 	    
 		// test to find unused keys
 		ArrayList<String> unusedKeys = pmManager.getUnusedKeys();
 		for (int i = 0; i < unusedKeys.size(); i++) {
 			System.out.println("findUnusedKeys: key " + unusedKeys.get(i) + " is unused in project " + pmManager.getProjectDirectory() + " (main language value = " + pmManager.getMessagesForLang("").get(unusedKeys.get(i)) + ")");	
 		}
-		
+
 		//dict.summary();
 		//dict.saveChanges();
-		
+
 		System.out.println("PluginMessages.main(): done.");
 	}
 
@@ -532,6 +556,4 @@
 	public HashMap<String, TreeSet<File>> getUsedKeysFilesIndex() {
 		return usedKeysFilesIndex;
 	}
-
-    
 }
