KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > ProblemImageProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
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
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.ide;
12
13 import org.eclipse.core.resources.IMarker;
14 import org.eclipse.core.runtime.CoreException;
15
16 /**
17  * Implementation of IMarkerImageProvider to provide the image
18  * path names for problem markers.
19  */

20 public class ProblemImageProvider implements IMarkerImageProvider {
21     /**
22      * TaskImageProvider constructor comment.
23      */

24     public ProblemImageProvider() {
25         super();
26     }
27
28     /**
29      * Returns the relative path for the image
30      * to be used for displaying an marker in the workbench.
31      * This path is relative to the plugin location
32      *
33      * Returns <code>null</code> if there is no appropriate image.
34      *
35      * @param marker The marker to get an image path for.
36      *
37      */

38     public String JavaDoc getImagePath(IMarker marker) {
39         String JavaDoc iconPath = "/icons/full/";//$NON-NLS-1$
40
if (isMarkerType(marker, IMarker.PROBLEM)) {
41             switch (marker.getAttribute(IMarker.SEVERITY,
42                     IMarker.SEVERITY_WARNING)) {
43             case IMarker.SEVERITY_ERROR:
44                 return iconPath + "obj16/error_tsk.gif";//$NON-NLS-1$
45
case IMarker.SEVERITY_WARNING:
46                 return iconPath + "obj16/warn_tsk.gif";//$NON-NLS-1$
47
case IMarker.SEVERITY_INFO:
48                 return iconPath + "obj16/info_tsk.gif";//$NON-NLS-1$
49
}
50         }
51         return null;
52     }
53
54     /**
55      * Returns whether the given marker is of the given type (either directly or indirectly).
56      */

57     private boolean isMarkerType(IMarker marker, String JavaDoc type) {
58         try {
59             return marker.isSubtypeOf(type);
60         } catch (CoreException e) {
61             return false;
62         }
63     }
64 }
65
Popular Tags