String repository = repositoryLabel.getToolTipText();
String fullPath = resourceLabel.getToolTipText();
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection)selection).getFirstElement();
if (obj instanceof ResourceHistoryEntry) {
ResourceHistoryEntry theEntry = (ResourceHistoryEntry)obj;
try {
IWebDavClient client = WebDavServerCache.getWebDavClient(repository);
if (client == null) {
client = WebDavClientFactory.createClient(new URL(repository));
WebDavServerCache.cacheWebDavClient(repository, client);
}
String contents = null;
try {
contents = client.getResourceVersionContents(fullPath, theEntry.getRevision());
} catch (WebDavException wde) {
if (wde.getErrorCode() != IResponse.SC_UNAUTHORIZED) {
// If not an authentication failure, we don't know what to do with it
throw wde;
}
boolean retry = PlatformUtils.getInstance().
authenticateForServer(repository, client);
if (retry) {
contents = client.getResourceVersionContents(fullPath, theEntry.getRevision());
}
}
if (contents != null) {
String editorTitle = null;
int pos = fullPath.lastIndexOf("/"); //$NON-NLS-1$
if (pos != -1
&& pos + 1 < fullPath.length()) {
editorTitle = fullPath.substring(pos + 1);
} else {
editorTitle = fullPath;
}
PlatformUtils.openEditor(contents, editorTitle + ", " + theEntry.getRevision()); //$NON-NLS-1$
}
} catch (Exception e) {
Activator.getDefault().displayError(IStatus.ERROR, e.getMessage(), e, true);
}
}