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