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
|
131
|
14
|
|
15 import dwtx.jface.text.presentation.IPresentationDamager; // packageimport
|
|
16 import dwtx.jface.text.presentation.IPresentationReconciler; // packageimport
|
|
17 import dwtx.jface.text.presentation.IPresentationRepairer; // packageimport
|
|
18 import dwtx.jface.text.presentation.IPresentationReconcilerExtension; // packageimport
|
|
19
|
129
|
20 module dwtx.jface.text.presentation.PresentationReconciler;
|
|
21
|
|
22 import dwt.dwthelper.utils;
|
|
23
|
|
24 import java.util.HashMap;
|
|
25 import java.util.Iterator;
|
|
26 import java.util.Map;
|
|
27
|
|
28 import dwt.custom.StyleRange;
|
|
29 import dwtx.core.runtime.Assert;
|
|
30 import dwtx.jface.text.BadLocationException;
|
|
31 import dwtx.jface.text.BadPositionCategoryException;
|
|
32 import dwtx.jface.text.DefaultPositionUpdater;
|
|
33 import dwtx.jface.text.DocumentEvent;
|
|
34 import dwtx.jface.text.DocumentPartitioningChangedEvent;
|
|
35 import dwtx.jface.text.IDocument;
|
|
36 import dwtx.jface.text.IDocumentExtension3;
|
|
37 import dwtx.jface.text.IDocumentListener;
|
|
38 import dwtx.jface.text.IDocumentPartitioningListener;
|
|
39 import dwtx.jface.text.IDocumentPartitioningListenerExtension;
|
|
40 import dwtx.jface.text.IDocumentPartitioningListenerExtension2;
|
|
41 import dwtx.jface.text.IPositionUpdater;
|
|
42 import dwtx.jface.text.IRegion;
|
|
43 import dwtx.jface.text.ITextInputListener;
|
|
44 import dwtx.jface.text.ITextListener;
|
|
45 import dwtx.jface.text.ITextViewer;
|
|
46 import dwtx.jface.text.ITextViewerExtension5;
|
|
47 import dwtx.jface.text.ITypedRegion;
|
|
48 import dwtx.jface.text.Region;
|
|
49 import dwtx.jface.text.TextEvent;
|
|
50 import dwtx.jface.text.TextPresentation;
|
|
51 import dwtx.jface.text.TextUtilities;
|
|
52 import dwtx.jface.text.TypedPosition;
|
|
53
|
|
54
|
|
55
|
|
56 /**
|
|
57 * Standard implementation of <code>IPresentationReconciler</code>. This
|
|
58 * implementation assumes that the tasks performed by its presentation damagers
|
|
59 * and repairers are lightweight and of low cost. This presentation reconciler
|
|
60 * runs in the UI thread and always repairs the complete damage caused by a
|
|
61 * document change rather than just the portion overlapping with the viewer's
|
|
62 * viewport.
|
|
63 * <p>
|
|
64 * Usually, clients instantiate this class and configure it before using it.
|
|
65 * </p>
|
|
66 */
|
|
67 public class PresentationReconciler : IPresentationReconciler, IPresentationReconcilerExtension {
|
|
68
|
|
69 /** Prefix of the name of the position category for tracking damage regions. */
|
|
70 protected final static String TRACKED_PARTITION= "__reconciler_tracked_partition"; //$NON-NLS-1$
|
|
71
|
|
72
|
|
73 /**
|
|
74 * Internal listener class.
|
|
75 */
|
|
76 class InternalListener :
|
|
77 ITextInputListener, IDocumentListener, ITextListener,
|
|
78 IDocumentPartitioningListener, IDocumentPartitioningListenerExtension, IDocumentPartitioningListenerExtension2 {
|
|
79
|
|
80 /** Set to <code>true</code> if between a document about to be changed and a changed event. */
|
|
81 private bool fDocumentChanging= false;
|
|
82 /**
|
|
83 * The cached redraw state of the text viewer.
|
|
84 * @since 3.0
|
|
85 */
|
|
86 private bool fCachedRedrawState= true;
|
|
87
|
|
88 /*
|
|
89 * @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument, IDocument)
|
|
90 */
|
|
91 public void inputDocumentAboutToBeChanged(IDocument oldDocument, IDocument newDocument) {
|
|
92 if (oldDocument !is null) {
|
|
93 try {
|
|
94
|
|
95 fViewer.removeTextListener(this);
|
|
96 oldDocument.removeDocumentListener(this);
|
|
97 oldDocument.removeDocumentPartitioningListener(this);
|
|
98
|
|
99 oldDocument.removePositionUpdater(fPositionUpdater);
|
|
100 oldDocument.removePositionCategory(fPositionCategory);
|
|
101
|
|
102 } catch (BadPositionCategoryException x) {
|
|
103 // should not happened for former input documents;
|
|
104 }
|
|
105 }
|
|
106 }
|
|
107
|
|
108 /*
|
|
109 * @see ITextInputListener#inputDocumenChanged(IDocument, IDocument)
|
|
110 */
|
|
111 public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) {
|
|
112
|
|
113 fDocumentChanging= false;
|
|
114 fCachedRedrawState= true;
|
|
115
|
|
116 if (newDocument !is null) {
|
|
117
|
|
118 newDocument.addPositionCategory(fPositionCategory);
|
|
119 newDocument.addPositionUpdater(fPositionUpdater);
|
|
120
|
|
121 newDocument.addDocumentPartitioningListener(this);
|
|
122 newDocument.addDocumentListener(this);
|
|
123 fViewer.addTextListener(this);
|
|
124
|
|
125 setDocumentToDamagers(newDocument);
|
|
126 setDocumentToRepairers(newDocument);
|
|
127 processDamage(new Region(0, newDocument.getLength()), newDocument);
|
|
128 }
|
|
129 }
|
|
130
|
|
131 /*
|
|
132 * @see IDocumentPartitioningListener#documentPartitioningChanged(IDocument)
|
|
133 */
|
|
134 public void documentPartitioningChanged(IDocument document) {
|
|
135 if (!fDocumentChanging && fCachedRedrawState)
|
|
136 processDamage(new Region(0, document.getLength()), document);
|
|
137 else
|
|
138 fDocumentPartitioningChanged= true;
|
|
139 }
|
|
140
|
|
141 /*
|
|
142 * @see IDocumentPartitioningListenerExtension#documentPartitioningChanged(IDocument, IRegion)
|
|
143 * @since 2.0
|
|
144 */
|
|
145 public void documentPartitioningChanged(IDocument document, IRegion changedRegion) {
|
|
146 if (!fDocumentChanging && fCachedRedrawState) {
|
|
147 processDamage(new Region(changedRegion.getOffset(), changedRegion.getLength()), document);
|
|
148 } else {
|
|
149 fDocumentPartitioningChanged= true;
|
|
150 fChangedDocumentPartitions= changedRegion;
|
|
151 }
|
|
152 }
|
|
153
|
|
154 /*
|
|
155 * @see dwtx.jface.text.IDocumentPartitioningListenerExtension2#documentPartitioningChanged(dwtx.jface.text.DocumentPartitioningChangedEvent)
|
|
156 * @since 3.0
|
|
157 */
|
|
158 public void documentPartitioningChanged(DocumentPartitioningChangedEvent event) {
|
|
159 IRegion changedRegion= event.getChangedRegion(getDocumentPartitioning());
|
|
160 if (changedRegion !is null)
|
|
161 documentPartitioningChanged(event.getDocument(), changedRegion);
|
|
162 }
|
|
163
|
|
164 /*
|
|
165 * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
|
|
166 */
|
|
167 public void documentAboutToBeChanged(DocumentEvent e) {
|
|
168
|
|
169 fDocumentChanging= true;
|
|
170 if (fCachedRedrawState) {
|
|
171 try {
|
|
172 int offset= e.getOffset() + e.getLength();
|
|
173 ITypedRegion region= getPartition(e.getDocument(), offset);
|
|
174 fRememberedPosition= new TypedPosition(region);
|
|
175 e.getDocument().addPosition(fPositionCategory, fRememberedPosition);
|
|
176 } catch (BadLocationException x) {
|
|
177 // can not happen
|
|
178 } catch (BadPositionCategoryException x) {
|
|
179 // should not happen on input elements
|
|
180 }
|
|
181 }
|
|
182 }
|
|
183
|
|
184 /*
|
|
185 * @see IDocumentListener#documentChanged(DocumentEvent)
|
|
186 */
|
|
187 public void documentChanged(DocumentEvent e) {
|
|
188 if (fCachedRedrawState) {
|
|
189 try {
|
|
190 e.getDocument().removePosition(fPositionCategory, fRememberedPosition);
|
|
191 } catch (BadPositionCategoryException x) {
|
|
192 // can not happen on input documents
|
|
193 }
|
|
194 }
|
|
195 fDocumentChanging= false;
|
|
196 }
|
|
197
|
|
198 /*
|
|
199 * @see ITextListener#textChanged(TextEvent)
|
|
200 */
|
|
201 public void textChanged(TextEvent e) {
|
|
202
|
|
203 fCachedRedrawState= e.getViewerRedrawState();
|
|
204 if (!fCachedRedrawState)
|
|
205 return;
|
|
206
|
|
207 IRegion damage= null;
|
|
208 IDocument document= null;
|
|
209
|
|
210 if (e.getDocumentEvent() is null) {
|
|
211 document= fViewer.getDocument();
|
|
212 if (document !is null) {
|
|
213 if (e.getOffset() is 0 && e.getLength() is 0 && e.getText() is null) {
|
|
214 // redraw state change, damage the whole document
|
|
215 damage= new Region(0, document.getLength());
|
|
216 } else {
|
|
217 IRegion region= widgetRegion2ModelRegion(e);
|
|
218 try {
|
|
219 String text= document.get(region.getOffset(), region.getLength());
|
|
220 DocumentEvent de= new DocumentEvent(document, region.getOffset(), region.getLength(), text);
|
|
221 damage= getDamage(de, false);
|
|
222 } catch (BadLocationException x) {
|
|
223 }
|
|
224 }
|
|
225 }
|
|
226 } else {
|
|
227 DocumentEvent de= e.getDocumentEvent();
|
|
228 document= de.getDocument();
|
|
229 damage= getDamage(de, true);
|
|
230 }
|
|
231
|
|
232 if (damage !is null && document !is null)
|
|
233 processDamage(damage, document);
|
|
234
|
|
235 fDocumentPartitioningChanged= false;
|
|
236 fChangedDocumentPartitions= null;
|
|
237 }
|
|
238
|
|
239 /**
|
|
240 * Translates the given text event into the corresponding range of the viewer's document.
|
|
241 *
|
|
242 * @param e the text event
|
|
243 * @return the widget region corresponding the region of the given event
|
|
244 * @since 2.1
|
|
245 */
|
|
246 protected IRegion widgetRegion2ModelRegion(TextEvent e) {
|
|
247
|
|
248 String text= e.getText();
|
|
249 int length= text is null ? 0 : text.length();
|
|
250
|
|
251 if (fViewer instanceof ITextViewerExtension5) {
|
|
252 ITextViewerExtension5 extension= (ITextViewerExtension5) fViewer;
|
|
253 return extension.widgetRange2ModelRange(new Region(e.getOffset(), length));
|
|
254 }
|
|
255
|
|
256 IRegion visible= fViewer.getVisibleRegion();
|
|
257 IRegion region= new Region(e.getOffset() + visible.getOffset(), length);
|
|
258 return region;
|
|
259 }
|
|
260 }
|
|
261
|
|
262 /** The map of presentation damagers. */
|
|
263 private Map fDamagers;
|
|
264 /** The map of presentation repairers. */
|
|
265 private Map fRepairers;
|
|
266 /** The target viewer. */
|
|
267 private ITextViewer fViewer;
|
|
268 /** The internal listener. */
|
|
269 private InternalListener fInternalListener= new InternalListener();
|
|
270 /** The name of the position category to track damage regions. */
|
|
271 private String fPositionCategory;
|
|
272 /** The position updated for the damage regions' position category. */
|
|
273 private IPositionUpdater fPositionUpdater;
|
|
274 /** The positions representing the damage regions. */
|
|
275 private TypedPosition fRememberedPosition;
|
|
276 /** Flag indicating the receipt of a partitioning changed notification. */
|
|
277 private bool fDocumentPartitioningChanged= false;
|
|
278 /** The range covering the changed partitioning. */
|
|
279 private IRegion fChangedDocumentPartitions= null;
|
|
280 /**
|
|
281 * The partitioning used by this presentation reconciler.
|
|
282 * @since 3.0
|
|
283 */
|
|
284 private String fPartitioning;
|
|
285
|
|
286 /**
|
|
287 * Creates a new presentation reconciler. There are no damagers or repairers
|
|
288 * registered with this reconciler by default. The default partitioning
|
|
289 * <code>IDocumentExtension3.DEFAULT_PARTITIONING</code> is used.
|
|
290 */
|
|
291 public PresentationReconciler() {
|
|
292 super();
|
|
293 fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING;
|
|
294 fPositionCategory= TRACKED_PARTITION + hashCode();
|
|
295 fPositionUpdater= new DefaultPositionUpdater(fPositionCategory);
|
|
296 }
|
|
297
|
|
298 /**
|
|
299 * Sets the document partitioning for this presentation reconciler.
|
|
300 *
|
|
301 * @param partitioning the document partitioning for this presentation reconciler.
|
|
302 * @since 3.0
|
|
303 */
|
|
304 public void setDocumentPartitioning(String partitioning) {
|
|
305 Assert.isNotNull(partitioning);
|
|
306 fPartitioning= partitioning;
|
|
307 }
|
|
308
|
|
309 /*
|
|
310 * @see dwtx.jface.text.presentation.IPresentationReconcilerExtension#geDocumenttPartitioning()
|
|
311 * @since 3.0
|
|
312 */
|
|
313 public String getDocumentPartitioning() {
|
|
314 return fPartitioning;
|
|
315 }
|
|
316
|
|
317 /**
|
|
318 * Registers the given presentation damager for a particular content type.
|
|
319 * If there is already a damager registered for this type, the old damager
|
|
320 * is removed first.
|
|
321 *
|
|
322 * @param damager the presentation damager to register, or <code>null</code> to remove an existing one
|
|
323 * @param contentType the content type under which to register
|
|
324 */
|
|
325 public void setDamager(IPresentationDamager damager, String contentType) {
|
|
326
|
|
327 Assert.isNotNull(contentType);
|
|
328
|
|
329 if (fDamagers is null)
|
|
330 fDamagers= new HashMap();
|
|
331
|
|
332 if (damager is null)
|
|
333 fDamagers.remove(contentType);
|
|
334 else
|
|
335 fDamagers.put(contentType, damager);
|
|
336 }
|
|
337
|
|
338 /**
|
|
339 * Registers the given presentation repairer for a particular content type.
|
|
340 * If there is already a repairer registered for this type, the old repairer
|
|
341 * is removed first.
|
|
342 *
|
|
343 * @param repairer the presentation repairer to register, or <code>null</code> to remove an existing one
|
|
344 * @param contentType the content type under which to register
|
|
345 */
|
|
346 public void setRepairer(IPresentationRepairer repairer, String contentType) {
|
|
347
|
|
348 Assert.isNotNull(contentType);
|
|
349
|
|
350 if (fRepairers is null)
|
|
351 fRepairers= new HashMap();
|
|
352
|
|
353 if (repairer is null)
|
|
354 fRepairers.remove(contentType);
|
|
355 else
|
|
356 fRepairers.put(contentType, repairer);
|
|
357 }
|
|
358
|
|
359 /*
|
|
360 * @see IPresentationReconciler#install(ITextViewer)
|
|
361 */
|
|
362 public void install(ITextViewer viewer) {
|
|
363 Assert.isNotNull(viewer);
|
|
364
|
|
365 fViewer= viewer;
|
|
366 fViewer.addTextInputListener(fInternalListener);
|
|
367
|
|
368 IDocument document= viewer.getDocument();
|
|
369 if (document !is null)
|
|
370 fInternalListener.inputDocumentChanged(null, document);
|
|
371 }
|
|
372
|
|
373 /*
|
|
374 * @see IPresentationReconciler#uninstall()
|
|
375 */
|
|
376 public void uninstall() {
|
|
377 fViewer.removeTextInputListener(fInternalListener);
|
|
378
|
|
379 // Ensure we uninstall all listeners
|
|
380 fInternalListener.inputDocumentAboutToBeChanged(fViewer.getDocument(), null);
|
|
381 }
|
|
382
|
|
383 /*
|
|
384 * @see IPresentationReconciler#getDamager(String)
|
|
385 */
|
|
386 public IPresentationDamager getDamager(String contentType) {
|
|
387
|
|
388 if (fDamagers is null)
|
|
389 return null;
|
|
390
|
|
391 return (IPresentationDamager) fDamagers.get(contentType);
|
|
392 }
|
|
393
|
|
394 /*
|
|
395 * @see IPresentationReconciler#getRepairer(String)
|
|
396 */
|
|
397 public IPresentationRepairer getRepairer(String contentType) {
|
|
398
|
|
399 if (fRepairers is null)
|
|
400 return null;
|
|
401
|
|
402 return (IPresentationRepairer) fRepairers.get(contentType);
|
|
403 }
|
|
404
|
|
405 /**
|
|
406 * Informs all registered damagers about the document on which they will work.
|
|
407 *
|
|
408 * @param document the document on which to work
|
|
409 */
|
|
410 protected void setDocumentToDamagers(IDocument document) {
|
|
411 if (fDamagers !is null) {
|
|
412 Iterator e= fDamagers.values().iterator();
|
|
413 while (e.hasNext()) {
|
|
414 IPresentationDamager damager= (IPresentationDamager) e.next();
|
|
415 damager.setDocument(document);
|
|
416 }
|
|
417 }
|
|
418 }
|
|
419
|
|
420 /**
|
|
421 * Informs all registered repairers about the document on which they will work.
|
|
422 *
|
|
423 * @param document the document on which to work
|
|
424 */
|
|
425 protected void setDocumentToRepairers(IDocument document) {
|
|
426 if (fRepairers !is null) {
|
|
427 Iterator e= fRepairers.values().iterator();
|
|
428 while (e.hasNext()) {
|
|
429 IPresentationRepairer repairer= (IPresentationRepairer) e.next();
|
|
430 repairer.setDocument(document);
|
|
431 }
|
|
432 }
|
|
433 }
|
|
434
|
|
435 /**
|
|
436 * Constructs a "repair description" for the given damage and returns this
|
|
437 * description as a text presentation. For this, it queries the partitioning
|
|
438 * of the damage region and asks the appropriate presentation repairer for
|
|
439 * each partition to construct the "repair description" for this partition.
|
|
440 *
|
|
441 * @param damage the damage to be repaired
|
|
442 * @param document the document whose presentation must be repaired
|
|
443 * @return the presentation repair description as text presentation or
|
|
444 * <code>null</code> if the partitioning could not be computed
|
|
445 */
|
|
446 protected TextPresentation createPresentation(IRegion damage, IDocument document) {
|
|
447 try {
|
|
448 if (fRepairers is null || fRepairers.isEmpty()) {
|
|
449 TextPresentation presentation= new TextPresentation(damage, 100);
|
|
450 presentation.setDefaultStyleRange(new StyleRange(damage.getOffset(), damage.getLength(), null, null));
|
|
451 return presentation;
|
|
452 }
|
|
453
|
|
454 TextPresentation presentation= new TextPresentation(damage, 1000);
|
|
455
|
|
456 ITypedRegion[] partitioning= TextUtilities.computePartitioning(document, getDocumentPartitioning(), damage.getOffset(), damage.getLength(), false);
|
|
457 for (int i= 0; i < partitioning.length; i++) {
|
|
458 ITypedRegion r= partitioning[i];
|
|
459 IPresentationRepairer repairer= getRepairer(r.getType());
|
|
460 if (repairer !is null)
|
|
461 repairer.createPresentation(presentation, r);
|
|
462 }
|
|
463
|
|
464 return presentation;
|
|
465
|
|
466 } catch (BadLocationException x) {
|
|
467 return null;
|
|
468 }
|
|
469 }
|
|
470
|
|
471
|
|
472 /**
|
|
473 * Checks for the first and the last affected partition affected by a
|
|
474 * document event and calls their damagers. Invalidates everything from the
|
|
475 * start of the damage for the first partition until the end of the damage
|
|
476 * for the last partition.
|
|
477 *
|
|
478 * @param e the event describing the document change
|
|
479 * @param optimize <code>true</code> if partition changes should be
|
|
480 * considered for optimization
|
|
481 * @return the damaged caused by the change or <code>null</code> if
|
|
482 * computing the partitioning failed
|
|
483 * @since 3.0
|
|
484 */
|
|
485 private IRegion getDamage(DocumentEvent e, bool optimize) {
|
|
486 int length= e.getText() is null ? 0 : e.getText().length();
|
|
487
|
|
488 if (fDamagers is null || fDamagers.isEmpty()) {
|
|
489 length= Math.max(e.getLength(), length);
|
|
490 length= Math.min(e.getDocument().getLength() - e.getOffset(), length);
|
|
491 return new Region(e.getOffset(), length);
|
|
492 }
|
|
493
|
|
494 bool isDeletion= length is 0;
|
|
495 IRegion damage= null;
|
|
496 try {
|
|
497 int offset= e.getOffset();
|
|
498 if (isDeletion)
|
|
499 offset= Math.max(0, offset - 1);
|
|
500 ITypedRegion partition= getPartition(e.getDocument(), offset);
|
|
501 IPresentationDamager damager= getDamager(partition.getType());
|
|
502 if (damager is null)
|
|
503 return null;
|
|
504
|
|
505 IRegion r= damager.getDamageRegion(partition, e, fDocumentPartitioningChanged);
|
|
506
|
|
507 if (!fDocumentPartitioningChanged && optimize && !isDeletion) {
|
|
508 damage= r;
|
|
509 } else {
|
|
510
|
|
511 int damageEnd= getDamageEndOffset(e);
|
|
512
|
|
513 int parititionDamageEnd= -1;
|
|
514 if (fChangedDocumentPartitions !is null)
|
|
515 parititionDamageEnd= fChangedDocumentPartitions.getOffset() + fChangedDocumentPartitions.getLength();
|
|
516
|
|
517 int end= Math.max(damageEnd, parititionDamageEnd);
|
|
518
|
|
519 damage= end is -1 ? r : new Region(r.getOffset(), end - r.getOffset());
|
|
520 }
|
|
521
|
|
522 } catch (BadLocationException x) {
|
|
523 }
|
|
524
|
|
525 return damage;
|
|
526 }
|
|
527
|
|
528 /**
|
|
529 * Returns the end offset of the damage. If a partition has been split by
|
|
530 * the given document event also the second half of the original
|
|
531 * partition must be considered. This is achieved by using the remembered
|
|
532 * partition range.
|
|
533 *
|
|
534 * @param e the event describing the change
|
|
535 * @return the damage end offset (excluding)
|
|
536 * @exception BadLocationException if method accesses invalid offset
|
|
537 */
|
|
538 private int getDamageEndOffset(DocumentEvent e) throws BadLocationException {
|
|
539
|
|
540 IDocument d= e.getDocument();
|
|
541
|
|
542 int length= 0;
|
|
543 if (e.getText() !is null) {
|
|
544 length= e.getText().length();
|
|
545 if (length > 0)
|
|
546 -- length;
|
|
547 }
|
|
548
|
|
549 ITypedRegion partition= getPartition(d, e.getOffset() + length);
|
|
550 int endOffset= partition.getOffset() + partition.getLength();
|
|
551 if (endOffset is e.getOffset())
|
|
552 return -1;
|
|
553
|
|
554 int end= fRememberedPosition is null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength();
|
|
555 if (endOffset < end && end < d.getLength())
|
|
556 partition= getPartition(d, end);
|
|
557
|
|
558 IPresentationDamager damager= getDamager(partition.getType());
|
|
559 if (damager is null)
|
|
560 return -1;
|
|
561
|
|
562 IRegion r= damager.getDamageRegion(partition, e, fDocumentPartitioningChanged);
|
|
563
|
|
564 return r.getOffset() + r.getLength();
|
|
565 }
|
|
566
|
|
567 /**
|
|
568 * Processes the given damage.
|
|
569 * @param damage the damage to be repaired
|
|
570 * @param document the document whose presentation must be repaired
|
|
571 */
|
|
572 private void processDamage(IRegion damage, IDocument document) {
|
|
573 if (damage !is null && damage.getLength() > 0) {
|
|
574 TextPresentation p= createPresentation(damage, document);
|
|
575 if (p !is null)
|
|
576 applyTextRegionCollection(p);
|
|
577 }
|
|
578 }
|
|
579
|
|
580 /**
|
|
581 * Applies the given text presentation to the text viewer the presentation
|
|
582 * reconciler is installed on.
|
|
583 *
|
|
584 * @param presentation the text presentation to be applied to the text viewer
|
|
585 */
|
|
586 private void applyTextRegionCollection(TextPresentation presentation) {
|
|
587 fViewer.changeTextPresentation(presentation, false);
|
|
588 }
|
|
589
|
|
590 /**
|
|
591 * Returns the partition for the given offset in the given document.
|
|
592 *
|
|
593 * @param document the document
|
|
594 * @param offset the offset
|
|
595 * @return the partition
|
|
596 * @throws BadLocationException if offset is invalid in the given document
|
|
597 * @since 3.0
|
|
598 */
|
|
599 private ITypedRegion getPartition(IDocument document, int offset) throws BadLocationException {
|
|
600 return TextUtilities.getPartition(document, getDocumentPartitioning(), offset, false);
|
|
601 }
|
|
602 }
|