KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jface.resource.DeviceResourceException;
15 import org.eclipse.jface.resource.JFaceResources;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
18
19 /**
20  * The FieldSeverityAndMessage is the field that
21  * displays severities and messages.
22  *
23  */

24 public class FieldSeverityAndMessage extends FieldMessage {
25
26     private String JavaDoc description;
27
28     /**
29      * Create a new instance of the receiver.
30      */

31     public FieldSeverityAndMessage() {
32         description = MarkerMessages.problemSeverity_description;
33     }
34
35     /*
36      * (non-Javadoc)
37      *
38      * @see org.eclipse.ui.views.markers.internal.IField#getDescription()
39      */

40     public String JavaDoc getDescription() {
41         return description;
42     }
43
44     /*
45      * (non-Javadoc)
46      *
47      * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
48      */

49     public Image getImage(Object JavaDoc obj) {
50         if (obj == null || !(obj instanceof MarkerNode)) {
51             return null;
52         }
53
54         MarkerNode node = (MarkerNode) obj;
55         if (node.isConcrete()) {
56             if (node instanceof ProblemMarker) {
57                 return Util.getImage(((ProblemMarker) obj).getSeverity());
58             }
59             return null;
60         }
61
62         try {
63             return JFaceResources
64                     .getResources()
65                     .createImage(
66                             IDEInternalWorkbenchImages
67                                     .getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_PROBLEM_CATEGORY));
68         } catch (DeviceResourceException e) {
69             return null;
70         }
71     }
72
73     /*
74      * (non-Javadoc)
75      *
76      * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object,
77      * java.lang.Object)
78      */

79     public int compare(Object JavaDoc obj1, Object JavaDoc obj2) {
80         if (obj1 == null || obj2 == null || !(obj1 instanceof ProblemMarker)
81                 || !(obj2 instanceof ProblemMarker)) {
82             return 0;
83         }
84         
85         ProblemMarker marker1 = (ProblemMarker) obj1;
86         ProblemMarker marker2 = (ProblemMarker) obj2;
87
88         int severity1 = marker1.getSeverity();
89         int severity2 = marker2.getSeverity();
90         if(severity1 == severity2)
91             return marker1.getDescriptionKey().compareTo(
92                     marker2.getDescriptionKey());
93         return severity2 - severity1;
94     }
95     
96     /*
97      * (non-Javadoc)
98      *
99      * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderImage()
100      */

101     public Image getColumnHeaderImage() {
102         return getImage(FieldDone.DESCRIPTION_IMAGE_PATH);
103     }
104
105
106 }
107
Popular Tags