KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > source > AnnotationModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  *******************************************************************************/

11 package org.eclipse.jface.text.source;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.NoSuchElementException JavaDoc;
19
20 import org.eclipse.core.runtime.Assert;
21
22 import org.eclipse.jface.text.BadLocationException;
23 import org.eclipse.jface.text.DocumentEvent;
24 import org.eclipse.jface.text.IDocument;
25 import org.eclipse.jface.text.IDocumentListener;
26 import org.eclipse.jface.text.ISynchronizable;
27 import org.eclipse.jface.text.Position;
28
29
30 /**
31  * Standard implementation of {@link IAnnotationModel} and its extension
32  * interfaces. This class can directly be used by clients. Subclasses may adapt
33  * this annotation model to other existing annotation mechanisms. This class
34  * also implements {@link org.eclipse.jface.text.ISynchronizable}. All
35  * modifications of the model's internal annotation map are synchronized using
36  * the model's lock object.
37  */

38 public class AnnotationModel implements IAnnotationModel, IAnnotationModelExtension, ISynchronizable {
39
40     /**
41      * A single iterator builds its behavior based on a sequence of iterators.
42      *
43      * @since 3.1
44      */

45     private static class MetaIterator implements Iterator JavaDoc {
46
47         /** The iterator over a list of iterators. */
48         private Iterator JavaDoc fSuperIterator;
49         /** The current iterator. */
50         private Iterator JavaDoc fCurrent;
51         /** The current element. */
52         private Object JavaDoc fCurrentElement;
53
54
55         public MetaIterator(Iterator JavaDoc iterator) {
56             fSuperIterator= iterator;
57             fCurrent= (Iterator JavaDoc) fSuperIterator.next(); // there is at least one.
58
}
59
60         public void remove() {
61             throw new UnsupportedOperationException JavaDoc();
62         }
63
64         public boolean hasNext() {
65             if (fCurrentElement != null)
66                 return true;
67
68             if (fCurrent.hasNext()) {
69                 fCurrentElement= fCurrent.next();
70                 return true;
71             } else if (fSuperIterator.hasNext()) {
72                 fCurrent= (Iterator JavaDoc) fSuperIterator.next();
73                 return hasNext();
74             } else
75                 return false;
76         }
77
78         public Object JavaDoc next() {
79             if (!hasNext())
80                 throw new NoSuchElementException JavaDoc();
81
82             Object JavaDoc element= fCurrentElement;
83             fCurrentElement= null;
84             return element;
85         }
86     }
87
88     /**
89      * Internal annotation model listener for forwarding annotation model changes from the attached models to the
90      * registered listeners of the outer most annotation model.
91      *
92      * @since 3.0
93      */

94     private class InternalModelListener implements IAnnotationModelListener, IAnnotationModelListenerExtension {
95
96         /*
97          * @see org.eclipse.jface.text.source.IAnnotationModelListener#modelChanged(org.eclipse.jface.text.source.IAnnotationModel)
98          */

99         public void modelChanged(IAnnotationModel model) {
100             AnnotationModel.this.fireModelChanged(new AnnotationModelEvent(model, true));
101         }
102
103         /*
104          * @see org.eclipse.jface.text.source.IAnnotationModelListenerExtension#modelChanged(org.eclipse.jface.text.source.AnnotationModelEvent)
105          */

106         public void modelChanged(AnnotationModelEvent event) {
107             AnnotationModel.this.fireModelChanged(event);
108         }
109     }
110
111     /**
112      * The list of managed annotations
113      * @deprecated since 3.0 use <code>getAnnotationMap</code> instead
114      */

115     protected Map JavaDoc fAnnotations;
116     /** The list of annotation model listeners */
117     protected ArrayList JavaDoc fAnnotationModelListeners;
118     /** The document connected with this model */
119     protected IDocument fDocument;
120     /** The number of open connections to the same document */
121     private int fOpenConnections= 0;
122     /** The document listener for tracking whether document positions might have been changed. */
123     private IDocumentListener fDocumentListener;
124     /** The flag indicating whether the document positions might have been changed. */
125     private boolean fDocumentChanged= true;
126     /**
127      * The model's attachment.
128      * @since 3.0
129      */

130     private Map JavaDoc fAttachments= new HashMap JavaDoc();
131     /**
132      * The annotation model listener on attached sub-models.
133      * @since 3.0
134      */

135     private IAnnotationModelListener fModelListener= new InternalModelListener();
136     /**
137      * The current annotation model event.
138      * @since 3.0
139      */

140     private AnnotationModelEvent fModelEvent;
141     /**
142      * The modification stamp.
143      * @since 3.0
144      */

145     private Object JavaDoc fModificationStamp= new Object JavaDoc();
146
147     /**
148      * Creates a new annotation model. The annotation is empty, i.e. does not
149      * manage any annotations and is not connected to any document.
150      */

151     public AnnotationModel() {
152         fAnnotations= new AnnotationMap(10);
153         fAnnotationModelListeners= new ArrayList JavaDoc(2);
154
155         fDocumentListener= new IDocumentListener() {
156
157             public void documentAboutToBeChanged(DocumentEvent event) {
158             }
159
160             public void documentChanged(DocumentEvent event) {
161                 fDocumentChanged= true;
162             }
163         };
164     }
165
166     /**
167      * Returns the annotation map internally used by this annotation model.
168      *
169      * @return the annotation map internally used by this annotation model
170      * @since 3.0
171      */

172     protected IAnnotationMap getAnnotationMap() {
173         return (IAnnotationMap) fAnnotations;
174     }
175
176     /*
177      * @see org.eclipse.jface.text.ISynchronizable#getLockObject()
178      * @since 3.0
179      */

180     public Object JavaDoc getLockObject() {
181         return getAnnotationMap().getLockObject();
182     }
183
184     /*
185      * @see org.eclipse.jface.text.ISynchronizable#setLockObject(java.lang.Object)
186      * @since 3.0
187      */

188     public void setLockObject(Object JavaDoc lockObject) {
189         getAnnotationMap().setLockObject(lockObject);
190     }
191
192     /**
193      * Returns the current annotation model event. This is the event that will be sent out
194      * when calling <code>fireModelChanged</code>.
195      *
196      * @return the current annotation model event
197      * @since 3.0
198      */

199     protected final AnnotationModelEvent getAnnotationModelEvent() {
200         synchronized (getLockObject()) {
201             if (fModelEvent == null) {
202                 fModelEvent= createAnnotationModelEvent();
203                 fModelEvent.markWorldChange(false);
204                 fModificationStamp= fModelEvent;
205             }
206             return fModelEvent;
207         }
208     }
209
210     /*
211      * @see org.eclipse.jface.text.source.IAnnotationModel#addAnnotation(org.eclipse.jface.text.source.Annotation, org.eclipse.jface.text.Position)
212      */

213     public void addAnnotation(Annotation annotation, Position position) {
214         try {
215             addAnnotation(annotation, position, true);
216         } catch (BadLocationException e) {
217             // ignore invalid position
218
}
219     }
220
221     /*
222      * @see org.eclipse.jface.text.source.IAnnotationModelExtension#replaceAnnotations(org.eclipse.jface.text.source.Annotation[], java.util.Map)
223      * @since 3.0
224      */

225     public void replaceAnnotations(Annotation[] annotationsToRemove, Map JavaDoc annotationsToAdd) {
226         try {
227             replaceAnnotations(annotationsToRemove, annotationsToAdd, true);
228         } catch (BadLocationException x) {
229         }
230     }
231
232     /**
233      * Replaces the given annotations in this model and if advised fires a
234      * model change event.
235      *
236      * @param annotationsToRemove the annotations to be removed
237      * @param annotationsToAdd the annotations to be added
238      * @param fireModelChanged <code>true</code> if a model change event
239      * should be fired, <code>false</code> otherwise
240      * @throws BadLocationException in case an annotation should be added at an
241      * invalid position
242      * @since 3.0
243      */

244     protected void replaceAnnotations(Annotation[] annotationsToRemove, Map JavaDoc annotationsToAdd, boolean fireModelChanged) throws BadLocationException {
245
246         if (annotationsToRemove != null) {
247             for (int i= 0, length= annotationsToRemove.length; i < length; i++)
248                 removeAnnotation(annotationsToRemove[i], false);
249         }
250
251         if (annotationsToAdd != null) {
252             Iterator JavaDoc iter= annotationsToAdd.entrySet().iterator();
253             while (iter.hasNext()) {
254                 Map.Entry JavaDoc mapEntry= (Map.Entry JavaDoc) iter.next();
255                 Annotation annotation= (Annotation) mapEntry.getKey();
256                 Position position= (Position) mapEntry.getValue();
257                 addAnnotation(annotation, position, false);
258             }
259         }
260
261         if (fireModelChanged)
262             fireModelChanged();
263     }
264
265     /**
266      * Adds the given annotation to this model. Associates the
267      * annotation with the given position. If requested, all annotation
268      * model listeners are informed about this model change. If the annotation
269      * is already managed by this model nothing happens.
270      *
271      * @param annotation the annotation to add
272      * @param position the associate position
273      * @param fireModelChanged indicates whether to notify all model listeners
274      * @throws BadLocationException if the position is not a valid document position
275      */

276     protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException {
277         if (!fAnnotations.containsKey(annotation)) {
278
279             addPosition(fDocument, position);
280             fAnnotations.put(annotation, position);
281             synchronized (getLockObject()) {
282                 getAnnotationModelEvent().annotationAdded(annotation);
283             }
284
285             if (fireModelChanged)
286                 fireModelChanged();
287         }
288     }
289
290     /*
291      * @see org.eclipse.jface.text.source.IAnnotationModel#addAnnotationModelListener(org.eclipse.jface.text.source.IAnnotationModelListener)
292      */

293     public void addAnnotationModelListener(IAnnotationModelListener listener) {
294         if (!fAnnotationModelListeners.contains(listener)) {
295             fAnnotationModelListeners.add(listener);
296             if (listener instanceof IAnnotationModelListenerExtension) {
297                 IAnnotationModelListenerExtension extension= (IAnnotationModelListenerExtension) listener;
298                 AnnotationModelEvent event= createAnnotationModelEvent();
299                 event.markSealed();
300                 extension.modelChanged(event);
301             } else
302                 listener.modelChanged(this);
303         }
304     }
305
306     /**
307      * Adds the given position to the default position category of the
308      * given document.
309      *
310      * @param document the document to which to add the position
311      * @param position the position to add
312      * @throws BadLocationException if the position is not a valid document position
313      */

314     protected void addPosition(IDocument document, Position position) throws BadLocationException {
315         if (document != null)
316             document.addPosition(position);
317     }
318
319     /**
320      * Removes the given position from the default position category of the
321      * given document.
322      *
323      * @param document the document to which to add the position
324      * @param position the position to add
325      *
326      * @since 3.0
327      */

328     protected void removePosition(IDocument document, Position position) {
329         if (document != null)
330             document.removePosition(position);
331     }
332
333     /*
334      * @see org.eclipse.jface.text.source.IAnnotationModel#connect(org.eclipse.jface.text.IDocument)
335      */

336     public void connect(IDocument document) {
337         Assert.isTrue(fDocument == null || fDocument == document);
338
339         if (fDocument == null) {
340             fDocument= document;
341             Iterator JavaDoc e= getAnnotationMap().valuesIterator();
342             while (e.hasNext())
343                 try {
344                     addPosition(fDocument, (Position) e.next());
345                 } catch (BadLocationException x) {
346                     // ignore invalid position
347
}
348         }
349
350         ++ fOpenConnections;
351         if (fOpenConnections == 1) {
352             fDocument.addDocumentListener(fDocumentListener);
353             connected();
354         }
355
356         for (Iterator JavaDoc it= fAttachments.keySet().iterator(); it.hasNext();) {
357             IAnnotationModel model= (IAnnotationModel) fAttachments.get(it.next());
358             model.connect(document);
359         }
360     }
361
362     /**
363      * Hook method. Is called as soon as this model becomes connected to a document.
364      * Subclasses may re-implement.
365      */

366     protected void connected() {
367     }
368
369     /**
370      * Hook method. Is called as soon as this model becomes disconnected from its document.
371      * Subclasses may re-implement.
372      */

373     protected void disconnected() {
374     }
375
376     /*
377      * @see org.eclipse.jface.text.source.IAnnotationModel#disconnect(org.eclipse.jface.text.IDocument)
378      */

379     public void disconnect(IDocument document) {
380
381         Assert.isTrue(fDocument == document);
382
383         for (Iterator JavaDoc it= fAttachments.keySet().iterator(); it.hasNext();) {
384             IAnnotationModel model= (IAnnotationModel) fAttachments.get(it.next());
385             model.disconnect(document);
386         }
387
388         -- fOpenConnections;
389         if (fOpenConnections == 0) {
390
391             disconnected();
392             fDocument.removeDocumentListener(fDocumentListener);
393
394             if (fDocument != null) {
395                 Iterator JavaDoc e= getAnnotationMap().valuesIterator();
396                 while (e.hasNext()) {
397                     Position p= (Position) e.next();
398                     removePosition(fDocument, p);
399                 }
400                 fDocument= null;
401             }
402         }
403     }
404
405     /**
406      * Informs all annotation model listeners that this model has been changed.
407      */

408     protected void fireModelChanged() {
409         AnnotationModelEvent modelEvent= null;
410
411         synchronized(getLockObject()) {
412             if (fModelEvent != null) {
413                 modelEvent= fModelEvent;
414                 fModelEvent= null;
415             }
416         }
417
418         if (modelEvent != null)
419             fireModelChanged(modelEvent);
420     }
421
422     /**
423      * Creates and returns a new annotation model event. Subclasses may override.
424      *
425      * @return a new and empty annotation model event
426      * @since 3.0
427      */

428     protected AnnotationModelEvent createAnnotationModelEvent() {
429         return new AnnotationModelEvent(this);
430     }
431
432     /**
433      * Informs all annotation model listeners that this model has been changed
434      * as described in the annotation model event. The event is sent out
435      * to all listeners implementing <code>IAnnotationModelListenerExtension</code>.
436      * All other listeners are notified by just calling <code>modelChanged(IAnnotationModel)</code>.
437      *
438      * @param event the event to be sent out to the listeners
439      * @since 2.0
440      */

441     protected void fireModelChanged(AnnotationModelEvent event) {
442
443         event.markSealed();
444
445         if (event.isEmpty())
446             return;
447
448         ArrayList JavaDoc v= new ArrayList JavaDoc(fAnnotationModelListeners);
449         Iterator JavaDoc e= v.iterator();
450         while (e.hasNext()) {
451             IAnnotationModelListener l= (IAnnotationModelListener) e.next();
452             if (l instanceof IAnnotationModelListenerExtension)
453                 ((IAnnotationModelListenerExtension) l).modelChanged(event);
454             else if (l != null)
455                 l.modelChanged(this);
456         }
457     }
458
459     /**
460      * Removes the given annotations from this model. If requested all
461      * annotation model listeners will be informed about this change.
462      * <code>modelInitiated</code> indicates whether the deletion has
463      * been initiated by this model or by one of its clients.
464      *
465      * @param annotations the annotations to be removed
466      * @param fireModelChanged indicates whether to notify all model listeners
467      * @param modelInitiated indicates whether this changes has been initiated by this model
468      */

469     protected void removeAnnotations(List JavaDoc annotations, boolean fireModelChanged, boolean modelInitiated) {
470         if (annotations.size() > 0) {
471             Iterator JavaDoc e= annotations.iterator();
472             while (e.hasNext())
473                 removeAnnotation((Annotation) e.next(), false);
474
475             if (fireModelChanged)
476                 fireModelChanged();
477         }
478     }
479
480     /**
481      * Removes all annotations from the model whose associated positions have been
482      * deleted. If requested inform all model listeners about the change.
483      *
484      * @param fireModelChanged indicates whether to notify all model listeners
485      */

486     protected void cleanup(boolean fireModelChanged) {
487         cleanup(fireModelChanged, true);
488     }
489
490     /**
491      * Removes all annotations from the model whose associated positions have been
492      * deleted. If requested inform all model listeners about the change. If requested
493      * a new thread is created for the notification of the model listeners.
494      *
495      * @param fireModelChanged indicates whether to notify all model listeners
496      * @param forkNotification <code>true</code> iff notification should be done in a new thread
497      * @since 3.0
498      */

499     private void cleanup(boolean fireModelChanged, boolean forkNotification) {
500         if (fDocumentChanged) {
501             fDocumentChanged= false;
502
503             ArrayList JavaDoc deleted= new ArrayList JavaDoc();
504             Iterator JavaDoc e= getAnnotationMap().keySetIterator();
505             while (e.hasNext()) {
506                 Annotation a= (Annotation) e.next();
507                 Position p= (Position) fAnnotations.get(a);
508                 if (p == null || p.isDeleted())
509                     deleted.add(a);
510             }
511
512             if (fireModelChanged && forkNotification) {
513                 removeAnnotations(deleted, false, false);
514                 synchronized (getLockObject()) {
515                     if (fModelEvent != null)
516                         new Thread JavaDoc() {
517                             public void run() {
518                                 fireModelChanged();
519                             }
520                         }.start();
521                 }
522             } else
523                 removeAnnotations(deleted, fireModelChanged, false);
524         }
525     }
526
527     /*
528      * @see org.eclipse.jface.text.source.IAnnotationModel#getAnnotationIterator()
529      */

530     public Iterator JavaDoc getAnnotationIterator() {
531         return getAnnotationIterator(true, true);
532     }
533
534     /**
535      * Returns all annotations managed by this model. <code>cleanup</code>
536      * indicates whether all annotations whose associated positions are
537      * deleted should previously be removed from the model. <code>recurse</code> indicates
538      * whether annotations of attached sub-models should also be returned.
539      *
540      * @param cleanup indicates whether annotations with deleted associated positions are removed
541      * @param recurse whether to return annotations managed by sub-models.
542      * @return all annotations managed by this model
543      * @since 3.0
544      */

545     private Iterator JavaDoc getAnnotationIterator(boolean cleanup, boolean recurse) {
546
547         if (!recurse || fAttachments.isEmpty())
548             return getAnnotationIterator(cleanup);
549
550         List JavaDoc iterators= new ArrayList JavaDoc(fAttachments.size() + 1);
551         iterators.add(getAnnotationIterator(cleanup));
552         for (Iterator JavaDoc it= fAttachments.keySet().iterator(); it.hasNext();) {
553             iterators.add(((IAnnotationModel) fAttachments.get(it.next())).getAnnotationIterator());
554         }
555
556         return new MetaIterator(iterators.iterator());
557     }
558
559     /**
560      * Returns all annotations managed by this model. <code>cleanup</code>
561      * indicates whether all annotations whose associated positions are
562      * deleted should previously be removed from the model.
563      *
564      * @param cleanup indicates whether annotations with deleted associated positions are removed
565      * @return all annotations managed by this model
566      */

567     protected Iterator JavaDoc getAnnotationIterator(boolean cleanup) {
568         if (cleanup)
569             cleanup(true);
570
571         return getAnnotationMap().keySetIterator();
572     }
573
574     /*
575      * @see org.eclipse.jface.text.source.IAnnotationModel#getPosition(org.eclipse.jface.text.source.Annotation)
576      */

577     public Position getPosition(Annotation annotation) {
578         Position position= (Position) fAnnotations.get(annotation);
579         if (position != null)
580             return position;
581
582         Iterator JavaDoc it= fAttachments.values().iterator();
583         while (position == null && it.hasNext())
584             position= ((IAnnotationModel) it.next()).getPosition(annotation);
585         return position;
586     }
587
588     /*
589      * @see org.eclipse.jface.text.source.IAnnotationModelExtension#removeAllAnnotations()
590      * @since 3.0
591      */

592     public void removeAllAnnotations() {
593         removeAllAnnotations(true);
594     }
595
596     /**
597      * Removes all annotations from the annotation model. If requested
598      * inform all model change listeners about this change.
599      *
600      * @param fireModelChanged indicates whether to notify all model listeners
601      */

602     protected void removeAllAnnotations(boolean fireModelChanged) {
603
604         if (fDocument != null) {
605             Iterator JavaDoc e= getAnnotationMap().keySetIterator();
606             while (e.hasNext()) {
607                 Annotation a= (Annotation) e.next();
608                 Position p= (Position) fAnnotations.get(a);
609                 removePosition(fDocument, p);
610 // p.delete();
611
synchronized (getLockObject()) {
612                     getAnnotationModelEvent().annotationRemoved(a, p);
613                 }
614             }
615         }
616
617         fAnnotations.clear();
618
619         if (fireModelChanged)
620             fireModelChanged();
621     }
622
623     /*
624      * @see org.eclipse.jface.text.source.IAnnotationModel#removeAnnotation(org.eclipse.jface.text.source.Annotation)
625      */

626     public void removeAnnotation(Annotation annotation) {
627         removeAnnotation(annotation, true);
628     }
629
630     /**
631      * Removes the given annotation from the annotation model.
632      * If requested inform all model change listeners about this change.
633      *
634      * @param annotation the annotation to be removed
635      * @param fireModelChanged indicates whether to notify all model listeners
636      */

637     protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) {
638         if (fAnnotations.containsKey(annotation)) {
639
640             Position p= null;
641             if (fDocument != null) {
642                 p= (Position) fAnnotations.get(annotation);
643                 removePosition(fDocument, p);
644 // p.delete();
645
}
646
647             fAnnotations.remove(annotation);
648             synchronized (getLockObject()) {
649                 getAnnotationModelEvent().annotationRemoved(annotation, p);
650             }
651
652             if (fireModelChanged)
653                 fireModelChanged();
654         }
655     }
656
657     /*
658      * @see org.eclipse.jface.text.source.IAnnotationModelExtension#modifyAnnotationPosition(org.eclipse.jface.text.source.Annotation, org.eclipse.jface.text.Position)
659      * @since 3.0
660      */

