001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.ui.texteditor;
011:
012: import org.eclipse.core.runtime.Assert;
013:
014: import org.eclipse.core.resources.IMarker;
015: import org.eclipse.jface.text.source.Annotation;
016: import org.eclipse.ui.internal.editors.text.EditorsPlugin;
017:
018: /**
019: * An annotation representing a marker. This is a model annotation.
020: *
021: * @see IMarker
022: * @since 3.0
023: */
024: public class SimpleMarkerAnnotation extends Annotation {
025:
026: private IMarker fMarker;
027:
028: /**
029: * Creates a new annotation for the given marker.
030: * @see IMarker
031: *
032: * @param marker the marker
033: */
034: public SimpleMarkerAnnotation(IMarker marker) {
035: this (EditorsPlugin.getDefault().getAnnotationTypeLookup()
036: .getAnnotationType(marker), marker);
037: }
038:
039: /**
040: * Creates a new annotation of the given type for the given marker.
041: *
042: * @param annotationType the annotation type
043: * @param marker the marker
044: */
045: public SimpleMarkerAnnotation(String annotationType, IMarker marker) {
046: super (annotationType, true, null);
047: Assert.isNotNull(marker);
048: fMarker = marker;
049: }
050:
051: /**
052: * Returns this annotation's underlying marker.
053: *
054: * @return the marker
055: */
056: public IMarker getMarker() {
057: return fMarker;
058: }
059:
060: /**
061: * The <code>SimpleMarkerAnnotation</code> implementation of this
062: * <code>Object</code> method returns <code>true</code> iff the other
063: * object is of the same class and the marker handles are equal.
064: *
065: * @see Object#equals(java.lang.Object)
066: */
067: public boolean equals(Object o) {
068: if (o != null && o.getClass() == getClass())
069: return fMarker.equals(((SimpleMarkerAnnotation) o).fMarker);
070: return false;
071: }
072:
073: /*
074: * @see Object#hashCode()
075: */
076: public int hashCode() {
077: return fMarker.hashCode();
078: }
079:
080: /**
081: * Informs this annotation about changes applied to its underlying marker
082: * and adapts to those changes.
083: * <p>
084: * Subclasses may extend this method.
085: * </p>
086: */
087: public void update() {
088: updateType();
089: }
090:
091: /**
092: * Updates the type to be synchronized with its underlying marker.
093: *
094: * @since 3.0
095: */
096: private void updateType() {
097: String annotationType = EditorsPlugin.getDefault()
098: .getAnnotationTypeLookup().getAnnotationType(fMarker);
099: if (annotationType != null && !annotationType.equals(getType()))
100: setType(annotationType);
101: }
102:
103: /*
104: * @see org.eclipse.jface.text.source.Annotation#getText()
105: */
106: public String getText() {
107: return MarkerUtilities.getMessage(fMarker);
108: }
109: }
|