if (file != null && file.exists()) {
// open in editor
final IEditorPart editor = IDE.openEditor(activePage, file, false);
Assert.isNotNull(editor);
final ITextEditor textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
final IDocument document = ((textEditor).getDocumentProvider()).getDocument(editor.getEditorInput());
Assert.isNotNull(document);
final FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
try {
if (JAVA.equals(extension)) {
IRegion region = frda.find(0, '"' + wicketId + '"', true, true, false, false);
if (region != null) {
while (region != null) {
final IRegion li = document.getLineInformationOfOffset(region.getOffset());
String line = document.get(li.getOffset(), li.getLength()).trim();
if (line.startsWith("*") || line.startsWith("/*") || line.startsWith("//")) {
region = frda.find(region.getOffset() + 1, '"' + wicketId + '"', true, true, false, false);
} else {
DocumentHelper.markOccurrence(textEditor, DocumentHelper.getStringConstantName(line));
textEditor.selectAndReveal(region.getOffset() + 1, wicketId.length());
found = true;
break;
}
}
} else {
// wicket id not found in file, so search up in tree
final List<Object> supertypes = TypeHelper.getSupertypes(file);
if (supertypes.size() > 0) {
if (supertypes.get(0) instanceof IFile) {
final IEditorPart oe = IDE.openEditor(activePage, (IFile) supertypes.get(0), false);
open();
if (!found) {
activePage.closeEditor(oe, false);
}
}
}
}
} else if (HTML.equals(extension)) {
String wid_const = DocumentHelper.getNamespacePrefix(document);
final IRegion region = frda.find(0, wid_const + ":id=\"" + wicketId, true, true, true, false);
if (region != null) {
textEditor.selectAndReveal(region.getOffset() + wid_const.length() + 5, wicketId.length());
break;
}
} else if (PROPERTIES.equals(extension)) {
// for the wicket tags that use wicket:message
if (wicketId.startsWith("value:")) {
wicketId = wicketId.substring(6);
}
final IRegion regionBegin = frda.find(0, wicketId, true, true, false, false);
if (regionBegin != null) {
IRegion sr = frda.find(regionBegin.getOffset(), "\">", true, true, false, false);
if (sr == null) { // properties, select till eol
sr = frda.find(regionBegin.getOffset(), "=", true, true, false, false);
if (sr == null) {
activePage.closeEditor(editor, false);
continue;
}
final IRegion lineRegion = document.getLineInformationOfOffset(sr.getOffset());
final int selectionLength = lineRegion.getOffset() + lineRegion.getLength() - sr.getOffset();
textEditor.selectAndReveal(sr.getOffset() + 1, selectionLength - 1);
foundInPropertiesFile = true;
break;
} else { // xml, select till </
final IRegion selEnd = frda.find(regionBegin.getOffset(), "</", true, true, false, false);
textEditor.selectAndReveal(sr.getOffset() + 2, selEnd.getOffset() - sr.getOffset() - 2);
foundInPropertiesFile = true;
break;
}
} else {
activePage.closeEditor(editor, false);
continue;
}
}
} catch (final BadLocationException e) {
textEditor.resetHighlightRange();
return;
}
} else {
if (!found) {
if (JAVA.equals(extension) && !openedResource.getName().contains("_")) {