661     public void modifyAnnotationPosition(Annotation annotation, Position position) {
662         modifyAnnotationPosition(annotation, position, true);
663     }
664
665     /**
666      * Modifies the associated position of the given annotation to the given
667      * position. If the annotation is not yet managed by this annotation model,
668      * the annotation is added. When the position is <code>null</code>, the
669      * annotation is removed from the model.
670      * <p>
671      * If requested, all annotation model change listeners will be informed
672      * about the change.
673      *
674      * @param annotation the annotation whose associated position should be
675      * modified
676      * @param position the position to whose values the associated position
677      * should be changed
678      * @param fireModelChanged indicates whether to notify all model listeners
679      * @since 3.0
680      */

681     protected void modifyAnnotationPosition(Annotation annotation, Position position, boolean fireModelChanged) {
682         if (position == null) {
683             removeAnnotation(annotation, fireModelChanged);
684         } else {
685             Position p= (Position) fAnnotations.get(annotation);
686             if (p != null) {
687
688                 if (position.getOffset() != p.getOffset() || position.getLength() != p.getLength()) {
689                     p.setOffset(position.getOffset());
690                     p.setLength(position.getLength());
691                 }
692                 synchronized (getLockObject()) {
693                     getAnnotationModelEvent().annotationChanged(annotation);
694                 }
695                 if (fireModelChanged)
696                     fireModelChanged();
697
698             } else {
699                 try {
700                     addAnnotation(annotation, position, fireModelChanged);
701                 } catch (BadLocationException x) {
702                     // ignore invalid position
703
}
704             }
705         }
706     }
707
708     /**
709      * Modifies the given annotation if the annotation is managed by this
710      * annotation model.
711      * <p>
712      * If requested, all annotation model change listeners will be informed
713      * about the change.
714      *
715      * @param annotation the annotation to be modified
716      * @param fireModelChanged indicates whether to notify all model listeners
717      * @since 3.0
718      */

