129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2008 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 v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.revisions.RevisionInformation;
|
|
14
|
131
|
15 import dwtx.jface.text.revisions.IRevisionListener; // packageimport
|
|
16 import dwtx.jface.text.revisions.IRevisionRulerColumnExtension; // packageimport
|
|
17 import dwtx.jface.text.revisions.RevisionRange; // packageimport
|
|
18 import dwtx.jface.text.revisions.IRevisionRulerColumn; // packageimport
|
|
19 import dwtx.jface.text.revisions.RevisionEvent; // packageimport
|
|
20 import dwtx.jface.text.revisions.Revision; // packageimport
|
|
21
|
|
22
|
129
|
23 import dwt.dwthelper.utils;
|
|
24
|
|
25 import java.util.ArrayList;
|
|
26 import java.util.Collections;
|
|
27 import java.util.Comparator;
|
|
28 import java.util.Iterator;
|
|
29 import java.util.List;
|
|
30
|
|
31 import dwtx.core.runtime.Assert;
|
|
32 import dwtx.jface.internal.text.revisions.Hunk;
|
|
33 import dwtx.jface.text.IInformationControlCreator;
|
|
34 import dwtx.jface.text.ITextHoverExtension;
|
|
35 import dwtx.jface.text.information.IInformationProviderExtension2;
|
|
36
|
|
37 /**
|
|
38 * Encapsulates revision information for one line-based document.
|
|
39 * <p>
|
|
40 * Clients may instantiate.
|
|
41 * </p>
|
|
42 *
|
|
43 * @since 3.2
|
|
44 * @see Revision
|
|
45 */
|
|
46 public final class RevisionInformation : ITextHoverExtension, IInformationProviderExtension2 {
|
|
47 /** The revisions, element type: {@link Revision}. */
|
|
48 private final List fRevisions= new ArrayList();
|
|
49 /** A unmodifiable view of <code>fRevisions</code>. */
|
|
50 private final List fRORevisions= Collections.unmodifiableList(fRevisions);
|
|
51 /**
|
|
52 * The flattened list of {@link RevisionRange}s, unmodifiable. <code>null</code> if the list
|
|
53 * must be re-computed.
|
|
54 *
|
|
55 * @since 3.3
|
|
56 */
|
|
57 private List fRanges= null;
|
|
58
|
|
59 /**
|
|
60 * The hover control creator. Can be <code>null</code>.
|
|
61 *
|
|
62 * @since 3.3
|
|
63 */
|
|
64 private IInformationControlCreator fHoverControlCreator;
|
|
65
|
|
66 /**
|
|
67 * The information presenter control creator. Can be <code>null</code>.
|
|
68 *
|
|
69 * @since 3.3
|
|
70 */
|
|
71 private IInformationControlCreator fInformationPresenterControlCreator;
|
|
72
|
|
73 /**
|
|
74 * Creates a new revision information model.
|
|
75 */
|
|
76 public RevisionInformation() {
|
|
77 }
|
|
78
|
|
79 /**
|
|
80 * Adds a revision.
|
|
81 *
|
|
82 * @param revision a revision
|
|
83 */
|
|
84 public void addRevision(Revision revision) {
|
|
85 Assert.isLegal(revision !is null);
|
|
86 fRevisions.add(revision);
|
|
87 }
|
|
88
|
|
89 /**
|
|
90 * Returns the contained revisions.
|
|
91 *
|
|
92 * @return an unmodifiable view of the contained revisions (element type: {@link Revision})
|
|
93 */
|
|
94 public List getRevisions() {
|
|
95 return fRORevisions;
|
|
96 }
|
|
97
|
|
98 /**
|
|
99 * Returns the line ranges of this revision information. The returned information is only valid
|
|
100 * at the moment it is returned, and may change as the annotated document is modified. See
|
|
101 * {@link IRevisionListener} for a way to be informed when the revision information changes. The
|
|
102 * returned list is sorted by document offset.
|
|
103 *
|
|
104 * @return an unmodifiable view of the line ranges (element type: {@link RevisionRange})
|
|
105 * @see IRevisionListener
|
|
106 * @since 3.3
|
|
107 */
|
|
108 public List getRanges() {
|
|
109 if (fRanges is null) {
|
|
110 List ranges= new ArrayList(fRevisions.size() * 2); // wild size guess
|
|
111 for (Iterator it= fRevisions.iterator(); it.hasNext();) {
|
|
112 Revision revision= (Revision) it.next();
|
|
113 ranges.addAll(revision.getRegions());
|
|
114 }
|
|
115
|
|
116 // sort by start line
|
|
117 Collections.sort(ranges, new Comparator() {
|
|
118 public int compare(Object o1, Object o2) {
|
|
119 RevisionRange r1= (RevisionRange) o1;
|
|
120 RevisionRange r2= (RevisionRange) o2;
|
|
121
|
|
122 return r1.getStartLine() - r2.getStartLine();
|
|
123 }
|
|
124 });
|
|
125
|
|
126 fRanges= Collections.unmodifiableList(ranges);
|
|
127 }
|
|
128 return fRanges;
|
|
129 }
|
|
130
|
|
131 /**
|
|
132 * Adjusts the revision information to the given diff information. Any previous diff information is discarded. <strong>Note</strong>: This is an internal framework method and must not be called by clients.
|
|
133 *
|
|
134 * @param hunks the diff hunks to adjust the revision information to
|
|
135 * @since 3.3
|
|
136 * @noreference This method is not intended to be referenced by clients.
|
|
137 */
|
|
138 public void applyDiff(Hunk[] hunks) {
|
|
139 fRanges= null; // mark for recomputation
|
|
140 for (Iterator revisions= getRevisions().iterator(); revisions.hasNext();)
|
|
141 ((Revision) revisions.next()).applyDiff(hunks);
|
|
142 }
|
|
143
|
|
144 /*
|
|
145 * @see dwtx.jface.text.ITextHoverExtension#getHoverControlCreator()
|
|
146 * @since 3.3
|
|
147 */
|
|
148 public IInformationControlCreator getHoverControlCreator() {
|
|
149 return fHoverControlCreator;
|
|
150 }
|
|
151
|
|
152 /**
|
|
153 * {@inheritDoc}
|
|
154 * @return the information control creator or <code>null</code>
|
|
155 * @since 3.3
|
|
156 */
|
|
157 public IInformationControlCreator getInformationPresenterControlCreator() {
|
|
158 return fInformationPresenterControlCreator;
|
|
159 }
|
|
160
|
|
161 /**
|
|
162 * Sets the hover control creator.
|
|
163 * <p>
|
|
164 * <strong>Note:</strong> The created information control must be able to display the object
|
|
165 * returned by the concrete implementation of {@link Revision#getHoverInfo()}.
|
|
166 * </p>
|
|
167 *
|
|
168 * @param creator the control creator
|
|
169 * @since 3.3
|
|
170 */
|
|
171 public void setHoverControlCreator(IInformationControlCreator creator) {
|
|
172 fHoverControlCreator= creator;
|
|
173 }
|
|
174
|
|
175 /**
|
|
176 * Sets the information presenter control creator.
|
|
177 *
|
|
178 * @param creator the control creator
|
|
179 * @since 3.3
|
|
180 */
|
|
181 public void setInformationPresenterControlCreator(IInformationControlCreator creator) {
|
|
182 fInformationPresenterControlCreator= creator;
|
|
183 }
|
|
184 }
|