blob: c7b196e57db436f4979b13b0a63e8e176f9f1966 [file] [log] [blame]
david_williamscfdb2cd2004-11-11 08:37:49 +00001/*******************************************************************************
amywuecebb042007-04-10 20:07:35 +00002 * Copyright (c) 2001, 2006 IBM Corporation and others.
david_williamscfdb2cd2004-11-11 08:37:49 +00003 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
amywuecebb042007-04-10 20:07:35 +00007 *
david_williamscfdb2cd2004-11-11 08:37:49 +00008 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
pavery0f11a862005-03-29 21:14:36 +000013package org.eclipse.wst.sse.ui.internal;
david_williamscfdb2cd2004-11-11 08:37:49 +000014
15
16import org.eclipse.core.resources.IMarker;
17import org.eclipse.core.runtime.CoreException;
paveryb99ec532005-05-02 21:39:36 +000018import org.eclipse.jface.resource.JFaceResources;
19import org.eclipse.jface.text.source.IAnnotationPresentation;
paveryb99ec532005-05-02 21:39:36 +000020import org.eclipse.swt.SWT;
david_williamscfdb2cd2004-11-11 08:37:49 +000021import org.eclipse.swt.graphics.Image;
22import org.eclipse.swt.widgets.Display;
paveryb99ec532005-05-02 21:39:36 +000023import org.eclipse.ui.ISharedImages;
24import org.eclipse.ui.PlatformUI;
david_williamscfdb2cd2004-11-11 08:37:49 +000025import org.eclipse.ui.texteditor.MarkerAnnotation;
david_williamscfdb2cd2004-11-11 08:37:49 +000026import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
27
28
29/**
30 * This is overridden to get around the problem of being registered as a
31 * org.eclipse.wst.validation.core.problemmarker rather than a
32 * org.eclipse.core.resource.problemmarker causing all problems to be skipped
33 * in the OverviewRuler
34 */
paveryb99ec532005-05-02 21:39:36 +000035public class StructuredMarkerAnnotation extends MarkerAnnotation implements IAnnotationPresentation {
nitind09d2cb82006-05-18 18:42:43 +000036 // controls if icon should be painted gray
paveryb99ec532005-05-02 21:39:36 +000037 private boolean fIsGrayed = false;
38 String fAnnotationType = null;
david_williamscfdb2cd2004-11-11 08:37:49 +000039
david_williamscfdb2cd2004-11-11 08:37:49 +000040 StructuredMarkerAnnotation(IMarker marker) {
41 super(marker);
david_williamscfdb2cd2004-11-11 08:37:49 +000042 }
nitind09d2cb82006-05-18 18:42:43 +000043
paveryb99ec532005-05-02 21:39:36 +000044 public final String getAnnotationType() {
45 return fAnnotationType;
46 }
nitind09d2cb82006-05-18 18:42:43 +000047
paveryb99ec532005-05-02 21:39:36 +000048 /**
nitind09d2cb82006-05-18 18:42:43 +000049 * Eventually will have to use IAnnotationPresentation &
50 * IAnnotationExtension
51 *
david_williamscfdb2cd2004-11-11 08:37:49 +000052 * @see org.eclipse.ui.texteditor.MarkerAnnotation#getImage(org.eclipse.swt.widgets.Display)
53 */
54 protected Image getImage(Display display) {
paveryb99ec532005-05-02 21:39:36 +000055 Image image = null;
nitind09d2cb82006-05-18 18:42:43 +000056 if (fAnnotationType == TemporaryAnnotation.ANNOT_ERROR) {
paveryb99ec532005-05-02 21:39:36 +000057 image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
58 }
nitind09d2cb82006-05-18 18:42:43 +000059 else if (fAnnotationType == TemporaryAnnotation.ANNOT_WARNING) {
paveryb99ec532005-05-02 21:39:36 +000060 image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK);
61 }
nitind09d2cb82006-05-18 18:42:43 +000062 else if (fAnnotationType == TemporaryAnnotation.ANNOT_INFO) {
paveryb99ec532005-05-02 21:39:36 +000063 image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK);
64 }
nitind09d2cb82006-05-18 18:42:43 +000065
66 if (image != null && isGrayed())
paveryb99ec532005-05-02 21:39:36 +000067 setImage(getGrayImage(display, image));
nitind09d2cb82006-05-18 18:42:43 +000068 else
paveryb99ec532005-05-02 21:39:36 +000069 setImage(image);
nitind09d2cb82006-05-18 18:42:43 +000070
david_williamscfdb2cd2004-11-11 08:37:49 +000071 return super.getImage(display);
72 }
73
paveryb99ec532005-05-02 21:39:36 +000074 private Image getGrayImage(Display display, Image image) {
75 if (image != null) {
nitind09d2cb82006-05-18 18:42:43 +000076 String key = Integer.toString(image.hashCode());
paveryb99ec532005-05-02 21:39:36 +000077 // make sure we cache the gray image
78 Image grayImage = JFaceResources.getImageRegistry().get(key);
79 if (grayImage == null) {
nitind09d2cb82006-05-18 18:42:43 +000080 grayImage = new Image(display, image, SWT.IMAGE_GRAY);
paveryb99ec532005-05-02 21:39:36 +000081 JFaceResources.getImageRegistry().put(key, grayImage);
82 }
nitind09d2cb82006-05-18 18:42:43 +000083 image = grayImage;
paveryb99ec532005-05-02 21:39:36 +000084 }
85 return image;
86 }
nitind09d2cb82006-05-18 18:42:43 +000087
paveryb99ec532005-05-02 21:39:36 +000088 public final boolean isGrayed() {
89 return fIsGrayed;
90 }
nitind09d2cb82006-05-18 18:42:43 +000091
paveryb99ec532005-05-02 21:39:36 +000092 public final void setGrayed(boolean grayed) {
93 fIsGrayed = grayed;
94 }
nitind09d2cb82006-05-18 18:42:43 +000095
david_williamscfdb2cd2004-11-11 08:37:49 +000096 /**
97 * Initializes the annotation's icon representation and its drawing layer
98 * based upon the properties of the underlying marker.
99 */
100 protected void initAnnotationType() {
nitind09d2cb82006-05-18 18:42:43 +0000101
david_williamscfdb2cd2004-11-11 08:37:49 +0000102 IMarker marker = getMarker();
nitind09d2cb82006-05-18 18:42:43 +0000103 fAnnotationType = TemporaryAnnotation.ANNOT_UNKNOWN;
104 try {
105 if (marker.isSubtypeOf(IMarker.PROBLEM)) {
106 int severity = marker.getAttribute(IMarker.SEVERITY, -1);
107 switch (severity) {
108 case IMarker.SEVERITY_ERROR :
109 fAnnotationType = TemporaryAnnotation.ANNOT_ERROR;
110 break;
111 case IMarker.SEVERITY_WARNING :
112 fAnnotationType = TemporaryAnnotation.ANNOT_WARNING;
113 break;
114 case IMarker.SEVERITY_INFO :
115 fAnnotationType = TemporaryAnnotation.ANNOT_INFO;
116 break;
pavery328c4a12005-10-06 14:55:56 +0000117 }
david_williamscfdb2cd2004-11-11 08:37:49 +0000118 }
nitind09d2cb82006-05-18 18:42:43 +0000119
120 }
121 catch (CoreException e) {
122 Logger.logException(e);
david_williamscfdb2cd2004-11-11 08:37:49 +0000123 }
124 }
125}