Source:
<code>public static void Replace(Q7SearchResult searchResult, String replaceString, IWorkbenchPage page, IProgressMonitor monitor) throws IOException { try { monitor.beginTask(getReplaceHint(searchResult), searchResult.getMatchCount()); int scenarioPart = ((Q7SearchQuery) searchResult.getQuery()) .getSearchFor(); String searchPattern = ((Q7SearchQuery) searchResult.getQuery()) .getSearchString(); boolean IsRegEx = ((Q7SearchQuery) searchResult.getQuery()) .isRegexSearch(); <START> WriteAccessChecker writeAccessChecker = new WriteAccessChecker(); <END> if (!writeAccessChecker.makeResourceWritable(foundFiles(searchResult))) { return; } for (Object element : searchResult.getElements()) { IFile file = searchResult.getFile(element); if (file != null) { try { EclContainer scenario = adaptToEclContainer((IQ7NamedElement) RcpttCore.create(file)); String originalText = getOriginalText(scenario, scenarioPart); StringBuilder strBuilder = new StringBuilder(); int currentOffset = 0; for (Match match : searchResult.getMatches(element)) { String beforeMatch = originalText.substring( currentOffset, match.getOffset()); strBuilder.append(beforeMatch); String replacedStr = replaceString; if (IsRegEx) { String matchStr = originalText.substring( match.getOffset(), match.getOffset() + match.getLength()); replacedStr = matchStr.replaceAll( searchPattern, replaceString); } strBuilder.append(replacedStr); currentOffset = match.getOffset() + match.getLength(); monitor.worked(1); } String afterMatch = originalText .substring(currentOffset); strBuilder.append(afterMatch); IQ7NamedElement workingCopy = setNewText(scenario, scenarioPart, strBuilder.toString()); try { IEditorInput input = new FileEditorInput(file); IEditorPart editor = page.findEditor(input); if (editor == null) { workingCopy.commitWorkingCopy(true, new NullProgressMonitor()); } } finally { workingCopy.discardWorkingCopy(); } } catch (ModelException e) { Q7UIPlugin.log(e); } } } searchResult.removeAll(); } catch (CoreException e) { Q7UIPlugin.log(e); } finally { monitor.done(); } }</code><technical_language>default shell, page one</technical_language>

Target:
public static void Replace(Q7SearchResult searchResult, String replaceString, IWorkbenchPage page, IProgressMonitor monitor) throws IOException { try { monitor.beginTask(getReplaceHint(searchResult), searchResult.getMatchCount()); int scenarioPart = ((Q7SearchQuery) searchResult.getQuery()) .getSearchFor(); String searchPattern = ((Q7SearchQuery) searchResult.getQuery()) .getSearchString(); boolean IsRegEx = ((Q7SearchQuery) searchResult.getQuery()) .isRegexSearch(); Shell shell = page.getActivePart().getSite().getShell(); WriteAccessChecker writeAccessChecker = new WriteAccessChecker(shell, false); if (!writeAccessChecker.makeResourceWritable(foundFiles(searchResult))) { return; } for (Object element : searchResult.getElements()) { IFile file = searchResult.getFile(element); if (file != null) { try { EclContainer scenario = adaptToEclContainer((IQ7NamedElement) RcpttCore.create(file)); String originalText = getOriginalText(scenario, scenarioPart); StringBuilder strBuilder = new StringBuilder(); int currentOffset = 0; for (Match match : searchResult.getMatches(element)) { String beforeMatch = originalText.substring( currentOffset, match.getOffset()); strBuilder.append(beforeMatch); String replacedStr = replaceString; if (IsRegEx) { String matchStr = originalText.substring( match.getOffset(), match.getOffset() + match.getLength()); replacedStr = matchStr.replaceAll( searchPattern, replaceString); } strBuilder.append(replacedStr); currentOffset = match.getOffset() + match.getLength(); monitor.worked(1); } String afterMatch = originalText .substring(currentOffset); strBuilder.append(afterMatch); IQ7NamedElement workingCopy = setNewText(scenario, scenarioPart, strBuilder.toString()); try { IEditorInput input = new FileEditorInput(file); IEditorPart editor = page.findEditor(input); if (editor == null) { workingCopy.commitWorkingCopy(true, new NullProgressMonitor()); } } finally { workingCopy.discardWorkingCopy(); } } catch (ModelException e) { Q7UIPlugin.log(e); } } } searchResult.removeAll(); } catch (CoreException e) { Q7UIPlugin.log(e); } finally { monitor.done(); } }