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
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
;
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
;
29 * An {@link ITypedElement} wrapper for {@link IFileRevision} for use with the
32 public class FileRevisionTypedElement
extends StorageTypedElement
{
34 private IFileRevision fileRevision
;
36 private String author
;
41 * @param localEncoding
42 * the encoding of the local file that corresponds to the given
45 public FileRevisionTypedElement(IFileRevision fileRevision
,
46 String localEncoding
) {
48 Assert
.isNotNull(fileRevision
);
49 this.fileRevision
= fileRevision
;
53 public String
getName() {
54 return fileRevision
.getName();
58 protected IStorage
fetchContents(IProgressMonitor monitor
)
59 throws CoreException
{
60 return fileRevision
.getStorage(monitor
);
65 * @return String the string contains a unique content id
67 public String
getContentIdentifier() {
68 return fileRevision
.getContentIdentifier();
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
);
81 * @return the file revision of this element
83 public IFileRevision
getFileRevision() {
88 * @return the human readable path of this element
90 public String
getPath() {
91 URI uri
= fileRevision
.getURI();
98 public IEditorInput
getDocumentKey(Object element
) {
99 if (element
== this && getBufferedStorage() != null) {
100 return new FileRevisionEditorInput(fileRevision
,
101 getBufferedStorage(), getLocalEncoding());
107 public int hashCode() {
108 return fileRevision
.hashCode();
112 public boolean equals(Object obj
) {
115 if (obj
instanceof FileRevisionTypedElement
) {
116 FileRevisionTypedElement other
= (FileRevisionTypedElement
) obj
;
117 return other
.getFileRevision().equals(getFileRevision());
125 public String
getAuthor() {
127 author
= fileRevision
.getAuthor();
135 public void setAuthor(String author
) {
136 this.author
= author
;
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() {