Temporal fix for AST modification errors
diff --git a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/autocompletion/InsertResourceBundleReferenceProposal.java b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/autocompletion/InsertResourceBundleReferenceProposal.java
index 308dac1..68088f8 100644
--- a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/autocompletion/InsertResourceBundleReferenceProposal.java
+++ b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/autocompletion/InsertResourceBundleReferenceProposal.java
@@ -58,7 +58,7 @@
 		String key = dialog.getSelectedResource();
 		Locale locale = dialog.getSelectedLocale();
 
-		reference = ASTutilsUI.insertExistingBundleRef(document, resource,
+		reference = ASTutilsUI.insertExistingBundleRef(null, resource,
 				offset, length, resourceBundleId, key, locale);
 	}
 
diff --git a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/autocompletion/NewResourceBundleEntryProposal.java b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/autocompletion/NewResourceBundleEntryProposal.java
index 8a68647..393762d 100644
--- a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/autocompletion/NewResourceBundleEntryProposal.java
+++ b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/autocompletion/NewResourceBundleEntryProposal.java
@@ -53,7 +53,7 @@
     @Override
     public void apply(IDocument document) {
 
-        CreateResourceBundleEntryDialog dialog = new CreateResourceBundleEntryDialog(
+        final CreateResourceBundleEntryDialog dialog = new CreateResourceBundleEntryDialog(
                 Display.getDefault().getActiveShell());
 
         DialogConfiguration config = dialog.new DialogConfiguration();
@@ -74,13 +74,13 @@
 
         try {
             if (!bundleContext) {
-                reference = ASTutilsUI.insertNewBundleRef(document, resource,
+                reference = ASTutilsUI.insertNewBundleRef(null, resource,
                         startPos, endPos - startPos, resourceBundleId, key);
             } else {
                 document.replace(startPos, endPos - startPos, key);
                 reference = key + "\"";
             }
-            ResourceBundleManager.rebuildProject(resource);
+            //ResourceBundleManager.rebuildProject(resource);
         } catch (Exception e) {
             Logger.logError(e);
         }
diff --git a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/quickfix/ExportToResourceBundleResolution.java b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/quickfix/ExportToResourceBundleResolution.java
index bcceaed..3b30d97 100644
--- a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/quickfix/ExportToResourceBundleResolution.java
+++ b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/quickfix/ExportToResourceBundleResolution.java
@@ -23,9 +23,14 @@
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IMarkerResolution2;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.texteditor.ITextEditor;
 
 public class ExportToResourceBundleResolution implements IMarkerResolution2 {
 
@@ -83,7 +88,8 @@
                     .insertNewBundleRef(document, resource, startPos, endPos,
                             dialog.getSelectedResourceBundle(),
                             dialog.getSelectedKey());
-
+            
+            document.replace(startPos, 0, "");
             textFileBuffer.commit(null, false);
         } catch (Exception e) {
             e.printStackTrace();
diff --git a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/quickfix/IgnoreStringFromInternationalization.java b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/quickfix/IgnoreStringFromInternationalization.java
index d40dcc2..a60bd22 100644
--- a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/quickfix/IgnoreStringFromInternationalization.java
+++ b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/quickfix/IgnoreStringFromInternationalization.java
@@ -54,7 +54,7 @@
             int position = marker.getAttribute(IMarker.CHAR_START, 0);
 
             ASTutils.createReplaceNonInternationalisationComment(cu, document,
-                    position);
+                    position, 1);
             textFileBuffer.commit(null, false);
 
         } catch (JavaModelException e) {
diff --git a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/util/ASTutilsUI.java b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/util/ASTutilsUI.java
index e2d6f1c..8d619cd 100644
--- a/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/util/ASTutilsUI.java
+++ b/org.eclipse.babel.tapiji.tools.java.ui/src/org/eclipse/babel/tapiji/tools/java/ui/util/ASTutilsUI.java
@@ -41,7 +41,6 @@
 import org.eclipse.jdt.core.JavaCore;

 import org.eclipse.jdt.core.JavaModelException;

 import org.eclipse.jdt.core.dom.AST;

-import org.eclipse.jdt.core.dom.ASTParser;

 import org.eclipse.jdt.core.dom.CompilationUnit;

 import org.eclipse.jdt.core.dom.ImportDeclaration;

 import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;

@@ -55,307 +54,318 @@
 

 public class ASTutilsUI {

 

-    public static ICompilationUnit getCompilationUnit(IResource resource) {

-        return (ICompilationUnit) JavaCore.create(resource,

-                JavaCore.create(resource.getProject()));

-    }

+	public static ICompilationUnit getCompilationUnit(IResource resource) {

+		return (ICompilationUnit) JavaCore.create(resource,

+				JavaCore.create(resource.getProject()));

+	}

 

-    public static CompilationUnit getAstRoot(ITypeRoot typeRoot) {

-        // get a reference to the shared AST of the loaded CompilationUnit

-        CompilationUnit cu = SharedASTProvider.getAST(typeRoot,

-        // do not wait for AST creation

-                SharedASTProvider.WAIT_YES, null);

+	public static CompilationUnit getAstRoot(ITypeRoot typeRoot) {

+		// get a reference to the shared AST of the loaded CompilationUnit

+		CompilationUnit cu = SharedASTProvider.getAST(typeRoot,

+		// do not wait for AST creation

+				SharedASTProvider.WAIT_YES, null);

 

-        return cu;

-    }

+		return cu;

+	}

 

-    public static String insertNewBundleRef(IDocument document,

-            IResource resource, int startPos, int endPos,

-            String resourceBundleId, String key) {

-        boolean createRBReference = false;

-        String reference = "";

+	public static String insertNewBundleRef(IDocument origDocument,

+			IResource resource, int startPos, int endPos,

+			String resourceBundleId, String key) {

+		boolean createRBReference = false;

+		String reference = "";

 

-        try {

-            // creation of DOM/AST from a ICompilationUnit

-            ICompilationUnit cu = getCompilationUnit(resource);

-            CompilationUnit astRoot = getAstRoot(cu);

-            AST ast = astRoot.getAST();

+		try {

+			final ICompilationUnit cu = getCompilationUnit(resource);

+			final CompilationUnit astRoot = getAstRoot(cu);

+			final AST ast = astRoot.getAST();

+			final ASTRewrite rewriter = ASTRewrite.create(ast);

+			IDocument document;

 

-            ASTRewrite rewriter = ASTRewrite.create(ast);

-            final String source = cu.getSource();

-            document = new Document(source);

+			if (origDocument == null) {

+				final String source = cu.getSource();

+				document = new Document(source);

+			} else {

+				document = origDocument;

+			}

 

-            String variableName = ASTutils.resolveRBReferenceVar(document,

-                    resource, startPos, resourceBundleId, astRoot);

-            if (variableName == null) {

-                variableName = ASTutils.getNonExistingRBRefName(

-                        resourceBundleId, astRoot);

-                createRBReference = true;

-            }

+			String variableName = ASTutils.resolveRBReferenceVar(document,

+					resource, startPos, resourceBundleId, astRoot);

+			if (variableName == null) {

+				variableName = ASTutils.getNonExistingRBRefName(

+						resourceBundleId, astRoot);

+				createRBReference = true;

+			}

 

-            try {

-                reference = ASTutils.createResourceReference(resourceBundleId,

-                        key, null, resource, startPos, variableName, ast,

-                        rewriter, astRoot);

+			try {

+				reference = ASTutils.createResourceReference(resourceBundleId,

+						key, null, resource, startPos, variableName, ast,

+						rewriter, astRoot);

 

-                if (reference != null) {

-                    if (startPos > 0

-                            && document.get().charAt(startPos - 1) == '\"') {

-                        startPos--;

-                        endPos++;

-                    }

+				if (reference != null) {

+					if (startPos > 0

+							&& document.get().charAt(startPos - 1) == '\"') {

+						startPos--;

+						endPos++;

+					}

 

-                    if ((startPos + endPos) < document.getLength()

-                            && document.get().charAt(startPos + endPos) == '\"') {

-                        endPos++;

-                    }

+					if ((startPos + endPos) < document.getLength()

+							&& document.get().charAt(startPos + endPos) == '\"') {

+						endPos++;

+					}

 

-                    if ((startPos + endPos) < document.getLength()

-                            && document.get().charAt(startPos + endPos - 1) == ';') {

-                        endPos--;

-                    }

+					if ((startPos + endPos) < document.getLength()

+							&& document.get().charAt(startPos + endPos - 1) == ';') {

+						endPos--;

+					}

 

-                    document.replace(startPos, endPos, reference);

+					document.replace(startPos, endPos, reference);

 

-                }

-                // create non-internationalisation-comment

-                ASTutils.createReplaceNonInternationalisationComment(astRoot,

-                        document, startPos);

-            } catch (BadLocationException e) {

-                e.printStackTrace();

-            }

+				}

+				// create non-internationalisation-comment

+				ASTutils.createReplaceNonInternationalisationComment(astRoot,

+						document, startPos, reference == null ? 0 : 1);

+			} catch (BadLocationException e) {

+				e.printStackTrace();

+			}

 

-            if (createRBReference) {

-                ASTutils.createResourceBundleReference(resource, startPos,

-                        document, resourceBundleId, null, true, variableName,

-                        astRoot, ast, rewriter);

-            }

+			if (createRBReference) {

+				ASTutils.createResourceBundleReference(resource, startPos,

+						document, resourceBundleId, null, true, variableName,

+						astRoot, ast, rewriter);

+			}

 

-            // computation of the text edits

-            TextEdit edits = rewriter.rewriteAST(document, null);

+			// computation of the text edits

+			TextEdit edits = rewriter.rewriteAST(document, null);

 

-            // computation of the new source code

-            try {

-                edits.apply(document);

-                String newSource = document.get();

+			// computation of the new source code

+			try {

+				edits.apply(document);

 

-                // update of the compilation unit

-                cu.getBuffer().setContents(newSource);

-            } catch (MalformedTreeException e) {

-                Logger.logError(e);

-            } catch (BadLocationException e) {

-                Logger.logError(e);

-            }

-        } catch (JavaModelException e) {

-            Logger.logError(e);

-        }

+				if (origDocument == null) {

+					String newSource = document.get();

 

-        return reference;

-    }

+					// update of the compilation unit

+					cu.getBuffer().setContents(newSource);

+				}

+			} catch (MalformedTreeException e) {

+				Logger.logError(e);

+			} catch (BadLocationException e) {

+				Logger.logError(e);

+			}

+		} catch (JavaModelException e) {

+			Logger.logError(e);

+		}

 

-    public static String insertExistingBundleRef(IDocument document,

-            IResource resource, int offset, int length,

-            String resourceBundleId, String key, Locale locale) {

-        boolean createRBReference = false;

-        String reference = "";

+		return reference;

+	}

 

-        try {

+	public static String insertExistingBundleRef(IDocument origDocument,

+			IResource resource, int startPos, int length,

+			String resourceBundleId, String key, Locale locale) {

+		boolean createRBReference = false;

+		String reference = "";

 

-            ICompilationUnit cu = getCompilationUnit(resource);

+		try {

+			final ICompilationUnit cu = getCompilationUnit(resource);

+			final CompilationUnit astRoot = getAstRoot(cu);

+			final AST ast = astRoot.getAST();

+			final ASTRewrite rewriter = ASTRewrite.create(ast);

+			IDocument document;

 

-            // creation of DOM/AST from a ICompilationUnit

-            CompilationUnit astRoot = getAstRoot(cu);

-            AST ast = astRoot.getAST();

+			if (origDocument == null) {

+				final String source = cu.getSource();

+				document = new Document(source);

+			} else {

+				document = origDocument;

+			}

 

-            ASTRewrite rewriter = ASTRewrite.create(ast);

-            final String source = cu.getSource();

-            document = new Document(source);

+			String variableName = ASTutils.resolveRBReferenceVar(document,

+					resource, startPos, resourceBundleId, astRoot);

+			if (variableName == null) {

+				variableName = ASTutils.getNonExistingRBRefName(

+						resourceBundleId, astRoot);

+				createRBReference = true;

+			}

 

-            String variableName = ASTutils.resolveRBReferenceVar(document,

-                    resource, offset, resourceBundleId, astRoot);

+			reference = ASTutils.createResourceReference(resourceBundleId, key,

+					locale, resource, startPos, variableName, ast, rewriter,

+					astRoot);

 

-            if (variableName == null) {

-                variableName = ASTutils.getNonExistingRBRefName(

-                        resourceBundleId, astRoot);

-                createRBReference = true;

-            }

+			if (reference != null) {

+				try {

+					document.replace(startPos, length, reference);

+				} catch (BadLocationException e) {

+					Logger.logError(e);

+					return null;

+				}

+			}

+			// create non-internationalisation-comment

+			ASTutils.createReplaceNonInternationalisationComment(astRoot,

+					document, startPos, reference == null ? 0 : 1);

 

-            reference = ASTutils.createResourceReference(resourceBundleId, key,

-                    locale, resource, offset, variableName, ast, rewriter,

-                    astRoot);

+			// TODO retrieve cu in the same way as in createResourceReference

+			// the current version does not parse method bodies

 

-            if (reference != null) {

-                try {

-                    document.replace(offset, length, reference);

-                } catch (BadLocationException e) {

-                    Logger.logError(e);

-                    return null;

-                }

-            }

-            // create non-internationalisation-comment

-            ASTutils.createReplaceNonInternationalisationComment(astRoot,

-                    document, offset);

+			if (createRBReference) {

+				ASTutils.createResourceBundleReference(resource, startPos,

+						document, resourceBundleId, locale, true, variableName,

+						astRoot, ast, rewriter);

+			}

 

-            // TODO retrieve cu in the same way as in createResourceReference

-            // the current version does not parse method bodies

+			// computation of the text edits

+			TextEdit edits = rewriter.rewriteAST(document, null);

 

-            if (createRBReference) {

-                ASTutils.createResourceBundleReference(resource, offset,

-                        document, resourceBundleId, locale, true, variableName,

-                        astRoot, ast, rewriter);

-            }

+			// computation of the new source code

+			try {

+				edits.apply(document);

+				

+				if (origDocument == null) {

+					String newSource = document.get();

+	

+					// update of the compilation unit

+					cu.getBuffer().setContents(newSource);

+				}

+			} catch (MalformedTreeException e) {

+				Logger.logError(e);

+			} catch (BadLocationException e) {

+				Logger.logError(e);

+			}

 

-            // computation of the text edits

-            TextEdit edits = rewriter.rewriteAST(document, null);

+		} catch (JavaModelException e) {

+			Logger.logError(e);

+		}

 

-            // computation of the new source code

-            try {

-                edits.apply(document);

-                String newSource = document.get();

+		return reference;

+	}

 

-                // update of the compilation unit

-                cu.getBuffer().setContents(newSource);

-            } catch (MalformedTreeException e) {

-                Logger.logError(e);

-            } catch (BadLocationException e) {

-                Logger.logError(e);

-            }

+	/**

+	 * Performs the refactoring of messages key. The key can be a {@link String}

+	 * or an Enumeration! If it is an enumeration, then the enumPath needs to be

+	 * provided!

+	 * 

+	 * @param projectName

+	 *            The name of the project, where the resource bundle file is in

+	 * @param resourceBundleId

+	 *            The Id of the resource bundle, which contains the old key

+	 * @param selectedLocale

+	 *            The {@link Locale} to change

+	 * @param oldKey

+	 *            The name of the key to change

+	 * @param newKey

+	 *            The name of the key, which replaces the old one

+	 * @param enumPath

+	 *            The path of the enum file (needs:

+	 *            {@link IPath#toPortableString()})

+	 */

+	public static void refactorKey(final String projectName,

+			final String resourceBundleId, final String selectedLocale,

+			final String oldKey, final String newKey, final String enumPath) {

 

-        } catch (JavaModelException e) {

-            Logger.logError(e);

-        }

+		// contains file and line

+		final List<String> changeSet = new ArrayList<String>();

 

-        return reference;

-    }

+		ResourceBundleManager manager = ResourceBundleManager

+				.getManager(projectName);

+		IProject project = manager.getProject();

 

-    /**

-     * Performs the refactoring of messages key. The key can be a {@link String}

-     * or an Enumeration! If it is an enumeration, then the enumPath needs to be

-     * provided!

-     *

-     * @param projectName

-     *            The name of the project, where the resource bundle file is in

-     * @param resourceBundleId

-     *            The Id of the resource bundle, which contains the old key

-     * @param selectedLocale

-     *            The {@link Locale} to change

-     * @param oldKey

-     *            The name of the key to change

-     * @param newKey

-     *            The name of the key, which replaces the old one

-     * @param enumPath

-     *            The path of the enum file (needs:

-     *            {@link IPath#toPortableString()})

-     */

-    public static void refactorKey(final String projectName,

-            final String resourceBundleId, final String selectedLocale,

-            final String oldKey, final String newKey, final String enumPath) {

+		try {

+			project.accept(new IResourceVisitor() {

 

-        // contains file and line

-        final List<String> changeSet = new ArrayList<String>();

+				/**

+				 * First step of filtering. Only classes, which import

+				 * java.util.ResourceBundle or ch.qos.cal10n.MessageConveyor

+				 * will be changed. An exception is the enum file, which gets

+				 * referenced by the Cal10n framework.

+				 * 

+				 * {@inheritDoc}

+				 */

+				@Override

+				public boolean visit(IResource resource) throws CoreException {

+					if (!(resource instanceof IFile)

+							|| !resource.getFileExtension().equals("java")) {

+						return true;

+					}

 

-        ResourceBundleManager manager = ResourceBundleManager

-                .getManager(projectName);

-        IProject project = manager.getProject();

+					final ICompilationUnit icu = getCompilationUnit(resource);

+					final CompilationUnit cu = getAstRoot(icu);

 

-        try {

-            project.accept(new IResourceVisitor() {

+					// step 1: import filter

+					for (Object obj : cu.imports()) {

+						ImportDeclaration imp = (ImportDeclaration) obj;

+						String importName = imp.getName().toString();

+						if ("java.util.ResourceBundle".equals(importName)) {

+							PrimitiveRefactoringVisitor prv = new PrimitiveRefactoringVisitor(

+									cu, resourceBundleId, oldKey, newKey,

+									changeSet);

+							cu.accept(prv);

+							prv.saveChanges();

+							break;

+						} else if ("ch.qos.cal10n.MessageConveyor"

+								.equals(importName)) { // Cal10n

+							Cal10nRefactoringVisitor crv = new Cal10nRefactoringVisitor(

+									cu, oldKey, newKey, enumPath, changeSet);

+							cu.accept(crv);

+							crv.saveChanges();

+							break;

+						}

+					}

 

-                /**

-                 * First step of filtering. Only classes, which import

-                 * java.util.ResourceBundle or ch.qos.cal10n.MessageConveyor

-                 * will be changed. An exception is the enum file, which gets

-                 * referenced by the Cal10n framework.

-                 *

-                 * {@inheritDoc}

-                 */

-                @Override

-                public boolean visit(IResource resource) throws CoreException {

-                    if (!(resource instanceof IFile)

-                            || !resource.getFileExtension().equals("java")) {

-                        return true;

-                    }

+					return false;

+				}

+			});

+		} catch (CoreException e) {

+			Logger.logError(e);

+		}

 

-                    final ICompilationUnit icu = getCompilationUnit(resource);

-                    final CompilationUnit cu = getAstRoot(icu);

+		if (enumPath != null) { // Cal10n support, change the enum file

+			IFile file = project.getFile(enumPath.substring(project.getName()

+					.length() + 1));

+			final CompilationUnit enumCu = getAstRoot(getCompilationUnit(file));

 

-                    // step 1: import filter

-                    for (Object obj : cu.imports()) {

-                        ImportDeclaration imp = (ImportDeclaration) obj;

-                        String importName = imp.getName().toString();

-                        if ("java.util.ResourceBundle".equals(importName)) {

-                            PrimitiveRefactoringVisitor prv = new PrimitiveRefactoringVisitor(

-                                    cu, resourceBundleId, oldKey, newKey,

-                                    changeSet);

-                            cu.accept(prv);

-                            prv.saveChanges();

-                            break;

-                        } else if ("ch.qos.cal10n.MessageConveyor"

-                                .equals(importName)) { // Cal10n

-                            Cal10nRefactoringVisitor crv = new Cal10nRefactoringVisitor(

-                                    cu, oldKey, newKey, enumPath, changeSet);

-                            cu.accept(crv);

-                            crv.saveChanges();

-                            break;

-                        }

-                    }

+			Cal10nEnumRefactoringVisitor enumVisitor = new Cal10nEnumRefactoringVisitor(

+					enumCu, oldKey, newKey, changeSet);

+			enumCu.accept(enumVisitor);

+		}

 

-                    return false;

-                }

-            });

-        } catch (CoreException e) {

-            Logger.logError(e);

-        }

+		// change backend

+		RBManager rbManager = RBManager.getInstance(projectName);

+		IMessagesBundleGroup messagesBundleGroup = rbManager

+				.getMessagesBundleGroup(resourceBundleId);

 

-        if (enumPath != null) { // Cal10n support, change the enum file

-            IFile file = project.getFile(enumPath.substring(project.getName()

-                    .length() + 1));

-            final CompilationUnit enumCu = getAstRoot(getCompilationUnit(file));

+		DirtyHack.setFireEnabled(false); // now the editor won't get dirty

+		// but with this change, we have to write it manually down ->

+		// rbManager.writeToFile

+		if (KeyRefactoringDialog.ALL_LOCALES.equals(selectedLocale)) {

+			messagesBundleGroup.renameMessageKeys(oldKey, newKey);

 

-            Cal10nEnumRefactoringVisitor enumVisitor = new Cal10nEnumRefactoringVisitor(

-                    enumCu, oldKey, newKey, changeSet);

-            enumCu.accept(enumVisitor);

-        }

+		} else {

+			IMessagesBundle messagesBundle = messagesBundleGroup

+					.getMessagesBundle(LocaleUtils.getLocaleByDisplayName(

+							manager.getProvidedLocales(resourceBundleId),

+							selectedLocale));

+			messagesBundle.renameMessageKey(oldKey, newKey);

+			// rbManager.fireResourceChanged(messagesBundle); ??

+		}

+		DirtyHack.setFireEnabled(true);

 

-        // change backend

-        RBManager rbManager = RBManager.getInstance(projectName);

-        IMessagesBundleGroup messagesBundleGroup = rbManager

-                .getMessagesBundleGroup(resourceBundleId);

+		rbManager.fireEditorChanged(); // notify Resource Bundle View

+		rbManager.writeToFile(rbManager

+				.getMessagesBundleGroup(resourceBundleId));

 

-        DirtyHack.setFireEnabled(false); // now the editor won't get dirty

-        // but with this change, we have to write it manually down ->

-        // rbManager.writeToFile

-        if (KeyRefactoringDialog.ALL_LOCALES.equals(selectedLocale)) {

-            messagesBundleGroup.renameMessageKeys(oldKey, newKey);

+		// show the summary dialog

+		KeyRefactoringSummaryDialog summaryDialog = new KeyRefactoringSummaryDialog(

+				Display.getDefault().getActiveShell());

 

-        } else {

-            IMessagesBundle messagesBundle = messagesBundleGroup

-                    .getMessagesBundle(LocaleUtils.getLocaleByDisplayName(

-                            manager.getProvidedLocales(resourceBundleId),

-                            selectedLocale));

-            messagesBundle.renameMessageKey(oldKey, newKey);

-            // rbManager.fireResourceChanged(messagesBundle); ??

-        }

-        DirtyHack.setFireEnabled(true);

+		DialogConfiguration config = summaryDialog.new DialogConfiguration();

+		config.setPreselectedKey(oldKey);

+		config.setNewKey(newKey);

+		config.setPreselectedBundle(resourceBundleId);

+		config.setProjectName(projectName);

 

-        rbManager.fireEditorChanged(); // notify Resource Bundle View

-        rbManager.writeToFile(rbManager

-                .getMessagesBundleGroup(resourceBundleId));

+		summaryDialog.setDialogConfiguration(config);

+		summaryDialog.setChangeSet(changeSet);

 

-        // show the summary dialog

-        KeyRefactoringSummaryDialog summaryDialog = new KeyRefactoringSummaryDialog(

-                Display.getDefault().getActiveShell());

-

-        DialogConfiguration config = summaryDialog.new DialogConfiguration();

-        config.setPreselectedKey(oldKey);

-        config.setNewKey(newKey);

-        config.setPreselectedBundle(resourceBundleId);

-        config.setProjectName(projectName);

-

-        summaryDialog.setDialogConfiguration(config);

-        summaryDialog.setChangeSet(changeSet);

-

-        summaryDialog.open();

-    }

+		summaryDialog.open();

+	}

 

 }

diff --git a/org.eclipse.babel.tapiji.tools.java/src/org/eclipse/babel/tapiji/tools/java/util/ASTutils.java b/org.eclipse.babel.tapiji.tools.java/src/org/eclipse/babel/tapiji/tools/java/util/ASTutils.java
index 5eb9901..00e2a94 100644
--- a/org.eclipse.babel.tapiji.tools.java/src/org/eclipse/babel/tapiji/tools/java/util/ASTutils.java
+++ b/org.eclipse.babel.tapiji.tools.java/src/org/eclipse/babel/tapiji/tools/java/util/ASTutils.java
@@ -422,14 +422,14 @@
 	}
 
 	public static void createReplaceNonInternationalisationComment(
-			CompilationUnit cu, IDocument doc, int position) {
+			CompilationUnit cu, IDocument doc, int position, int nonNlsOffset) {
 		int i = findNonInternationalisationPosition(cu, doc, position);
 
 		IRegion reg;
 		try {
 			reg = doc.getLineInformationOfOffset(position);
 			doc.replace(reg.getOffset() + reg.getLength(), 0, " //$NON-NLS-"
-					+ i + "$");
+					+ (i + nonNlsOffset) + "$");
 		} catch (BadLocationException e) {
 			Logger.logError(e);
 		}
@@ -590,7 +590,7 @@
 
 		List<StringLiteral> strings = lsfinder.getStrings();
 
-		return strings.size() + 1;
+		return strings.size();
 	}
 
 	public static boolean existsNonInternationalisationComment(
@@ -637,7 +637,7 @@
 				// ignore string which is on given position
 			} else if (commentFrag.matches("^\\$non-nls-\\d+\\$$")) {
 				int iString = findNonInternationalisationPosition(cu, doc,
-						literal.getStartPosition());
+						literal.getStartPosition())+1;
 				int iComment = new Integer(commentFrag.substring(9, 10));
 				if (iString == iComment) {
 					return true;
@@ -887,6 +887,7 @@
 			try {
 				if (line == document.getLineOfOffset(node.getStartPosition())
 						&& node.getStartPosition() < position) {
+					Logger.logInfo(node.getLiteralValue());
 					strings.add(node);
 					return true;
 				}