viewer.getTree().setHeaderVisible(true);
viewer.getTree().setLinesVisible(true);
labelProvider = WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider();
final SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$
final CompareConfiguration config = new CompareConfiguration();
TreeViewerColumn resourceColumn = new TreeViewerColumn(viewer, SWT.LEAD);
resourceColumn.getColumn().setText("Changes");
resourceColumn.getColumn().setWidth(100);
resourceColumn.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
if (element instanceof BatchModelChange) {
StringBuffer buffer = new StringBuffer();
BatchModelChange batchChange = (BatchModelChange) element;
buffer.append(batchChange.isOutgoing() ? "Outgoing"
: "Incoming");
buffer.append(" (");
buffer.append(formatter.format(new Date(batchChange
.getTime())));
buffer.append(')');
return buffer.toString();
} else {
return new Path(((ResourceChangeMessage) element).getPath())
.lastSegment();
}
}
public Image getImage(Object element) {
if (element instanceof BatchModelChange) {
Image image = PlatformUI.getWorkbench().getSharedImages()
.getImage(ISharedImages.IMG_OBJ_FOLDER);
int kind = 0;
if (((BatchModelChange) element).isOutgoing()) {
kind = (kind & ~SyncInfo.OUTGOING)
| SyncInfo.INCOMING | SyncInfo.CHANGE;
} else {
kind = (kind & ~SyncInfo.OUTGOING)
| SyncInfo.OUTGOING | SyncInfo.CHANGE;
}
return config.getImage(image, kind);
} else {
ResourceChangeMessage message = (ResourceChangeMessage) element;
int type = message.getType();
IPath path = new Path(message.getPath());
Image image = null;
if (type == IResource.FILE) {
image = labelProvider.getImage(ResourcesPlugin
.getWorkspace().getRoot().getFile(path));
} else {
image = labelProvider.getImage(ResourcesPlugin
.getWorkspace().getRoot().getFolder(path));
}
if (message.isConflicted()) {
return config.getImage(image, SyncInfo.CHANGE
| SyncInfo.CONFLICTING);
}
int imageKind = 0;
switch (message.getKind()) {
case IResourceDelta.ADDED:
imageKind = (imageKind & ~SyncInfo.CHANGE)
| SyncInfo.DELETION;
break;
case IResourceDelta.CHANGED:
imageKind = (imageKind & ~SyncInfo.CHANGE)
| SyncInfo.CHANGE;
break;
case IResourceDelta.REMOVED:
imageKind = (imageKind & ~SyncInfo.CHANGE)
| SyncInfo.ADDITION;
break;
default:
return null;
}
return config.getImage(image, imageKind);
}
}
});
TreeViewerColumn pathColumn = new TreeViewerColumn(viewer, SWT.LEAD);