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.source.projection.ProjectionAnnotationModel;
|
|
14
|
131
|
15 import dwtx.jface.text.source.projection.ProjectionViewer; // packageimport
|
|
16 import dwtx.jface.text.source.projection.ProjectionSupport; // packageimport
|
|
17 import dwtx.jface.text.source.projection.IProjectionPosition; // packageimport
|
|
18 import dwtx.jface.text.source.projection.AnnotationBag; // packageimport
|
|
19 import dwtx.jface.text.source.projection.ProjectionSummary; // packageimport
|
|
20 import dwtx.jface.text.source.projection.ProjectionAnnotationHover; // packageimport
|
|
21 import dwtx.jface.text.source.projection.ProjectionRulerColumn; // packageimport
|
|
22 import dwtx.jface.text.source.projection.SourceViewerInformationControl; // packageimport
|
|
23 import dwtx.jface.text.source.projection.IProjectionListener; // packageimport
|
|
24 import dwtx.jface.text.source.projection.ProjectionAnnotation; // packageimport
|
|
25
|
|
26
|
129
|
27 import dwt.dwthelper.utils;
|
|
28
|
|
29 import java.util.Iterator;
|
|
30 import java.util.Map;
|
|
31
|
|
32 import dwtx.jface.text.BadLocationException;
|
|
33 import dwtx.jface.text.Position;
|
|
34 import dwtx.jface.text.source.Annotation;
|
|
35 import dwtx.jface.text.source.AnnotationModel;
|
|
36
|
|
37
|
|
38 /**
|
|
39 * A projection annotation model. It provides methods for modifying the
|
|
40 * expansion state of the managed projection annotations.
|
|
41 * <p>
|
|
42 * Do not subclass. Use it as is.
|
|
43 * </p>
|
|
44 *
|
|
45 * @since 3.0
|
|
46 * @noextend This class is not intended to be subclassed by clients.
|
|
47 */
|
|
48 public class ProjectionAnnotationModel : AnnotationModel {
|
|
49
|
|
50
|
|
51 /**
|
|
52 * Creates a new, empty projection annotation model.
|
|
53 */
|
|
54 public ProjectionAnnotationModel() {
|
|
55 }
|
|
56
|
|
57 /**
|
|
58 * Changes the state of the given annotation to collapsed. An appropriate
|
|
59 * annotation model change event is sent out.
|
|
60 *
|
|
61 * @param annotation the annotation
|
|
62 */
|
|
63 public void collapse(Annotation annotation) {
|
|
64 if (annotation instanceof ProjectionAnnotation) {
|
|
65 ProjectionAnnotation projection= (ProjectionAnnotation) annotation;
|
|
66 if (!projection.isCollapsed()) {
|
|
67 projection.markCollapsed();
|
|
68 modifyAnnotation(projection, true);
|
|
69 }
|
|
70 }
|
|
71 }
|
|
72
|
|
73 /**
|
|
74 * Changes the state of the given annotation to expanded. An appropriate
|
|
75 * annotation model change event is sent out.
|
|
76 *
|
|
77 * @param annotation the annotation
|
|
78 */
|
|
79 public void expand(Annotation annotation) {
|
|
80 if (annotation instanceof ProjectionAnnotation) {
|
|
81 ProjectionAnnotation projection= (ProjectionAnnotation) annotation;
|
|
82 if (projection.isCollapsed()) {
|
|
83 projection.markExpanded();
|
|
84 modifyAnnotation(projection, true);
|
|
85 }
|
|
86 }
|
|
87 }
|
|
88
|
|
89 /**
|
|
90 * Toggles the expansion state of the given annotation. An appropriate
|
|
91 * annotation model change event is sent out.
|
|
92 *
|
|
93 * @param annotation the annotation
|
|
94 */
|
|
95 public void toggleExpansionState(Annotation annotation) {
|
|
96 if (annotation instanceof ProjectionAnnotation) {
|
|
97 ProjectionAnnotation projection= (ProjectionAnnotation) annotation;
|
|
98
|
|
99 if (projection.isCollapsed())
|
|
100 projection.markExpanded();
|
|
101 else
|
|
102 projection.markCollapsed();
|
|
103
|
|
104 modifyAnnotation(projection, true);
|
|
105 }
|
|
106 }
|
|
107
|
|
108 /**
|
|
109 * Expands all annotations that overlap with the given range and are collapsed.
|
|
110 *
|
|
111 * @param offset the range offset
|
|
112 * @param length the range length
|
|
113 * @return <code>true</code> if any annotation has been expanded, <code>false</code> otherwise
|
|
114 */
|
|
115 public bool expandAll(int offset, int length) {
|
|
116 return expandAll(offset, length, true);
|
|
117 }
|
|
118
|
|
119 /**
|
|
120 * Collapses all annotations that overlap with the given range and are collapsed.
|
|
121 *
|
|
122 * @param offset the range offset
|
|
123 * @param length the range length
|
|
124 * @return <code>true</code> if any annotation has been collapse, <code>false</code>
|
|
125 * otherwise
|
|
126 * @since 3.2
|
|
127 */
|
|
128 public bool collapseAll(int offset, int length) {
|
|
129
|
|
130 bool collapsing= false;
|
|
131
|
|
132 Iterator iterator= getAnnotationIterator();
|
|
133 while (iterator.hasNext()) {
|
|
134 ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next();
|
|
135 if (!annotation.isCollapsed()) {
|
|
136 Position position= getPosition(annotation);
|
|
137 if (position !is null && position.overlapsWith(offset, length) /* || is a delete at the boundary */ ) {
|
|
138 annotation.markCollapsed();
|
|
139 modifyAnnotation(annotation, false);
|
|
140 collapsing= true;
|
|
141 }
|
|
142 }
|
|
143 }
|
|
144
|
|
145 if (collapsing)
|
|
146 fireModelChanged();
|
|
147
|
|
148 return collapsing;
|
|
149 }
|
|
150
|
|
151 /**
|
|
152 * Expands all annotations that overlap with the given range and are collapsed. Fires a model change event if
|
|
153 * requested.
|
|
154 *
|
|
155 * @param offset the offset of the range
|
|
156 * @param length the length of the range
|
|
157 * @param fireModelChanged <code>true</code> if a model change event
|
|
158 * should be fired, <code>false</code> otherwise
|
|
159 * @return <code>true</code> if any annotation has been expanded, <code>false</code> otherwise
|
|
160 */
|
|
161 protected bool expandAll(int offset, int length, bool fireModelChanged) {
|
|
162
|
|
163 bool expanding= false;
|
|
164
|
|
165 Iterator iterator= getAnnotationIterator();
|
|
166 while (iterator.hasNext()) {
|
|
167 ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next();
|
|
168 if (annotation.isCollapsed()) {
|
|
169 Position position= getPosition(annotation);
|
|
170 if (position !is null && position.overlapsWith(offset, length) /* || is a delete at the boundary */ ) {
|
|
171 annotation.markExpanded();
|
|
172 modifyAnnotation(annotation, false);
|
|
173 expanding= true;
|
|
174 }
|
|
175 }
|
|
176 }
|
|
177
|
|
178 if (expanding && fireModelChanged)
|
|
179 fireModelChanged();
|
|
180
|
|
181 return expanding;
|
|
182 }
|
|
183
|
|
184 /**
|
|
185 * Modifies the annotation model.
|
|
186 *
|
|
187 * @param deletions the list of deleted annotations
|
|
188 * @param additions the set of annotations to add together with their associated position
|
|
189 * @param modifications the list of modified annotations
|
|
190 */
|
|
191 public void modifyAnnotations(Annotation[] deletions, Map additions, Annotation[] modifications) {
|
|
192 try {
|
|
193 replaceAnnotations(deletions, additions, false);
|
|
194 if (modifications !is null) {
|
|
195 for (int i= 0; i < modifications.length; i++)
|
|
196 modifyAnnotation(modifications[i], false);
|
|
197 }
|
|
198 } catch (BadLocationException x) {
|
|
199 }
|
|
200 fireModelChanged();
|
|
201 }
|
|
202 }
|