Revision fa70a2ef
Added by Katja Luther about 7 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/LineAnnotationModel.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
40 | 40 |
* @version 1.0 |
41 | 41 |
*/ |
42 | 42 |
public class LineAnnotationModel extends AnnotationModel { |
43 |
|
|
43 |
|
|
44 | 44 |
private Comparator<Annotation> comparator; |
45 | 45 |
private IEntityCreator<?> entityCreator; |
46 | 46 |
private Set<LineAnnotation> deletedAnnotations = new HashSet<LineAnnotation>(); |
47 | 47 |
|
48 | 48 |
private ILineDisplayStrategy lineDisplayStrategy; |
49 |
|
|
49 |
|
|
50 | 50 |
/** |
51 | 51 |
* <p>Constructor for LineAnnotationModel.</p> |
52 | 52 |
* |
... | ... | |
56 | 56 |
super(); |
57 | 57 |
this.lineDisplayStrategy = lineDisplayStrategy; |
58 | 58 |
} |
59 |
|
|
59 |
|
|
60 | 60 |
/** |
61 | 61 |
* Changes the annotation's type and fires model changed |
62 | 62 |
* notification. Resulting redraw will cause any change |
... | ... | |
69 | 69 |
annotation.setType(type); |
70 | 70 |
fireModelChanged(new AnnotationModelEvent(this)); |
71 | 71 |
} |
72 |
|
|
72 |
|
|
73 | 73 |
/* (non-Javadoc) |
74 | 74 |
* @see org.eclipse.jface.text.source.AnnotationModel#removeAnnotation(org.eclipse.jface.text.source.Annotation, boolean) |
75 | 75 |
*/ |
76 | 76 |
/** {@inheritDoc} */ |
77 |
protected void removeAnnotation(Annotation annotation, |
|
77 |
@Override |
|
78 |
protected void removeAnnotation(Annotation annotation, |
|
78 | 79 |
boolean fireModelChanged) { |
79 |
// Set data model element for deletion |
|
80 |
annotation.markDeleted(true); |
|
81 | 80 |
if (annotation instanceof LineAnnotation) { |
82 | 81 |
deletedAnnotations.add((LineAnnotation) annotation); |
83 | 82 |
} |
84 | 83 |
super.removeAnnotation(annotation, fireModelChanged); |
85 | 84 |
} |
86 |
|
|
85 |
|
|
87 | 86 |
/** |
88 | 87 |
* <p>removeTypeFromAllAnnotations</p> |
89 | 88 |
* |
... | ... | |
98 | 97 |
} |
99 | 98 |
} |
100 | 99 |
} |
101 |
|
|
100 |
|
|
102 | 101 |
/** |
103 | 102 |
* <p>getAllAnnotationsOfType</p> |
104 | 103 |
* |
... | ... | |
113 | 112 |
if (annotation.getType().equals(type)) { |
114 | 113 |
candidates.add(annotation); |
115 | 114 |
} |
116 |
}
|
|
117 |
return candidates;
|
|
118 |
}
|
|
119 |
|
|
115 |
} |
|
116 |
return candidates; |
|
117 |
} |
|
118 |
|
|
120 | 119 |
/** |
121 | 120 |
* <p>getFirstAnnotationOfType</p> |
122 | 121 |
* |
... | ... | |
130 | 129 |
if (annotation.getType().equals(type)) { |
131 | 130 |
return annotation; |
132 | 131 |
} |
133 |
}
|
|
132 |
} |
|
134 | 133 |
return null; |
135 | 134 |
} |
136 |
|
|
135 |
|
|
137 | 136 |
/** |
138 | 137 |
* Gets first LineAnnotation in line |
139 | 138 |
* |
... | ... | |
146 | 145 |
try { |
147 | 146 |
int offset = document.getLineOffset(line); |
148 | 147 |
int length = document.getLineLength(line); |
149 |
|
|
148 |
|
|
150 | 149 |
Iterator<?> iterator = getAnnotationIterator(offset, length, true, true); |
151 | 150 |
while (iterator.hasNext()) { |
152 | 151 |
Object next = iterator.next(); |
... | ... | |
160 | 159 |
} |
161 | 160 |
return null; |
162 | 161 |
} |
163 |
|
|
162 |
|
|
164 | 163 |
/** |
165 | 164 |
* <p>getOrderedAnnotations</p> |
166 | 165 |
* |
... | ... | |
175 | 174 |
Collections.sort(list, getAnnotationComparator()); |
176 | 175 |
return list; |
177 | 176 |
} |
178 |
|
|
177 |
|
|
179 | 178 |
/** |
180 | 179 |
* <p>printAnnotations</p> |
181 | 180 |
*/ |
... | ... | |
185 | 184 |
logger.debug("Active annotations"); |
186 | 185 |
logger.debug("------------------------"); |
187 | 186 |
List<Annotation> list = getOrderedAnnotations(); |
188 |
|
|
187 |
|
|
189 | 188 |
for (Annotation annotation : list) { |
190 | 189 |
logger.debug( |
191 | 190 |
(annotation.isMarkedDeleted() ? "DELETED " : "") + |
... | ... | |
193 | 192 |
(((LineAnnotation) annotation).isDirty() ? "DIRTY " : "") + |
194 | 193 |
(((LineAnnotation) annotation).isMarkedAsNew() ? "NEW " : "") + |
195 | 194 |
annotation.getText() + ": o " + |
196 |
getPosition(annotation).getOffset() + ", l " +
|
|
195 |
getPosition(annotation).getOffset() + ", l " + |
|
197 | 196 |
getPosition(annotation).getLength()); |
198 | 197 |
} |
199 | 198 |
logger.debug("------------------------"); |
... | ... | |
202 | 201 |
for (LineAnnotation annotation : deletedAnnotations) { |
203 | 202 |
logger.debug( |
204 | 203 |
(annotation.isMarkedDeleted() ? "DELETED " : "") + |
205 |
(((LineAnnotation) annotation).isMarkedAsMerged() ? "MERGED " : "") +
|
|
206 |
(((LineAnnotation) annotation).isDirty() ? "DIRTY " : "") +
|
|
207 |
(((LineAnnotation) annotation).isMarkedAsNew() ? "NEW " : "") +
|
|
208 |
annotation.getText() + ": o ");
|
|
204 |
(annotation.isMarkedAsMerged() ? "MERGED " : "") +
|
|
205 |
(annotation.isDirty() ? "DIRTY " : "") +
|
|
206 |
(annotation.isMarkedAsNew() ? "NEW " : "") +
|
|
207 |
annotation.getText() + ": o "); |
|
209 | 208 |
} |
210 | 209 |
} |
211 |
|
|
210 |
|
|
212 | 211 |
/** |
213 | 212 |
* <p>getUndeletedAnnotations</p> |
214 | 213 |
* |
... | ... | |
217 | 216 |
* @return a {@link java.util.List} object. |
218 | 217 |
*/ |
219 | 218 |
public List<LineAnnotation> getUndeletedAnnotations(int offset, int length) { |
220 |
|
|
219 |
|
|
221 | 220 |
List<LineAnnotation> list = new ArrayList<LineAnnotation>(); |
222 |
|
|
221 |
|
|
223 | 222 |
Iterator<?> iterator = getAnnotationIterator(offset, length, true, true); |
224 | 223 |
while (iterator.hasNext()) { |
225 | 224 |
Object next = iterator.next(); |
226 | 225 |
if (next instanceof LineAnnotation && !((Annotation) next).isMarkedDeleted()) { |
227 |
list.add((LineAnnotation) next);
|
|
226 |
list.add((LineAnnotation) next); |
|
228 | 227 |
} |
229 | 228 |
} |
230 | 229 |
Collections.sort(list, getAnnotationComparator()); |
231 | 230 |
return list; |
232 | 231 |
} |
233 |
|
|
232 |
|
|
234 | 233 |
/** |
235 | 234 |
* <p>Getter for the field <code>deletedAnnotations</code>.</p> |
236 | 235 |
* |
... | ... | |
239 | 238 |
public Set<LineAnnotation> getDeletedAnnotations() { |
240 | 239 |
return deletedAnnotations; |
241 | 240 |
} |
242 |
|
|
241 |
|
|
243 | 242 |
/** |
244 | 243 |
* <p>clearDeletedAnnotations</p> |
245 | 244 |
*/ |
246 | 245 |
public void clearDeletedAnnotations() { |
247 | 246 |
deletedAnnotations.clear(); |
248 | 247 |
} |
249 |
|
|
248 |
|
|
250 | 249 |
private Comparator<Annotation> getAnnotationComparator() { |
251 | 250 |
if (comparator == null) { |
252 | 251 |
this.comparator = new AnnotationComparator(); |
253 | 252 |
} |
254 | 253 |
return comparator; |
255 | 254 |
} |
256 |
|
|
255 |
|
|
257 | 256 |
class AnnotationComparator implements Comparator<Annotation> { |
258 | 257 |
|
259 | 258 |
/* (non-Javadoc) |
260 | 259 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
261 | 260 |
*/ |
262 |
public int compare(Annotation annotation1, Annotation annotation2) { |
|
261 |
@Override |
|
262 |
public int compare(Annotation annotation1, Annotation annotation2) { |
|
263 | 263 |
if (annotation1.isMarkedDeleted() && !annotation2.isMarkedDeleted()) { |
264 | 264 |
return 1; |
265 | 265 |
} |
... | ... | |
277 | 277 |
} else { |
278 | 278 |
return 0; |
279 | 279 |
} |
280 |
}
|
|
280 |
} |
|
281 | 281 |
} |
282 |
|
|
282 |
|
|
283 | 283 |
/** |
284 | 284 |
* The annotation model is assigned responsibility for creating new containers |
285 | 285 |
* from blocks of text. |
... | ... | |
289 | 289 |
public void setEntityCreator(IEntityCreator<?> entityCreator) { |
290 | 290 |
this.entityCreator = entityCreator; |
291 | 291 |
} |
292 |
|
|
292 |
|
|
293 | 293 |
/** |
294 | 294 |
* Creates an annotation without adding it to the model. |
295 | 295 |
* |
... | ... | |
318 | 318 |
annotation.markAsNew(true); |
319 | 319 |
return annotation; |
320 | 320 |
} |
321 |
|
|
321 |
|
|
322 | 322 |
/* (non-Javadoc) |
323 | 323 |
* @see org.eclipse.jface.text.source.AnnotationModel#addAnnotation(org.eclipse.jface.text.source.Annotation, org.eclipse.jface.text.Position) |
324 | 324 |
*/ |
... | ... | |
327 | 327 |
public void addAnnotation(Annotation annotation, Position position) { |
328 | 328 |
super.addAnnotation(annotation, position); |
329 | 329 |
} |
330 |
|
|
330 |
|
|
331 | 331 |
/** |
332 | 332 |
* <p>getAnnotation</p> |
333 | 333 |
* |
Also available in: Unified diff
fix #6376: remove markAsDelete for merged items in bulk editor