Mercurial > projects > dwt-addons
annotate dwtx/jface/text/revisions/RevisionInformation.d @ 153:f70d9508c95c
Fix java Collection imports
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 25 Aug 2008 00:27:31 +0200 |
parents | 75302ef3f92f |
children | 25f1f92fa3df |
rev | line source |
---|---|
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 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
146
diff
changeset
|
25 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
146
diff
changeset
|
26 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
146
diff
changeset
|
27 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
146
diff
changeset
|
28 |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
146
diff
changeset
|
29 |
129 | 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}. */ | |
146 | 48 private const List fRevisions= new ArrayList(); |
129 | 49 /** A unmodifiable view of <code>fRevisions</code>. */ |
146 | 50 private const List fRORevisions= Collections.unmodifiableList(fRevisions); |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
76 public this() { |
129 | 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();) { | |
134 | 112 Revision revision= cast(Revision) it.next(); |
129 | 113 ranges.addAll(revision.getRegions()); |
114 } | |
115 | |
116 // sort by start line | |
135 | 117 Collections.sort(ranges, new class() Comparator { |
129 | 118 public int compare(Object o1, Object o2) { |
134 | 119 RevisionRange r1= cast(RevisionRange) o1; |
120 RevisionRange r2= cast(RevisionRange) o2; | |
129 | 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();) | |
134 | 141 (cast(Revision) revisions.next()).applyDiff(hunks); |
129 | 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 } |