diff org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children 5feec68b4556
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.eclipse.text/src/org/eclipse/jface/text/source/AnnotationModelEvent.d	Sat Mar 14 18:23:29 2009 +0100
@@ -0,0 +1,333 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module org.eclipse.jface.text.source.AnnotationModelEvent;
+
+import org.eclipse.jface.text.source.ISharedTextColors; // packageimport
+import org.eclipse.jface.text.source.ILineRange; // packageimport
+import org.eclipse.jface.text.source.IAnnotationPresentation; // packageimport
+import org.eclipse.jface.text.source.IVerticalRulerInfoExtension; // packageimport
+import org.eclipse.jface.text.source.ICharacterPairMatcher; // packageimport
+import org.eclipse.jface.text.source.TextInvocationContext; // packageimport
+import org.eclipse.jface.text.source.LineChangeHover; // packageimport
+import org.eclipse.jface.text.source.IChangeRulerColumn; // packageimport
+import org.eclipse.jface.text.source.IAnnotationMap; // packageimport
+import org.eclipse.jface.text.source.IAnnotationModelListenerExtension; // packageimport
+import org.eclipse.jface.text.source.ISourceViewerExtension2; // packageimport
+import org.eclipse.jface.text.source.IAnnotationHover; // packageimport
+import org.eclipse.jface.text.source.ContentAssistantFacade; // packageimport
+import org.eclipse.jface.text.source.IAnnotationAccess; // packageimport
+import org.eclipse.jface.text.source.IVerticalRulerExtension; // packageimport
+import org.eclipse.jface.text.source.IVerticalRulerColumn; // packageimport
+import org.eclipse.jface.text.source.LineNumberRulerColumn; // packageimport
+import org.eclipse.jface.text.source.MatchingCharacterPainter; // packageimport
+import org.eclipse.jface.text.source.IAnnotationModelExtension; // packageimport
+import org.eclipse.jface.text.source.ILineDifferExtension; // packageimport
+import org.eclipse.jface.text.source.DefaultCharacterPairMatcher; // packageimport
+import org.eclipse.jface.text.source.LineNumberChangeRulerColumn; // packageimport
+import org.eclipse.jface.text.source.IAnnotationAccessExtension; // packageimport
+import org.eclipse.jface.text.source.ISourceViewer; // packageimport
+import org.eclipse.jface.text.source.AnnotationModel; // packageimport
+import org.eclipse.jface.text.source.ILineDifferExtension2; // packageimport
+import org.eclipse.jface.text.source.IAnnotationModelListener; // packageimport
+import org.eclipse.jface.text.source.IVerticalRuler; // packageimport
+import org.eclipse.jface.text.source.DefaultAnnotationHover; // packageimport
+import org.eclipse.jface.text.source.SourceViewer; // packageimport
+import org.eclipse.jface.text.source.SourceViewerConfiguration; // packageimport
+import org.eclipse.jface.text.source.AnnotationBarHoverManager; // packageimport
+import org.eclipse.jface.text.source.CompositeRuler; // packageimport
+import org.eclipse.jface.text.source.ImageUtilities; // packageimport
+import org.eclipse.jface.text.source.VisualAnnotationModel; // packageimport
+import org.eclipse.jface.text.source.IAnnotationModel; // packageimport
+import org.eclipse.jface.text.source.ISourceViewerExtension3; // packageimport
+import org.eclipse.jface.text.source.ILineDiffInfo; // packageimport
+import org.eclipse.jface.text.source.VerticalRulerEvent; // packageimport
+import org.eclipse.jface.text.source.ChangeRulerColumn; // packageimport
+import org.eclipse.jface.text.source.ILineDiffer; // packageimport
+import org.eclipse.jface.text.source.AnnotationColumn; // packageimport
+import org.eclipse.jface.text.source.AnnotationRulerColumn; // packageimport
+import org.eclipse.jface.text.source.IAnnotationHoverExtension; // packageimport
+import org.eclipse.jface.text.source.AbstractRulerColumn; // packageimport
+import org.eclipse.jface.text.source.ISourceViewerExtension; // packageimport
+import org.eclipse.jface.text.source.AnnotationMap; // packageimport
+import org.eclipse.jface.text.source.IVerticalRulerInfo; // packageimport
+import org.eclipse.jface.text.source.IAnnotationModelExtension2; // packageimport
+import org.eclipse.jface.text.source.LineRange; // packageimport
+import org.eclipse.jface.text.source.IAnnotationAccessExtension2; // packageimport
+import org.eclipse.jface.text.source.VerticalRuler; // packageimport
+import org.eclipse.jface.text.source.JFaceTextMessages; // packageimport
+import org.eclipse.jface.text.source.IOverviewRuler; // packageimport
+import org.eclipse.jface.text.source.Annotation; // packageimport
+import org.eclipse.jface.text.source.IVerticalRulerListener; // packageimport
+import org.eclipse.jface.text.source.ISourceViewerExtension4; // packageimport
+import org.eclipse.jface.text.source.AnnotationPainter; // packageimport
+import org.eclipse.jface.text.source.IAnnotationHoverExtension2; // packageimport
+import org.eclipse.jface.text.source.OverviewRuler; // packageimport
+import org.eclipse.jface.text.source.OverviewRulerHoverManager; // packageimport
+
+
+import java.lang.all;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+
+
+
+
+
+
+import org.eclipse.jface.text.Position;
+
+
+/**
+ * Specification of changes applied to annotation models. The event carries the
+ * changed annotation model as well as added, removed, and modified annotations.
+ * <p>
+ * An event can be sealed. Afterwards it can not be modified. Thus, the normal
+ * process is that an empty event is created, filled with the changed
+ * information, and before it is sent to the listeners, the event is sealed.
+ *
+ * @see org.eclipse.jface.text.source.IAnnotationModel
+ * @see org.eclipse.jface.text.source.IAnnotationModelListenerExtension
+ * @since 2.0
+ */
+public class AnnotationModelEvent {
+
+    /** The model this event refers to. */
+    private IAnnotationModel fAnnotationModel;
+    /**
+     * The added annotations.
+     * @since 3.0
+     */
+    private Set fAddedAnnotations;
+    /**
+     * The removed annotations.
+     * @since 3.0
+     */
+    private Map fRemovedAnnotations;
+    /**
+     * The changed annotations.
+     * @since 3.0
+     */
+    private Set fChangedAnnotations;
+    /**
+     * Indicates that this event does not contain detailed information.
+     * @since 3.0
+     */
+    private bool fIsWorldChange;
+    /**
+     * The modification stamp.
+     * @since 3.0
+     */
+    private Object fModificationStamp;
+
+    /**
+     * Creates a new annotation model event for the given model.
+     *
+     * @param model the model
+     */
+    public this(IAnnotationModel model) {
+        this(model, true);
+    }
+
+    /**
+     * Creates a new annotation model event for the given model.
+     *
+     * @param model the model
+     * @param isWorldChange <code>true</code> if world change
+     * @since 3.0
+     */
+    public this(IAnnotationModel model, bool isWorldChange) {
+        fAddedAnnotations= new HashSet();
+        fRemovedAnnotations= new HashMap();
+        fChangedAnnotations= new HashSet();
+
+        fAnnotationModel= model;
+        fIsWorldChange= isWorldChange;
+    }
+
+    /**
+     * Returns the model this event refers to.
+     *
+     * @return the model this events belongs to
+     */
+    public IAnnotationModel getAnnotationModel() {
+        return fAnnotationModel;
+    }
+
+    /**
+     * Adds the given annotation to the set of annotations that are reported as
+     * being added from the model. If this event is considered a world change,
+     * it is no longer so after this method has successfully finished.
+     *
+     * @param annotation the added annotation
+     * @since 3.0
+     */
+    public void annotationAdded(Annotation annotation) {
+        fAddedAnnotations.add(annotation);
+        fIsWorldChange= false;
+    }
+
+    /**
+     * Returns the added annotations.
+     *
+     * @return the added annotations
+     * @since 3.0
+     */
+    public Annotation[] getAddedAnnotations() {
+        int size= fAddedAnnotations.size();
+        Annotation[] added= new Annotation[size];
+        fAddedAnnotations.toArray(added);
+        return added;
+    }
+
+    /**
+     * Adds the given annotation to the set of annotations that are reported as
+     * being removed from the model. If this event is considered a world
+     * change, it is no longer so after this method has successfully finished.
+     *
+     * @param annotation the removed annotation
+     * @since 3.0
+     */
+    public void annotationRemoved(Annotation annotation) {
+        annotationRemoved(annotation, null);
+    }
+
+    /**
+     * Adds the given annotation to the set of annotations that are reported as
+     * being removed from the model. If this event is considered a world
+     * change, it is no longer so after this method has successfully finished.
+     *
+     * @param annotation the removed annotation
+     * @param position the position of the removed annotation
+     * @since 3.0
+     */
+    public void annotationRemoved(Annotation annotation, Position position) {
+        fRemovedAnnotations.put(annotation, position);
+        fIsWorldChange= false;
+    }
+
+    /**
+     * Returns the removed annotations.
+     *
+     * @return the removed annotations
+     * @since 3.0
+     */
+    public Annotation[] getRemovedAnnotations() {
+        int size= fRemovedAnnotations.size();
+        Annotation[] removed= new Annotation[size];
+        fRemovedAnnotations.keySet().toArray(removed);
+        return removed;
+    }
+
+    /**
+     * Returns the position of the removed annotation at that point in time
+     * when the annotation has been removed.
+     *
+     * @param annotation the removed annotation
+     * @return the position of the removed annotation or <code>null</code>
+     * @since 3.0
+     */
+    public Position getPositionOfRemovedAnnotation(Annotation annotation) {
+        return cast(Position) fRemovedAnnotations.get(annotation);
+    }
+
+    /**
+     * Adds the given annotation to the set of annotations that are reported as
+     * being changed from the model. If this event is considered a world
+     * change, it is no longer so after this method has successfully finished.
+     *
+     * @param annotation the changed annotation
+     * @since 3.0
+     */
+    public void annotationChanged(Annotation annotation) {
+        fChangedAnnotations.add(annotation);
+        fIsWorldChange= false;
+    }
+
+    /**
+     * Returns the changed annotations.
+     *
+     * @return the changed annotations
+     * @since 3.0
+     */
+    public Annotation[] getChangedAnnotations() {
+        int size= fChangedAnnotations.size();
+        Annotation[] changed= new Annotation[size];
+        fChangedAnnotations.toArray(changed);
+        return changed;
+    }
+
+    /**
+     * Returns whether this annotation model event is empty or not. If this
+     * event represents a world change, this method returns <code>false</code>
+     * although the event does not carry any added, removed, or changed
+     * annotations.
+     *
+     * @return <code>true</code> if this event is empty
+     * @since 3.0
+     */
+    public bool isEmpty() {
+        return !fIsWorldChange && fAddedAnnotations.isEmpty() && fRemovedAnnotations.isEmpty() && fChangedAnnotations.isEmpty();
+    }
+
+    /**
+     * Returns whether this annotation model events contains detailed
+     * information about the modifications applied to the event annotation
+     * model or whether it represents a world change. I.e. everything in the
+     * model might have changed.
+     *
+     * @return <code>true</code> if world change, <code>false</code> otherwise
+     * @since 3.0
+     */
+    public bool isWorldChange() {
+        return fIsWorldChange;
+    }
+
+    /**
+     * Marks this event as world change according to the given flag.
+     *
+     * @param isWorldChange <code>true</code> if this event is a world change, <code>false</code> otherwise
+     * @since 3.0
+     */
+    void markWorldChange(bool isWorldChange) {
+        fIsWorldChange= isWorldChange;
+    }
+
+    /**
+     * Returns whether this annotation model event is still valid.
+     *
+     * @return <code>true</code> if this event is still valid, <code>false</code> otherwise
+     * @since 3.0
+     */
+    public bool isValid() {
+        if (fModificationStamp !is null && cast(IAnnotationModelExtension)fAnnotationModel ) {
+            IAnnotationModelExtension extension= cast(IAnnotationModelExtension) fAnnotationModel;
+            return fModificationStamp is extension.getModificationStamp();
+        }
+        return true;
+    }
+
+    /**
+     * Seals this event. Any direct modification to the annotation model after the event has been sealed
+     * invalidates this event.
+     *
+     * @since 3.0
+     */
+    public void markSealed() {
+        if ( cast(IAnnotationModelExtension)fAnnotationModel ) {
+            IAnnotationModelExtension extension= cast(IAnnotationModelExtension) fAnnotationModel;
+            fModificationStamp= extension.getModificationStamp();
+        }
+    }
+}