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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
15 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
17 import org.eclipse.core.resources.IMarker;
18 import org.eclipse.core.resources.IResource;
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.jface.text.Position;
21 import org.eclipse.jface.text.source.Annotation;
22 import org.eclipse.jface.text.source.AnnotationModelEvent;
23 import org.eclipse.jface.text.source.IAnnotationModel;
24 import org.eclipse.ui.texteditor.MarkerAnnotation;
28 * Event sent out by changes of the compilation unit annotation model.
30 public class CompilationUnitAnnotationModelEvent extends AnnotationModelEvent {
32 private boolean fIncludesProblemMarkerAnnotations;
33 private IResource fUnderlyingResource;
36 * Constructor for CompilationUnitAnnotationModelEvent.
38 * @param underlyingResource The annotation model's underlying resource
40 public CompilationUnitAnnotationModelEvent(IAnnotationModel model, IResource underlyingResource) {
42 fUnderlyingResource= underlyingResource;
43 fIncludesProblemMarkerAnnotations= false;
46 private void testIfProblemMarker(Annotation annotation) {
47 if (fIncludesProblemMarkerAnnotations) {
50 if (annotation instanceof JavaMarkerAnnotation) {
51 fIncludesProblemMarkerAnnotations= ((JavaMarkerAnnotation) annotation).isProblem();
52 } else if (annotation instanceof MarkerAnnotation) {
54 IMarker marker= ((MarkerAnnotation) annotation).getMarker();
55 if (!marker.exists() || marker.isSubtypeOf(IMarker.PROBLEM)) {
56 fIncludesProblemMarkerAnnotations= true;
58 } catch (CoreException e) {
59 PHPeclipsePlugin.log(e);
65 * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationAdded(org.eclipse.jface.text.source.Annotation)
67 public void annotationAdded(Annotation annotation) {
68 super.annotationAdded(annotation);
69 testIfProblemMarker(annotation);
74 * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationRemoved(org.eclipse.jface.text.source.Annotation)
76 public void annotationRemoved(Annotation annotation) {
77 super.annotationRemoved(annotation);
78 testIfProblemMarker(annotation);
82 * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationRemoved(org.eclipse.jface.text.source.Annotation, org.eclipse.jface.text.Position)
84 public void annotationRemoved(Annotation annotation, Position position) {
85 super.annotationRemoved(annotation, position);
86 testIfProblemMarker(annotation);
90 * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationChanged(org.eclipse.jface.text.source.Annotation)
92 public void annotationChanged(Annotation annotation) {
93 testIfProblemMarker(annotation);
94 super.annotationChanged(annotation);
98 * Returns whether the change included problem marker annotations.
100 * @return <code>true</code> if the change included marker annotations
102 public boolean includesProblemMarkerAnnotationChanges() {
103 return fIncludesProblemMarkerAnnotations;
107 * Returns the annotation model's underlying resource
109 public IResource getUnderlyingResource() {
110 return fUnderlyingResource;