719     protected void modifyAnnotation(Annotation annotation, boolean fireModelChanged) {
720         if (fAnnotations.containsKey(annotation)) {
721             synchronized (getLockObject()) {
722                 getAnnotationModelEvent().annotationChanged(annotation);
723             }
724             if (fireModelChanged)
725                 fireModelChanged();
726         }
727     }
728
729     /*
730      * @see IAnnotationModel#removeAnnotationModelListener(IAnnotationModelListener)
731      */

732     public void removeAnnotationModelListener(IAnnotationModelListener listener) {
733         fAnnotationModelListeners.remove(listener);
734     }
735
736     /*
737      * @see org.eclipse.jface.text.source.IAnnotationModelExtension#attach(java.lang.Object, java.lang.Object)
738      * @since 3.0
739      */

740     public void addAnnotationModel(Object JavaDoc key, IAnnotationModel attachment) {
741         Assert.isNotNull(attachment);
742         if (!fAttachments.containsValue(attachment)) {
743             fAttachments.put(key, attachment);
744             for (int i= 0; i < fOpenConnections; i++)
745                 attachment.connect(fDocument);
746             attachment.addAnnotationModelListener(fModelListener);
747         }
748     }
749
750     /*
751      * @see org.eclipse.jface.text.source.IAnnotationModelExtension#get(java.lang.Object)
752      * @since 3.0
753      */

754     public IAnnotationModel getAnnotationModel(Object JavaDoc key) {
755         return (IAnnotationModel) fAttachments.get(key);
756     }
757
758     /*
759      * @see org.eclipse.jface.text.source.IAnnotationModelExtension#detach(java.lang.Object)
760      * @since 3.0
761      */

762     public IAnnotationModel removeAnnotationModel(Object JavaDoc key) {
763         IAnnotationModel ret= (IAnnotationModel) fAttachments.remove(key);
764         if (ret != null) {
765             for (int i= 0; i < fOpenConnections; i++)
766                 ret.disconnect(fDocument);
767             ret.removeAnnotationModelListener(fModelListener);
768         }
769         return ret;
770     }
771
772     /*
773      * @see org.eclipse.jface.text.source.IAnnotationModelExtension#getModificationStamp()
774      * @since 3.0
775      */

776     public Object JavaDoc getModificationStamp() {
777         return fModificationStamp;
778     }
779 }
780
Popular Tags