1 11 package org.eclipse.team.internal.core.history; 12 13 import java.net.URI ; 14 15 import org.eclipse.core.filesystem.URIUtil; 16 import org.eclipse.core.resources.*; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.team.core.history.IFileRevision; 21 import org.eclipse.team.core.history.ITag; 22 import org.eclipse.team.core.history.provider.FileRevision; 23 import org.eclipse.team.internal.core.Messages; 24 25 30 public class LocalFileRevision extends FileRevision { 31 35 private IFileState state; 37 38 private IFile file; 40 private IFileRevision baseRevision; 42 43 46 public LocalFileRevision(IFileState state) { 47 this.state = state; 48 this.file = null; 49 this.baseRevision = null; 50 } 51 52 59 public LocalFileRevision(IFile file) { 60 this.file = file; 61 this.baseRevision = null; 62 this.state = null; 63 } 64 65 68 public String getContentIdentifier() { 69 if (file != null) 70 return baseRevision == null ? NLS.bind(Messages.LocalFileRevision_currentVersion, "") : NLS.bind(Messages.LocalFileRevision_currentVersion, baseRevision.getContentIdentifier()); return ""; } 73 74 77 public String getAuthor() { 78 return ""; } 80 81 84 public String getComment() { 85 if (file != null) 86 return Messages.LocalFileRevision_currentVersionTag; 87 return null; 88 } 89 90 93 public ITag[] getTags() { 94 return new ITag[0]; 95 } 96 97 100 public IStorage getStorage(IProgressMonitor monitor) throws CoreException { 101 if (file != null) { 102 return file; 103 } 104 return state; 105 } 106 107 110 public String getName() { 111 if (file != null) { 112 return file.getName(); 113 } 114 115 return state.getName(); 116 } 117 118 121 public long getTimestamp() { 122 if (file != null) { 123 return file.getLocalTimeStamp(); 124 } 125 126 return state.getModificationTime(); 127 } 128 129 134 public boolean exists() { 135 if (file != null) { 136 return file.exists(); 137 } 138 139 return state.exists(); 140 } 141 142 146 public void setBaseRevision(IFileRevision baseRevision) { 147 this.baseRevision = baseRevision; 148 } 149 150 public boolean isPropertyMissing() { 151 return true; 152 } 153 154 155 public IFileRevision withAllProperties(IProgressMonitor monitor) { 156 return this; 157 } 158 159 public boolean isPredecessorOf(IFileRevision revision) { 160 long compareRevisionTime = revision.getTimestamp(); 161 return (this.getTimestamp() < compareRevisionTime); 162 } 163 164 public boolean isDescendentOf(IFileRevision revision) { 165 long compareRevisionTime = revision.getTimestamp(); 166 return (this.getTimestamp() > compareRevisionTime); 167 } 168 169 public URI getURI() { 170 if (file != null) 171 return file.getLocationURI(); 172 173 return URIUtil.toURI(state.getFullPath()); 174 } 175 176 public IFile getFile() { 177 return file; 178 } 179 180 public IFileState getState() { 181 return state; 182 } 183 184 public boolean isCurrentState() { 185 return file != null; 186 } 187 188 public boolean equals(Object obj) { 189 if (obj == this) 190 return true; 191 if (obj instanceof LocalFileRevision) { 192 LocalFileRevision other = (LocalFileRevision) obj; 193 if (file != null && other.file != null) 194 return file.equals(other.file); 195 if (state != null && other.state != null) 196 return statesEqual(state, other.state); 197 } 198 return false; 199 } 200 201 private boolean statesEqual(IFileState s1, IFileState s2) { 202 return (s1.getFullPath().equals(s2.getFullPath()) && s1.getModificationTime() == s2.getModificationTime()); 203 } 204 205 public int hashCode() { 206 if (file != null) 207 return file.hashCode(); 208 if (state != null) 209 return (int)state.getModificationTime(); 210 return super.hashCode(); 211 } 212 } 213 | Popular Tags |