UIText.ReflogView_CommitColumnHeader, 10, SWT.LEFT);
toColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
final ReflogEntry entry = (ReflogEntry) element;
return entry.getNewId().abbreviate(7).name();
}
@Override
public String getToolTipText(Object element) {
final ReflogEntry entry = (ReflogEntry) element;
return entry.getNewId().name();
}
@Override
public Image getImage(Object element) {
return branchImage;
}
});
TreeViewerColumn commitMessageColumn = createColumn(layout,
UIText.ReflogView_CommitMessageColumnHeader, 40, SWT.LEFT);
commitMessageColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
final ReflogEntry entry = (ReflogEntry) element;
RevCommit c = getCommit(entry);
return c == null ? "" : c.getShortMessage(); //$NON-NLS-1$
}
private RevCommit getCommit(final ReflogEntry entry) {
RevWalk walk = new RevWalk(getRepository());
walk.setRetainBody(true);
RevCommit c = null;
try {
c = walk.parseCommit(entry.getNewId());
} catch (IOException ignored) {
// ignore
} finally {
walk.release();
}
return c;
}
});
TreeViewerColumn dateColumn = createColumn(layout,
UIText.ReflogView_DateColumnHeader, 15, SWT.LEFT);
dateColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
final ReflogEntry entry = (ReflogEntry) element;
final PersonIdent who = entry.getWho();
// TODO add option to use RelativeDateFormatter
return absoluteFormatter.format(who.getWhen());
}
@Override
public Image getImage(Object element) {
return null;
}
});
TreeViewerColumn messageColumn = createColumn(layout,
UIText.ReflogView_MessageColumnHeader, 40, SWT.LEFT);
messageColumn.setLabelProvider(new ColumnLabelProvider() {
private ResourceManager resourceManager = new LocalResourceManager(
JFaceResources.getResources());
@Override
public String getText(Object element) {
final ReflogEntry entry = (ReflogEntry) element;
return entry.getComment();
}
public Image getImage(Object element) {
String comment = ((ReflogEntry) element).getComment();
if (comment.startsWith("commit:") || comment.startsWith("commit (initial):")) //$NON-NLS-1$ //$NON-NLS-2$
return (Image) resourceManager.get(UIIcons.COMMIT);
if (comment.startsWith("commit (amend):")) //$NON-NLS-1$
return (Image) resourceManager.get(UIIcons.AMEND_COMMIT);
if (comment.startsWith("pull")) //$NON-NLS-1$
return (Image) resourceManager.get(UIIcons.PULL);
if (comment.startsWith("clone")) //$NON-NLS-1$
return (Image) resourceManager.get(UIIcons.CLONEGIT);
if (comment.startsWith("rebase")) //$NON-NLS-1$
return (Image) resourceManager.get(UIIcons.REBASE);
if (comment.startsWith("merge")) //$NON-NLS-1$
return (Image) resourceManager.get(UIIcons.MERGE);
if (comment.startsWith("fetch")) //$NON-NLS-1$
return (Image) resourceManager.get(UIIcons.FETCH);
if (comment.startsWith("branch")) //$NON-NLS-1$
return (Image) resourceManager.get(UIIcons.CREATE_BRANCH);
if (comment.startsWith("checkout")) //$NON-NLS-1$
return (Image) resourceManager.get(UIIcons.CHECKOUT);
return null;
}
public void dispose() {
resourceManager.dispose();
super.dispose();
}
});
new OpenAndLinkWithEditorHelper(refLogTableTreeViewer) {
@Override
protected void linkToEditor(ISelection selection) {
// Not supported
}
@Override
protected void open(ISelection sel, boolean activate) {
handleOpen(sel, OpenStrategy.activateOnOpen());
}
@Override
protected void activate(ISelection selection) {
handleOpen(selection, true);
}
private void handleOpen(ISelection selection, boolean activateOnOpen) {
if (selection instanceof IStructuredSelection)
if (selection.isEmpty())
return;
Repository repo = getRepository();
if (repo == null)
return;
RevWalk walk = new RevWalk(repo);
try {
for (Object element : ((IStructuredSelection)selection).toArray()) {
ReflogEntry entry = (ReflogEntry) element;
ObjectId id = entry.getNewId();
if (id == null || id.equals(ObjectId.zeroId()))
id = entry.getOldId();
if (id != null && !id.equals(ObjectId.zeroId()))
CommitEditor.openQuiet(new RepositoryCommit(repo,
walk.parseCommit(id)), activateOnOpen);
}
} catch (IOException e) {