Have icon for "reset" entry in reflog
[egit/eclipse.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / revision / FileRevisionTypedElement.java
blob4c9fe87036516cbfabdb1781556706f5fd8bc3b9
1 /*******************************************************************************
2 * Copyright (c) 2006, 2015 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License 2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-2.0/
8 * SPDX-License-Identifier: EPL-2.0
10 * Contributors:
11 * IBM Corporation - initial API and implementation
12 * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 477248
13 *******************************************************************************/
14 package org.eclipse.egit.ui.internal.revision;
16 import java.net.URI;
17 import java.util.Date;
19 import org.eclipse.compare.ITypedElement;
20 import org.eclipse.core.resources.IStorage;
21 import org.eclipse.core.runtime.Assert;
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.core.runtime.IProgressMonitor;
24 import org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter;
25 import org.eclipse.team.core.history.IFileRevision;
26 import org.eclipse.ui.IEditorInput;
28 /**
29 * An {@link ITypedElement} wrapper for {@link IFileRevision} for use with the
30 * Compare framework.
32 public class FileRevisionTypedElement extends StorageTypedElement {
34 private IFileRevision fileRevision;
36 private String author;
38 /**
39 * @param fileRevision
40 * the file revision
41 * @param localEncoding
42 * the encoding of the local file that corresponds to the given
43 * file revision
45 public FileRevisionTypedElement(IFileRevision fileRevision,
46 String localEncoding) {
47 super(localEncoding);
48 Assert.isNotNull(fileRevision);
49 this.fileRevision = fileRevision;
52 @Override
53 public String getName() {
54 return fileRevision.getName();
57 @Override
58 protected IStorage fetchContents(IProgressMonitor monitor)
59 throws CoreException {
60 return fileRevision.getStorage(monitor);
64 /**
65 * @return String the string contains a unique content id
67 public String getContentIdentifier() {
68 return fileRevision.getContentIdentifier();
71 /**
72 * @return the human readable timestamp of this element
74 public String getTimestamp() {
75 long date = fileRevision.getTimestamp();
76 Date dateFromLong = new Date(date);
77 return PreferenceBasedDateFormatter.create().formatDate(dateFromLong);
80 /**
81 * @return the file revision of this element
83 public IFileRevision getFileRevision() {
84 return fileRevision;
87 /**
88 * @return the human readable path of this element
90 public String getPath() {
91 URI uri = fileRevision.getURI();
92 if (uri != null)
93 return uri.getPath();
94 return getName();
97 @Override
98 public IEditorInput getDocumentKey(Object element) {
99 if (element == this && getBufferedStorage() != null) {
100 return new FileRevisionEditorInput(fileRevision,
101 getBufferedStorage(), getLocalEncoding());
103 return null;
106 @Override
107 public int hashCode() {
108 return fileRevision.hashCode();
111 @Override
112 public boolean equals(Object obj) {
113 if (obj == this)
114 return true;
115 if (obj instanceof FileRevisionTypedElement) {
116 FileRevisionTypedElement other = (FileRevisionTypedElement) obj;
117 return other.getFileRevision().equals(getFileRevision());
119 return false;
123 * @return the author
125 public String getAuthor() {
126 if (author == null)
127 author = fileRevision.getAuthor();
128 return author;
132 * @param author
133 * the author
135 public void setAuthor(String author) {
136 this.author = author;
140 * @param monitor
141 * @throws CoreException
143 public void fetchAuthor(IProgressMonitor monitor) throws CoreException {
144 if (getAuthor() == null && fileRevision.isPropertyMissing()) {
145 IFileRevision other = fileRevision.withAllProperties(monitor);
146 author = other.getAuthor();
151 * @return the revision
153 public IFileRevision getRevision() {
154 return fileRevision;