KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > CompilationUnitAnnotationModelEvent


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.ui.javaeditor;
12
13
14
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18
19 import org.eclipse.jface.text.Position;
20 import org.eclipse.jface.text.source.Annotation;
21 import org.eclipse.jface.text.source.AnnotationModelEvent;
22 import org.eclipse.jface.text.source.IAnnotationModel;
23
24 import org.eclipse.ui.texteditor.MarkerAnnotation;
25
26 import org.eclipse.jdt.internal.ui.JavaPlugin;
27
28 /**
29  * Event sent out by changes of the compilation unit annotation model.
30  */

31 public class CompilationUnitAnnotationModelEvent extends AnnotationModelEvent {
32
33     private boolean fIncludesProblemMarkerAnnotations;
34     private IResource fUnderlyingResource;
35
36     /**
37      * Constructor for CompilationUnitAnnotationModelEvent.
38      * @param model
39      * @param underlyingResource The annotation model's underlying resource
40      */

41     public CompilationUnitAnnotationModelEvent(IAnnotationModel model, IResource underlyingResource) {
42         super(model);
43         fUnderlyingResource= underlyingResource;
44         fIncludesProblemMarkerAnnotations= false;
45     }
46
47     private void testIfProblemMarker(Annotation annotation) {
48         if (fIncludesProblemMarkerAnnotations) {
49             return;
50         }
51         if (annotation instanceof JavaMarkerAnnotation) {
52             fIncludesProblemMarkerAnnotations= ((JavaMarkerAnnotation) annotation).isProblem();
53         } else if (annotation instanceof MarkerAnnotation) {
54             try {
55                 IMarker marker= ((MarkerAnnotation) annotation).getMarker();
56                 if (!marker.exists() || marker.isSubtypeOf(IMarker.PROBLEM)) {
57                     fIncludesProblemMarkerAnnotations= true;
58                 }
59             } catch (CoreException e) {
60                 JavaPlugin.log(e);
61             }
62         }
63     }
64
65     /*
66      * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationAdded(org.eclipse.jface.text.source.Annotation)
67      */

68     public void annotationAdded(Annotation annotation) {
69         super.annotationAdded(annotation);
70         testIfProblemMarker(annotation);
71     }
72
73
74     /*
75      * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationRemoved(org.eclipse.jface.text.source.Annotation)
76      */

77     public void annotationRemoved(Annotation annotation) {
78         super.annotationRemoved(annotation);
79         testIfProblemMarker(annotation);
80     }
81
82     /*
83      * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationRemoved(org.eclipse.jface.text.source.Annotation, org.eclipse.jface.text.Position)
84      */

85     public void annotationRemoved(Annotation annotation, Position position) {
86         super.annotationRemoved(annotation, position);
87         testIfProblemMarker(annotation);
88     }
89
90     /*
91      * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationChanged(org.eclipse.jface.text.source.Annotation)
92      */

93     public void annotationChanged(Annotation annotation) {
94         testIfProblemMarker(annotation);
95         super.annotationChanged(annotation);
96     }
97
98     /**
99      * Returns whether the change included problem marker annotations.
100      *
101      * @return <code>true</code> if the change included marker annotations
102      */

103     public boolean includesProblemMarkerAnnotationChanges() {
104         return fIncludesProblemMarkerAnnotations;
105     }
106
107     /**
108      * Returns the annotation model's underlying resource
109      */

110     public IResource getUnderlyingResource() {
111         return fUnderlyingResource;
112     }
113
114 }
115
Popular Tags