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;
13 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
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;
25 * Event sent out by changes of the compilation unit annotation model.
27 public class CompilationUnitAnnotationModelEvent extends AnnotationModelEvent {
29 private boolean fIncludesProblemMarkerAnnotations;
31 private IResource fUnderlyingResource;
34 * Constructor for CompilationUnitAnnotationModelEvent.
37 * @param underlyingResource
38 * The annotation model's underlying resource
40 public CompilationUnitAnnotationModelEvent(IAnnotationModel model,
41 IResource underlyingResource) {
43 fUnderlyingResource = underlyingResource;
44 fIncludesProblemMarkerAnnotations = false;
47 private void testIfProblemMarker(Annotation annotation) {
48 if (fIncludesProblemMarkerAnnotations) {
51 if (annotation instanceof JavaMarkerAnnotation) {
52 fIncludesProblemMarkerAnnotations = ((JavaMarkerAnnotation) annotation)
54 } else if (annotation instanceof MarkerAnnotation) {
56 IMarker marker = ((MarkerAnnotation) annotation).getMarker();
57 if (!marker.exists() || marker.isSubtypeOf(IMarker.PROBLEM)) {
58 fIncludesProblemMarkerAnnotations = true;
60 } catch (CoreException e) {
61 PHPeclipsePlugin.log(e);
67 * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationAdded(org.eclipse.jface.text.source.Annotation)
69 public void annotationAdded(Annotation annotation) {
70 super.annotationAdded(annotation);
71 testIfProblemMarker(annotation);
75 * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationRemoved(org.eclipse.jface.text.source.Annotation)
77 public void annotationRemoved(Annotation annotation) {
78 super.annotationRemoved(annotation);
79 testIfProblemMarker(annotation);
83 * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationRemoved(org.eclipse.jface.text.source.Annotation,
84 * org.eclipse.jface.text.Position)
86 public void annotationRemoved(Annotation annotation, Position position) {
87 super.annotationRemoved(annotation, position);
88 testIfProblemMarker(annotation);
92 * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationChanged(org.eclipse.jface.text.source.Annotation)
94 public void annotationChanged(Annotation annotation) {
95 testIfProblemMarker(annotation);
96 super.annotationChanged(annotation);
100 * Returns whether the change included problem marker annotations.
102 * @return <code>true</code> if the change included marker annotations
104 public boolean includesProblemMarkerAnnotationChanges() {
105 return fIncludesProblemMarkerAnnotations;
109 * Returns the annotation model's underlying resource
111 public IResource getUnderlyingResource() {
112 return fUnderlyingResource;