1 11 package org.eclipse.team.internal.ui.history; 12 13 import java.net.URI ; 14 import java.util.Date ; 15 16 import org.eclipse.compare.ITypedElement; 17 import org.eclipse.core.resources.IStorage; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.team.core.history.IFileRevision; 20 import org.eclipse.team.internal.ui.StorageTypedElement; 21 import org.eclipse.ui.IEditorInput; 22 23 import com.ibm.icu.text.DateFormat; 24 25 29 public class FileRevisionTypedElement extends StorageTypedElement { 30 31 private IFileRevision fileRevision; 32 private String author; 33 34 38 public FileRevisionTypedElement(IFileRevision fileRevision){ 39 this(fileRevision, null); 40 } 41 42 47 public FileRevisionTypedElement(IFileRevision fileRevision, String localEncoding){ 48 super(localEncoding); 49 Assert.isNotNull(fileRevision); 50 this.fileRevision = fileRevision; 51 } 52 53 56 public String getName() { 57 return fileRevision.getName(); 58 } 59 60 63 protected IStorage fetchContents(IProgressMonitor monitor) throws CoreException { 64 return fileRevision.getStorage(monitor); 65 66 } 67 68 72 public String getContentIdentifier() { 73 return fileRevision.getContentIdentifier(); 74 } 75 76 80 public String getTimestamp() { 81 long date = fileRevision.getTimestamp(); 82 Date dateFromLong = new Date (date); 83 return DateFormat.getDateTimeInstance().format(dateFromLong); 84 } 85 86 90 public IFileRevision getFileRevision(){ 91 return fileRevision; 92 } 93 94 98 public String getPath() { 99 URI uri = fileRevision.getURI(); 100 if (uri != null) 101 return uri.getPath(); 102 return getName(); 103 } 104 105 108 public IEditorInput getDocumentKey(Object element) { 109 if (element == this && getBufferedStorage() != null) { 110 return new FileRevisionEditorInput(fileRevision, getBufferedStorage(), getLocalEncoding()); 111 } 112 return null; 113 } 114 115 118 public int hashCode() { 119 return fileRevision.hashCode(); 120 } 121 122 public boolean equals(Object obj) { 123 if (obj == this) 124 return true; 125 if (obj instanceof FileRevisionTypedElement) { 126 FileRevisionTypedElement other = (FileRevisionTypedElement) obj; 127 return other.getFileRevision().equals(getFileRevision()); 128 } 129 return false; 130 } 131 132 public String getAuthor() { 133 if (author == null) 134 author = fileRevision.getAuthor(); 135 return author; 136 } 137 138 public void setAuthor(String author) { 139 this.author = author; 140 } 141 142 public void fetchAuthor(IProgressMonitor monitor) throws CoreException { 143 if (getAuthor() == null && fileRevision.isPropertyMissing()) { 144 IFileRevision other = fileRevision.withAllProperties(monitor); 145 author = other.getAuthor(); 146 } 147 } 148 149 public IFileRevision getRevision() { 150 return fileRevision; 151 } 152 153 } 154 | Popular Tags |