committing phphelp to Plug-ins for feature to fix build dependence for phpmanual.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / CompilationUnitAnnotationModelEvent.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
12
13 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
14
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.jface.text.Position;
19 import org.eclipse.jface.text.source.Annotation;
20 import org.eclipse.jface.text.source.AnnotationModelEvent;
21 import org.eclipse.jface.text.source.IAnnotationModel;
22 import org.eclipse.ui.texteditor.MarkerAnnotation;
23
24 /**
25  * Event sent out by changes of the compilation unit annotation model.
26  */
27 public class CompilationUnitAnnotationModelEvent extends AnnotationModelEvent {
28
29         private boolean fIncludesProblemMarkerAnnotations;
30
31         private IResource fUnderlyingResource;
32
33         /**
34          * Constructor for CompilationUnitAnnotationModelEvent.
35          * 
36          * @param model
37          * @param underlyingResource
38          *            The annotation model's underlying resource
39          */
40         public CompilationUnitAnnotationModelEvent(IAnnotationModel model,
41                         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)
53                                         .isProblem();
54                 } else if (annotation instanceof MarkerAnnotation) {
55                         try {
56                                 IMarker marker = ((MarkerAnnotation) annotation).getMarker();
57                                 if (!marker.exists() || marker.isSubtypeOf(IMarker.PROBLEM)) {
58                                         fIncludesProblemMarkerAnnotations = true;
59                                 }
60                         } catch (CoreException e) {
61                                 PHPeclipsePlugin.log(e);
62                         }
63                 }
64         }
65
66         /*
67          * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationAdded(org.eclipse.jface.text.source.Annotation)
68          */
69         public void annotationAdded(Annotation annotation) {
70                 super.annotationAdded(annotation);
71                 testIfProblemMarker(annotation);
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,
84          *      org.eclipse.jface.text.Position)
85          */
86         public void annotationRemoved(Annotation annotation, Position position) {
87                 super.annotationRemoved(annotation, position);
88                 testIfProblemMarker(annotation);
89         }
90
91         /*
92          * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationChanged(org.eclipse.jface.text.source.Annotation)
93          */
94         public void annotationChanged(Annotation annotation) {
95                 testIfProblemMarker(annotation);
96                 super.annotationChanged(annotation);
97         }
98
99         /**
100          * Returns whether the change included problem marker annotations.
101          * 
102          * @return <code>true</code> if the change included marker annotations
103          */
104         public boolean includesProblemMarkerAnnotationChanges() {
105                 return fIncludesProblemMarkerAnnotations;
106         }
107
108         /**
109          * Returns the annotation model's underlying resource
110          */
111         public IResource getUnderlyingResource() {
112                 return fUnderlyingResource;
113         }
114
115 }