david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2001, 2006 IBM Corporation and others. |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 3 | * 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 |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 7 | * |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | * Jens Lukowski/Innoopract - initial renaming/restructuring |
| 11 | * |
| 12 | *******************************************************************************/ |
pavery | 0f11a86 | 2005-03-29 21:14:36 +0000 | [diff] [blame] | 13 | package org.eclipse.wst.sse.ui.internal; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | import org.eclipse.core.resources.IMarker; |
| 17 | import org.eclipse.core.runtime.CoreException; |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 18 | import org.eclipse.jface.resource.JFaceResources; |
| 19 | import org.eclipse.jface.text.source.IAnnotationPresentation; |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 20 | import org.eclipse.swt.SWT; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 21 | import org.eclipse.swt.graphics.Image; |
| 22 | import org.eclipse.swt.widgets.Display; |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 23 | import org.eclipse.ui.ISharedImages; |
| 24 | import org.eclipse.ui.PlatformUI; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 25 | import org.eclipse.ui.texteditor.MarkerAnnotation; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 26 | import 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 | */ |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 35 | public class StructuredMarkerAnnotation extends MarkerAnnotation implements IAnnotationPresentation { |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 36 | // controls if icon should be painted gray |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 37 | private boolean fIsGrayed = false; |
| 38 | String fAnnotationType = null; |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 39 | |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 40 | StructuredMarkerAnnotation(IMarker marker) { |
| 41 | super(marker); |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 42 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 43 | |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 44 | public final String getAnnotationType() { |
| 45 | return fAnnotationType; |
| 46 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 47 | |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 48 | /** |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 49 | * Eventually will have to use IAnnotationPresentation & |
| 50 | * IAnnotationExtension |
| 51 | * |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 52 | * @see org.eclipse.ui.texteditor.MarkerAnnotation#getImage(org.eclipse.swt.widgets.Display) |
| 53 | */ |
| 54 | protected Image getImage(Display display) { |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 55 | Image image = null; |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 56 | if (fAnnotationType == TemporaryAnnotation.ANNOT_ERROR) { |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 57 | image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); |
| 58 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 59 | else if (fAnnotationType == TemporaryAnnotation.ANNOT_WARNING) { |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 60 | image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK); |
| 61 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 62 | else if (fAnnotationType == TemporaryAnnotation.ANNOT_INFO) { |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 63 | image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK); |
| 64 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 65 | |
| 66 | if (image != null && isGrayed()) |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 67 | setImage(getGrayImage(display, image)); |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 68 | else |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 69 | setImage(image); |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 70 | |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 71 | return super.getImage(display); |
| 72 | } |
| 73 | |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 74 | private Image getGrayImage(Display display, Image image) { |
| 75 | if (image != null) { |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 76 | String key = Integer.toString(image.hashCode()); |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 77 | // make sure we cache the gray image |
| 78 | Image grayImage = JFaceResources.getImageRegistry().get(key); |
| 79 | if (grayImage == null) { |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 80 | grayImage = new Image(display, image, SWT.IMAGE_GRAY); |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 81 | JFaceResources.getImageRegistry().put(key, grayImage); |
| 82 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 83 | image = grayImage; |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 84 | } |
| 85 | return image; |
| 86 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 87 | |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 88 | public final boolean isGrayed() { |
| 89 | return fIsGrayed; |
| 90 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 91 | |
pavery | b99ec53 | 2005-05-02 21:39:36 +0000 | [diff] [blame] | 92 | public final void setGrayed(boolean grayed) { |
| 93 | fIsGrayed = grayed; |
| 94 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 95 | |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 96 | /** |
| 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() { |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 101 | |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 102 | IMarker marker = getMarker(); |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 103 | 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; |
pavery | 328c4a1 | 2005-10-06 14:55:56 +0000 | [diff] [blame] | 117 | } |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 118 | } |
nitind | 09d2cb8 | 2006-05-18 18:42:43 +0000 | [diff] [blame] | 119 | |
| 120 | } |
| 121 | catch (CoreException e) { |
| 122 | Logger.logException(e); |
david_williams | cfdb2cd | 2004-11-11 08:37:49 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | } |