Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2003-10-24 14:51:05 +0000
committerDani Megert2003-10-24 14:51:05 +0000
commitaafcddf9edfda662656b299cfca3b3b2896b649c (patch)
tree975002783e1beaca632d6d236a5b8c7e1c1c5778
parent792a686e4cd10ba20c30d96a53db3a71834ba475 (diff)
downloadeclipse.platform.text-aafcddf9edfda662656b299cfca3b3b2896b649c.tar.gz
eclipse.platform.text-aafcddf9edfda662656b299cfca3b3b2896b649c.tar.xz
eclipse.platform.text-aafcddf9edfda662656b299cfca3b3b2896b649c.zip
Feature 45091: inplace, permanent, and dynamic "find occurrences"
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DefaultAnnotation.java298
1 files changed, 298 insertions, 0 deletions
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DefaultAnnotation.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DefaultAnnotation.java
new file mode 100644
index 00000000000..9ceaf567d85
--- /dev/null
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/DefaultAnnotation.java
@@ -0,0 +1,298 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.ui.texteditor;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+
+import org.eclipse.jface.text.Assert;
+import org.eclipse.jface.text.source.Annotation;
+
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+/**
+ * Default annotation.
+ * This class may be instantiated or be subclassed.
+ * <p>
+ * XXX: This is work in progress and can change anytime until API for 3.0 is frozen.
+ * </p>
+ * @since 3.0
+ */
+public class DefaultAnnotation extends Annotation implements IAnnotationExtension {
+
+ /**
+ * The layer in which markers representing problem are located.
+ */
+ public final static int PROBLEM_LAYER= 5;
+
+ /** Internal image registry */
+ private static Map fgImageRegistry;
+ /** Internal type to descriptor map */
+ private static Map fgType2Descriptor= new HashMap();
+ /** Indicates that no descriptor was found */
+ private static final Object NO_DESCRIPTOR= new Object();
+
+ protected Image fImage;
+ protected String fImageName;
+
+ private int fSeverity;
+ private boolean fIsTemporary;
+ private String fMessage;
+ private String fAnnotationType;
+
+ private boolean fIsInitialized= false;
+
+ /**
+ * Returns an image for the given display as specified by the given image descriptor.
+ *
+ * @param display the display
+ * @param descriptor the image descriptor
+ * @return an image for the display as specified by the descriptor
+ */
+ protected static Image getImage(Display display, ImageDescriptor descriptor) {
+ Map map= getImageRegistry(display);
+ Image image= (Image) map.get(descriptor);
+ if (image == null) {
+ image= descriptor.createImage();
+ map.put(descriptor, image);
+ }
+ return image;
+ }
+
+ /**
+ * Returns an image registry for the given display. If no such registry exists
+ * the resgitry is created.
+ *
+ * @param display the display
+ * @return the image registry for the given display
+ */
+ protected static Map getImageRegistry(Display display) {
+ if (fgImageRegistry == null) {
+ fgImageRegistry= new HashMap();
+ display.disposeExec(new Runnable() {
+ public void run() {
+ if (fgImageRegistry != null) {
+ Map map= fgImageRegistry;
+ fgImageRegistry= null;
+ Iterator e= map.values().iterator();
+ while (e.hasNext()) {
+ Image image= (Image) e.next();
+ if (!image.isDisposed())
+ image.dispose();
+ }
+ }
+ }
+ });
+ }
+ return fgImageRegistry;
+ }
+
+ /**
+ * Returns whether the given annotationType is of the given type.
+ * <p>
+ * XXX: See bug 41478 why we don't match sub-types
+ * </p>
+ *
+ * @param annotationType the annotationType to be checked
+ * @param type the reference type
+ * @return <code>true</code>if annotationType is an instance of the reference type
+ */
+ private static boolean isAnnotationType(String annotationType, String type) {
+ return annotationType != null && annotationType.equals(type);
+ }
+
+ /**
+ * Creates a new editor annotation.
+ *
+ * @param annotationType the type of this annotation
+ * @param severity the severity of this annotation
+ * @param isTemporary <code>true</code> if this is a temporary annotation
+ * @param message the message of this annotation
+ */
+ public DefaultAnnotation(String annotationType, int severity, boolean isTemporary, String message) {
+ Assert.isTrue(severity == IMarker.SEVERITY_INFO || severity == IMarker.SEVERITY_WARNING || severity == IMarker.SEVERITY_ERROR);
+ fSeverity= severity;
+ fIsTemporary= isTemporary;
+ fMessage= message;
+ setLayer(PROBLEM_LAYER + 1);
+ fAnnotationType= annotationType;
+ }
+
+ /**
+ * Initializes the annotation's icon representation and its drawing layer
+ * based upon the properties of the underlying marker.
+ */
+ protected void initialize() {
+
+ String name= getUnknownImageName(fAnnotationType);
+ int layer= 1;
+
+ if (isAnnotationType(fAnnotationType, IMarker.TASK)) {
+ name= ISharedImages.IMG_OBJS_TASK_TSK;
+ layer= 1;
+ } else if (isAnnotationType(fAnnotationType, IMarker.BOOKMARK)) {
+ name= ISharedImages.IMG_OBJS_BKMRK_TSK;
+ layer= 2;
+ } else if (isAnnotationType(fAnnotationType, IMarker.PROBLEM)) {
+ switch (fSeverity) {
+ case IMarker.SEVERITY_INFO:
+ name= ISharedImages.IMG_OBJS_INFO_TSK;
+ layer= 3;
+ break;
+ case IMarker.SEVERITY_WARNING:
+ name= ISharedImages.IMG_OBJS_WARN_TSK;
+ layer= 3;
+ break;
+ case IMarker.SEVERITY_ERROR:
+ name= ISharedImages.IMG_OBJS_ERROR_TSK;
+ layer= PROBLEM_LAYER;
+ break;
+ }
+ }
+
+ fImage= null;
+ fImageName= name;
+ setLayer(layer);
+ }
+
+ /**
+ * Returns the name of an image used to visually represent markers of
+ * unknown type. This implementation returns <code>null</code>.
+ * Subclasses may replace this method.
+ *
+ * @return the name of an image for markers of unknown type.
+ */
+ protected String getUnknownImageName(String annotationType) {
+ return null;
+ }
+
+ /*
+ * @see Annotation#paint(GC, Canvas, Rectangle)
+ */
+ public void paint(GC gc, Canvas canvas, Rectangle r) {
+ Image image= getImage(canvas.getDisplay());
+ if (image != null)
+ drawImage(image, gc, canvas, r, SWT.CENTER, SWT.TOP);
+ }
+
+ /**
+ * Sets the marker image to the given image.
+ *
+ * @param image the new marker image
+ */
+ protected void setImage(Image image) {
+ fImage= image;
+ }
+
+ /**
+ * Returns the image of the given name. Subclasses may extend this method.
+ * If so, subclasses must assume responsibility for disposing the images
+ * they create.
+ *
+ * @param name the name of the requested image
+ * @return the image or <code>null</code> if there is no such image
+ */
+ protected Image getImage(String name) {
+ if (name != null)
+ return PlatformUI.getWorkbench().getSharedImages().getImage(name);
+ return null;
+ }
+
+ /*
+ * @see IJavaAnnotation#getImage(Display)
+ */
+ protected Image getImage(Display display) {
+
+ if (!fIsInitialized) {
+ fIsInitialized= true;
+ initialize();
+ }
+
+ if (fImage != null)
+ return fImage;
+
+ Object descriptor= fgType2Descriptor.get(fAnnotationType);
+ if (descriptor == NO_DESCRIPTOR)
+ fImage= getImage(fImageName);
+ else if (descriptor != null)
+ fImage= getImage(display, (ImageDescriptor)descriptor);
+
+ if (fImage != null)
+ return fImage;
+
+ // XXX: hack since I cannot get the image for a marker type
+ try {
+ IMarker tempMarker= ResourcesPlugin.getWorkspace().getRoot().createMarker(fAnnotationType);
+ if (tempMarker.exists()) {
+ IWorkbenchAdapter adapter= (IWorkbenchAdapter) tempMarker.getAdapter(IWorkbenchAdapter.class);
+ if (adapter != null) {
+ descriptor= adapter.getImageDescriptor(tempMarker);
+ if (descriptor != null) {
+ fImage= getImage(display, (ImageDescriptor)descriptor);
+ fgType2Descriptor.put(fAnnotationType, descriptor);
+ } else {
+ fgType2Descriptor.put(fAnnotationType, NO_DESCRIPTOR);
+ }
+ }
+ tempMarker.delete();
+ }
+ } catch (CoreException ex) {
+ fgType2Descriptor.put(fAnnotationType, NO_DESCRIPTOR);
+ }
+
+ if (fImage == null)
+ fImage= getImage(fImageName);
+
+ return fImage;
+ }
+
+ /*
+ * @see IAnnotationExtension#getMessage()
+ */
+ public String getMessage() {
+ return fMessage;
+ }
+
+ public String getMarkerType() {
+ return fAnnotationType;
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.IAnnotationExtension#getSeverity()
+ */
+ public int getSeverity() {
+ return fSeverity;
+ }
+
+ /*
+ * @see IAnnotationExtension#isTemporary()
+ */
+ public boolean isTemporary() {
+ return fIsTemporary;
+ }
+}

Back to the top