129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 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.Revision;
|
|
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.RevisionInformation; // packageimport
|
|
21
|
|
22
|
129
|
23 import dwt.dwthelper.utils;
|
|
24
|
|
25 import java.util.ArrayList;
|
|
26 import java.util.Collections;
|
|
27 import java.util.Date;
|
|
28 import java.util.Iterator;
|
|
29 import java.util.List;
|
|
30
|
|
31 import dwt.graphics.RGB;
|
|
32 import dwtx.jface.internal.text.revisions.ChangeRegion;
|
|
33 import dwtx.jface.internal.text.revisions.Hunk;
|
|
34 import dwtx.jface.text.IInformationControlCreator;
|
|
35 import dwtx.jface.text.source.ILineRange;
|
|
36
|
|
37 /**
|
|
38 * Describes a revision of a document. A revision consists of one ore more {@link ILineRange}s.
|
|
39 * <p>
|
|
40 * Clients may subclass.
|
|
41 * </p>
|
|
42 *
|
|
43 * @since 3.2
|
|
44 */
|
|
45 public abstract class Revision {
|
|
46 /** The original list of change regions, element type: {@link ChangeRegion}. */
|
|
47 private final List fChangeRegions= new ArrayList();
|
|
48 /**
|
|
49 * The cached list of adjusted ranges, element type: {@link RevisionRange}. <code>null</code>
|
|
50 * if the list must be re-computed. Unmodifiable.
|
|
51 *
|
|
52 * @since 3.3
|
|
53 */
|
|
54 private List fRanges= null;
|
|
55
|
|
56 /**
|
|
57 * Creates a new revision.
|
|
58 */
|
|
59 protected Revision() {
|
|
60 }
|
|
61
|
|
62 /**
|
|
63 * Adds a line range to this revision. The range must be non-empty and have a legal start line
|
|
64 * (not -1).
|
|
65 *
|
|
66 * @param range a line range that was changed with this revision
|
|
67 * @throws IndexOutOfBoundsException if the line range is empty or has a negative start line
|
|
68 */
|
|
69 public final void addRange(ILineRange range) throws IndexOutOfBoundsException {
|
|
70 fChangeRegions.add(new ChangeRegion(this, range));
|
|
71 }
|
|
72
|
|
73 /**
|
|
74 * Returns the contained {@link RevisionRange}s adapted to the current diff state. The returned
|
|
75 * information is only valid at the moment it is returned, and may change as the annotated
|
|
76 * document is modified.
|
|
77 *
|
|
78 * @return an unmodifiable view of the contained ranges (element type: {@link RevisionRange})
|
|
79 */
|
|
80 public final List getRegions() {
|
|
81 if (fRanges is null) {
|
|
82 List ranges= new ArrayList(fChangeRegions.size());
|
|
83 for (Iterator it= fChangeRegions.iterator(); it.hasNext();) {
|
|
84 ChangeRegion region= (ChangeRegion) it.next();
|
|
85 for (Iterator inner= region.getAdjustedRanges().iterator(); inner.hasNext();) {
|
|
86 ILineRange range= (ILineRange) inner.next();
|
|
87 ranges.add(new RevisionRange(this, range));
|
|
88 }
|
|
89 }
|
|
90 fRanges= Collections.unmodifiableList(ranges);
|
|
91 }
|
|
92 return fRanges;
|
|
93 }
|
|
94
|
|
95 /**
|
|
96 * Adjusts the revision information to the given diff information. Any previous diff information
|
|
97 * is discarded.
|
|
98 *
|
|
99 * @param hunks the diff hunks to adjust the revision information to
|
|
100 * @since 3.3
|
|
101 */
|
|
102 final void applyDiff(Hunk[] hunks) {
|
|
103 fRanges= null; // mark for recomputation
|
|
104 for (Iterator regions= fChangeRegions.iterator(); regions.hasNext();) {
|
|
105 ChangeRegion region= (ChangeRegion) regions.next();
|
|
106 region.clearDiff();
|
|
107 for (int i= 0; i < hunks.length; i++) {
|
|
108 Hunk hunk= hunks[i];
|
|
109 region.adjustTo(hunk);
|
|
110 }
|
|
111 }
|
|
112 }
|
|
113
|
|
114 /**
|
|
115 * Returns the hover information that will be shown when the user hovers over the a change
|
|
116 * region of this revision.
|
|
117 * <p>
|
|
118 * <strong>Note:</strong> The hover information control which is used to display the information
|
|
119 * must be able process the given object. If the default information control creator is used
|
|
120 * the supported format is simple text, full HTML or an HTML fragment.
|
|
121 * </p>
|
|
122 *
|
|
123 * @return the hover information for this revision or <code>null</code> for no hover
|
|
124 * @see RevisionInformation#setHoverControlCreator(IInformationControlCreator)
|
|
125 */
|
|
126 public abstract Object getHoverInfo();
|
|
127
|
|
128 /**
|
|
129 * Returns the author color for this revision. This color can be used to visually distinguish
|
|
130 * one revision from another, for example as background color.
|
|
131 * <p>
|
|
132 * Revisions from the same author must return the same color and revisions from different authors
|
|
133 * must return distinct colors.</p>
|
|
134 *
|
|
135 * @return the RGB color for this revision's author
|
|
136 */
|
|
137 public abstract RGB getColor();
|
|
138
|
|
139 /**
|
|
140 * Returns the unique (within the document) id of this revision. This may be the version string
|
|
141 * or a different identifier.
|
|
142 *
|
|
143 * @return the id of this revision
|
|
144 */
|
|
145 public abstract String getId();
|
|
146
|
|
147 /**
|
|
148 * Returns the modification date of this revision.
|
|
149 *
|
|
150 * @return the modification date of this revision
|
|
151 */
|
|
152 public abstract Date getDate();
|
|
153
|
|
154 /*
|
|
155 * @see java.lang.Object#toString()
|
|
156 */
|
|
157 public String toString() {
|
|
158 return "Revision " + getId(); //$NON-NLS-1$
|
|
159 }
|
|
160
|
|
161 /**
|
|
162 * Returns the display string for the author of this revision.
|
|
163 * <p>
|
|
164 * Subclasses should replace - the default implementation returns the empty string.
|
|
165 * </p>
|
|
166 *
|
|
167 * @return the author name
|
|
168 * @since 3.3
|
|
169 */
|
|
170 public String getAuthor() {
|
|
171 return ""; //$NON-NLS-1$
|
|
172 }
|
|
173 }
|