KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > FieldSeverity


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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
12 package org.eclipse.ui.views.markers.internal;
13
14 import org.eclipse.core.resources.IMarker;
15 import org.eclipse.swt.graphics.Image;
16
17 public class FieldSeverity implements IField {
18
19     private static final String JavaDoc IMAGE_ERROR_PATH = "obj16/error_tsk.gif"; //$NON-NLS-1$
20

21     private static final String JavaDoc IMAGE_WARNING_PATH = "obj16/warn_tsk.gif"; //$NON-NLS-1$
22

23     private static final String JavaDoc IMAGE_INFO_PATH = "obj16/info_tsk.gif"; //$NON-NLS-1$
24

25     private String JavaDoc description;
26
27     private Image image;
28
29     public FieldSeverity() {
30         description = Messages.getString("problemSeverity.description"); //$NON-NLS-1$
31
image = null;
32     }
33
34     /*
35      * (non-Javadoc)
36      * @see org.eclipse.ui.views.markers.internal.IField#getDescription()
37      */

38     public String JavaDoc getDescription() {
39         return description;
40     }
41
42     /*
43      * (non-Javadoc)
44      * @see org.eclipse.ui.views.markers.internal.IField#getDescriptionImage()
45      */

46     public Image getDescriptionImage() {
47         return image;
48     }
49
50     /*
51      * (non-Javadoc)
52      * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderText()
53      */

54     public String JavaDoc getColumnHeaderText() {
55         return ""; //$NON-NLS-1$
56
}
57
58     /*
59      * (non-Javadoc)
60      * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderImage()
61      */

62     public Image getColumnHeaderImage() {
63         return null;
64     }
65
66     /*
67      * (non-Javadoc)
68      * @see org.eclipse.ui.views.markers.internal.IField#getValue(java.lang.Object)
69      */

70     public String JavaDoc getValue(Object JavaDoc obj) {
71         return "" + ((ProblemMarker) obj).getSeverity(); //$NON-NLS-1$
72
}
73
74     /*
75      * (non-Javadoc)
76      * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
77      */

78     public Image getImage(Object JavaDoc obj) {
79         if (obj == null || !(obj instanceof ProblemMarker)) {
80             return null;
81         }
82
83         int severity = ((ProblemMarker) obj).getSeverity();
84         if (severity == IMarker.SEVERITY_ERROR) {
85             return ImageFactory.getImage(IMAGE_ERROR_PATH);
86         }
87         if (severity == IMarker.SEVERITY_WARNING) {
88             return ImageFactory.getImage(IMAGE_WARNING_PATH);
89         }
90         if (severity == IMarker.SEVERITY_INFO) {
91             return ImageFactory.getImage(IMAGE_INFO_PATH);
92         }
93         return null;
94     }
95
96     /*
97      * (non-Javadoc)
98      * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
99      */

100     public int compare(Object JavaDoc obj1, Object JavaDoc obj2) {
101         if (obj1 == null || obj2 == null || !(obj1 instanceof ProblemMarker)
102                 || !(obj2 instanceof ProblemMarker)) {
103             return 0;
104         }
105
106         int severity1 = ((ProblemMarker) obj1).getSeverity();
107         int severity2 = ((ProblemMarker) obj2).getSeverity();
108         return severity1 - severity2;
109     }
110
111 }
112
Popular Tags