1 11 package org.eclipse.jface.text.revisions; 12 13 import java.util.ArrayList ; 14 import java.util.Collections ; 15 import java.util.Comparator ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 import org.eclipse.core.runtime.Assert; 20 21 import org.eclipse.jface.internal.text.revisions.Hunk; 22 23 import org.eclipse.jface.text.IInformationControlCreator; 24 import org.eclipse.jface.text.ITextHoverExtension; 25 import org.eclipse.jface.text.information.IInformationProviderExtension2; 26 27 36 public final class RevisionInformation implements ITextHoverExtension, IInformationProviderExtension2 { 37 38 private final List fRevisions= new ArrayList (); 39 40 private final List fRORevisions= Collections.unmodifiableList(fRevisions); 41 47 private List fRanges= null; 48 49 54 private IInformationControlCreator fHoverControlCreator; 55 56 61 private IInformationControlCreator fInformationPresenterControlCreator; 62 63 66 public RevisionInformation() { 67 } 68 69 74 public void addRevision(Revision revision) { 75 Assert.isLegal(revision != null); 76 fRevisions.add(revision); 77 } 78 79 84 public List getRevisions() { 85 return fRORevisions; 86 } 87 88 98 public List getRanges() { 99 if (fRanges == null) { 100 List ranges= new ArrayList (fRevisions.size() * 2); for (Iterator it= fRevisions.iterator(); it.hasNext();) { 102 Revision revision= (Revision) it.next(); 103 ranges.addAll(revision.getRegions()); 104 } 105 106 Collections.sort(ranges, new Comparator () { 108 public int compare(Object o1, Object o2) { 109 RevisionRange r1= (RevisionRange) o1; 110 RevisionRange r2= (RevisionRange) o2; 111 112 return r1.getStartLine() - r2.getStartLine(); 113 } 114 }); 115 116 fRanges= Collections.unmodifiableList(ranges); 117 } 118 return fRanges; 119 } 120 121 129 public void applyDiff(Hunk[] hunks) { 130 fRanges= null; for (Iterator revisions= getRevisions().iterator(); revisions.hasNext();) 132 ((Revision) revisions.next()).applyDiff(hunks); 133 } 134 135 139 public IInformationControlCreator getHoverControlCreator() { 140 return fHoverControlCreator; 141 } 142 143 148 public IInformationControlCreator getInformationPresenterControlCreator() { 149 return fInformationPresenterControlCreator; 150 } 151 152 158 public void setHoverControlCreator(IInformationControlCreator creator) { 159 fHoverControlCreator= creator; 160 } 161 162 168 public void setInformationPresenterControlCreator(IInformationControlCreator creator) { 169 fInformationPresenterControlCreator= creator; 170 } 171 } 172 | Popular Tags |