001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.javaeditor;
011:
012: import org.eclipse.core.resources.IMarker;
013: import org.eclipse.core.resources.IResource;
014: import org.eclipse.core.runtime.CoreException;
015:
016: import org.eclipse.jface.text.Position;
017: import org.eclipse.jface.text.source.Annotation;
018: import org.eclipse.jface.text.source.AnnotationModelEvent;
019: import org.eclipse.jface.text.source.IAnnotationModel;
020:
021: import org.eclipse.ui.texteditor.MarkerAnnotation;
022:
023: import org.eclipse.jdt.internal.ui.JavaPlugin;
024:
025: /**
026: * Event sent out by changes of the compilation unit annotation model.
027: */
028: public class CompilationUnitAnnotationModelEvent extends
029: AnnotationModelEvent {
030:
031: private boolean fIncludesProblemMarkerAnnotations;
032: private IResource fUnderlyingResource;
033:
034: /**
035: * Constructor for CompilationUnitAnnotationModelEvent.
036: * @param model
037: * @param underlyingResource The annotation model's underlying resource
038: */
039: public CompilationUnitAnnotationModelEvent(IAnnotationModel model,
040: IResource underlyingResource) {
041: super (model);
042: fUnderlyingResource = underlyingResource;
043: fIncludesProblemMarkerAnnotations = false;
044: }
045:
046: private void testIfProblemMarker(Annotation annotation) {
047: if (fIncludesProblemMarkerAnnotations) {
048: return;
049: }
050: if (annotation instanceof JavaMarkerAnnotation) {
051: fIncludesProblemMarkerAnnotations = ((JavaMarkerAnnotation) annotation)
052: .isProblem();
053: } else if (annotation instanceof MarkerAnnotation) {
054: try {
055: IMarker marker = ((MarkerAnnotation) annotation)
056: .getMarker();
057: if (!marker.exists()
058: || marker.isSubtypeOf(IMarker.PROBLEM)) {
059: fIncludesProblemMarkerAnnotations = true;
060: }
061: } catch (CoreException e) {
062: JavaPlugin.log(e);
063: }
064: }
065: }
066:
067: /*
068: * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationAdded(org.eclipse.jface.text.source.Annotation)
069: */
070: public void annotationAdded(Annotation annotation) {
071: super .annotationAdded(annotation);
072: testIfProblemMarker(annotation);
073: }
074:
075: /*
076: * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationRemoved(org.eclipse.jface.text.source.Annotation)
077: */
078: public void annotationRemoved(Annotation annotation) {
079: super .annotationRemoved(annotation);
080: testIfProblemMarker(annotation);
081: }
082:
083: /*
084: * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationRemoved(org.eclipse.jface.text.source.Annotation, org.eclipse.jface.text.Position)
085: */
086: public void annotationRemoved(Annotation annotation,
087: Position position) {
088: super .annotationRemoved(annotation, position);
089: testIfProblemMarker(annotation);
090: }
091:
092: /*
093: * @see org.eclipse.jface.text.source.AnnotationModelEvent#annotationChanged(org.eclipse.jface.text.source.Annotation)
094: */
095: public void annotationChanged(Annotation annotation) {
096: testIfProblemMarker(annotation);
097: super .annotationChanged(annotation);
098: }
099:
100: /**
101: * Returns whether the change included problem marker annotations.
102: *
103: * @return <code>true</code> if the change included marker annotations
104: */
105: public boolean includesProblemMarkerAnnotationChanges() {
106: return fIncludesProblemMarkerAnnotations;
107: }
108:
109: /**
110: * Returns the annotation model's underlying resource
111: */
112: public IResource getUnderlyingResource() {
113: return fUnderlyingResource;
114: }
115:
116: }
|