1 11 package org.eclipse.team.internal.core.history; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IFileState; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.team.core.TeamException; 20 import org.eclipse.team.core.history.IFileRevision; 21 import org.eclipse.team.core.history.provider.FileHistory; 22 import org.eclipse.team.internal.core.Messages; 23 24 public class LocalFileHistory extends FileHistory { 25 26 protected IFile file; 27 protected IFileRevision[] revisions; 29 private final boolean includeCurrent; 30 31 34 public LocalFileHistory(IFile file, boolean includeCurrent) { 35 this.file = file; 36 this.includeCurrent = includeCurrent; 37 } 38 39 42 public IFileRevision[] getContributors(IFileRevision revision) { 43 44 IFileRevision[] revisions = getFileRevisions(); 45 46 IFileRevision fileRevision = null; 49 for (int i = 0; i < revisions.length; i++) { 50 if (((LocalFileRevision) revisions[i]).isPredecessorOf(revision)) { 51 if (fileRevision == null) 53 fileRevision = revisions[i]; 54 if (fileRevision != null && revisions[i].getTimestamp() > fileRevision.getTimestamp()) { 57 fileRevision = revisions[i]; 58 } 59 } 60 } 61 if (fileRevision == null) 62 return new IFileRevision[0]; 63 return new IFileRevision[] {fileRevision}; 64 } 65 66 69 public IFileRevision getFileRevision(String id) { 70 if (revisions != null) { 71 for (int i = 0; i < revisions.length; i++) { 72 IFileRevision revision = revisions[i]; 73 if (revision.getContentIdentifier().equals(id)) { 74 return revision; 75 } 76 } 77 } 78 return null; 79 } 80 81 84 public IFileRevision[] getFileRevisions() { 85 if (revisions == null) 86 return new IFileRevision[0]; 87 return revisions; 88 } 89 90 93 public IFileRevision[] getTargets(IFileRevision revision) { 94 IFileRevision[] revisions = getFileRevisions(); 95 ArrayList directDescendents = new ArrayList (); 96 97 for (int i = 0; i < revisions.length; i++) { 98 if (((LocalFileRevision) revisions[i]).isDescendentOf(revision)) { 99 directDescendents.add(revisions[i]); 100 } 101 } 102 return (IFileRevision[]) directDescendents.toArray(new IFileRevision[directDescendents.size()]); 103 } 104 105 111 public void refresh(IProgressMonitor monitor) throws TeamException { 112 monitor.beginTask(Messages.LocalFileHistory_RefreshLocalHistory, 300); 113 try { 114 LocalFileRevision currentRevision = 116 (includeRevisionForFile() ? new LocalFileRevision(file) : null); 117 IFileState[] fileStates = file.getHistory(monitor); 118 int numRevisions = fileStates.length + (currentRevision != null ? 1 : 0); 119 revisions = new LocalFileRevision[numRevisions]; 120 for (int i = 0; i < fileStates.length; i++) { 121 revisions[i] = new LocalFileRevision(fileStates[i]); 122 } 123 if (currentRevision != null) 124 revisions[fileStates.length] = currentRevision; 125 } catch (CoreException e) { 126 throw TeamException.asTeamException(e); 127 } finally { 128 monitor.done(); 129 } 130 } 131 132 private boolean includeRevisionForFile() { 133 return file.exists() && includeCurrent; 134 } 135 136 } 137 | Popular Tags |