+ "Link";
BookmarkablePageLink<Void> blameByPageLink =
new BookmarkablePageLink<Void>(blameByLinkText, BlamePage.class, blameTypePageParam);
if (activeBlameType == type) {
blameByPageLink.add(new SimpleAttributeModifier("style", "font-weight:bold;"));
}
add(blameByPageLink);
}
add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));
String format = app().settings().getString(Keys.web.datetimestampLongFormat,
"EEEE, MMMM d, yyyy HH:mm Z");
final DateFormat df = new SimpleDateFormat(format);
df.setTimeZone(getTimeZone());
PathModel pathModel = null;
List<PathModel> paths = JGitUtils.getFilesInPath(getRepository(), StringUtils.getRootPath(blobPath), commit);
for (PathModel path : paths) {
if (path.path.equals(blobPath)) {
pathModel = path;
break;
}
}
if (pathModel == null) {
final String notFound = MessageFormat.format("Blame page failed to find {0} in {1} @ {2}",
blobPath, repositoryName, objectId);
logger.error(notFound);
add(new Label("annotation").setVisible(false));
add(new Label("missingBlob", missingBlob(blobPath, commit)).setEscapeModelStrings(false));
return;
}
add(new Label("missingBlob").setVisible(false));
List<AnnotatedLine> lines = DiffUtils.blame(getRepository(), blobPath, objectId);
final Map<?, String> colorMap = initializeColors(activeBlameType, lines);
ListDataProvider<AnnotatedLine> blameDp = new ListDataProvider<AnnotatedLine>(lines);
DataView<AnnotatedLine> blameView = new DataView<AnnotatedLine>("annotation", blameDp) {
private static final long serialVersionUID = 1L;
private String lastCommitId = "";
private boolean showInitials = true;
private String zeroId = ObjectId.zeroId().getName();
@Override
public void populateItem(final Item<AnnotatedLine> item) {
final AnnotatedLine entry = item.getModelObject();
// commit id and author
if (!lastCommitId.equals(entry.commitId)) {
lastCommitId = entry.commitId;
if (zeroId.equals(entry.commitId)) {
// unknown commit
item.add(new Label("commit", "<?>"));
showInitials = false;
} else {
// show the link for first line
LinkPanel commitLink = new LinkPanel("commit", null,
getShortObjectId(entry.commitId), CommitPage.class,
newCommitParameter(entry.commitId));
WicketUtils.setHtmlTooltip(commitLink,
MessageFormat.format("{0}, {1}", entry.author, df.format(entry.when)));
item.add(commitLink);
WicketUtils.setCssStyle(item, "border-top: 1px solid #ddd;");
showInitials = true;
}
} else {
if (showInitials) {
showInitials = false;
// show author initials
item.add(new Label("commit", getInitials(entry.author)));
} else {
// hide the commit link until the next block
item.add(new Label("commit").setVisible(false));
}
}
// line number
item.add(new Label("line", "" + entry.lineNumber));
// line content
String color;
switch (activeBlameType) {
case AGE:
color = colorMap.get(entry.when);
break;
case AUTHOR:
color = colorMap.get(entry.author);
break;
default:
color = colorMap.get(entry.commitId);
break;
}
Component data = new Label("data", StringUtils.escapeForHtml(entry.data, true)).setEscapeModelStrings(false);
data.add(new SimpleAttributeModifier("style", "background-color: " + color + ";"));
item.add(data);
}
};
add(blameView);
}