* Sets the text and selection of the dialog based on a SourcePosition.
* @param searchResultItem Specification of the hit to highlight
*/
void setResult(SearchResultItem.Precise searchResultItem) {
SourcePosition sourcePosition = searchResultItem.getSourcePosition();
// Update text if necessary
String sourceName = sourcePosition.getSourceName();
if(currentSourcePosition == null || !currentSourcePosition.getSourceName().equals(sourceName)) {
Reader sourceReader = perspective.getWorkspace().getSourceDefinition(ModuleName.make(sourceName)).getSourceReader(new Status("reading source for search hit display"));
if (sourceReader == null) {
System.err.println("Could not read source definition for source: " + sourceName);
return;
}
sourceReader = new BufferedReader(sourceReader);
try {
editorPane.read(sourceReader, null);
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
try {
sourceReader.close();
} catch (IOException e) {
}
}
}
currentSourcePosition = sourcePosition;
selectTargetAtCurrentPosition(searchResultItem.getSourceRange());
isEditable = isModuleWriteable();
String modulePath = getModulePath();
// Title depends on whether the module is readOnly
if(isEditable) {
setTitle(GemCutterMessages.getString("SD_SearchResultsTitle", sourcePosition.getSourceName(), modulePath));
} else if (modulePath != null) {
setTitle(GemCutterMessages.getString("SD_SearchResultsTitleReadOnly", sourcePosition.getSourceName(), modulePath));
} else {
setTitle(GemCutterMessages.getString("SD_SearchResultsTitleReadOnlyWithoutFile", sourcePosition.getSourceName()));
}
editorPane.setEditable(isEditable);
saveButton.setEnabled(false);
}