KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.resources.IMarker;
15 import org.eclipse.jface.resource.JFaceResources;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
18
19 /**
20  * The FieldPriority is the field for setting a tasks
21  * priority.
22  *
23  */

24 public class FieldPriority extends AbstractField {
25
26     static final String JavaDoc DESCRIPTION_IMAGE_PATH = "obj16/header_priority.gif"; //$NON-NLS-1$
27

28     static final String JavaDoc HIGH_PRIORITY_IMAGE_PATH = "obj16/hprio_tsk.gif"; //$NON-NLS-1$
29

30     static final String JavaDoc LOW_PRIORITY_IMAGE_PATH = "obj16/lprio_tsk.gif"; //$NON-NLS-1$
31

32     private String JavaDoc description;
33
34     /**
35      * Return a new instance of the receiver.
36      */

37     public FieldPriority() {
38         description = MarkerMessages.priority_description;
39     }
40
41     /*
42      * (non-Javadoc)
43      * @see org.eclipse.ui.views.markers.internal.IField#getDescription()
44      */

45     public String JavaDoc getDescription() {
46         return description;
47     }
48     
49     /**
50      * Get the image at path.
51      * @param path
52      * @return Image
53      */

54     private Image getImage(String JavaDoc path){
55         return JFaceResources.getResources().createImageWithDefault(
56                 IDEWorkbenchPlugin
57                         .getIDEImageDescriptor(path));
58         
59     }
60
61     /*
62      * (non-Javadoc)
63      * @see org.eclipse.ui.views.markers.internal.IField#getDescriptionImage()
64      */

65     public Image getDescriptionImage() {
66         return getImage(DESCRIPTION_IMAGE_PATH);
67     }
68
69     /*
70      * (non-Javadoc)
71      * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderText()
72      */

73     public String JavaDoc getColumnHeaderText() {
74         return ""; //$NON-NLS-1$
75
}
76
77     /*
78      * (non-Javadoc)
79      * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderImage()
80      */

81     public Image getColumnHeaderImage() {
82         return getDescriptionImage();
83     }
84
85     /*
86      * (non-Javadoc)
87      * @see org.eclipse.ui.views.markers.internal.IField#getValue(java.lang.Object)
88      */

89     public String JavaDoc getValue(Object JavaDoc obj) {
90         return ""; //$NON-NLS-1$
91
}
92
93     /*
94      * (non-Javadoc)
95      * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
96      */

97     public Image getImage(Object JavaDoc obj) {
98         if (obj == null || !(obj instanceof TaskMarker)) {
99             return null;
100         }
101         try {
102             int priority = ((TaskMarker) obj).getPriority();
103             if (priority == IMarker.PRIORITY_HIGH) {
104                 return getImage(HIGH_PRIORITY_IMAGE_PATH);
105             }
106             if (priority == IMarker.PRIORITY_LOW) {
107                 return getImage(LOW_PRIORITY_IMAGE_PATH);
108             }
109         } catch (NumberFormatException JavaDoc e) {
110             return null;
111         }
112         return null;
113     }
114
115     /*
116      * (non-Javadoc)
117      * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
118      */

119     public int compare(Object JavaDoc obj1, Object JavaDoc obj2) {
120         if (obj1 == null || obj2 == null || !(obj1 instanceof TaskMarker)
121                 || !(obj2 instanceof TaskMarker)) {
122             return 0;
123         }
124         int priority1 = ((TaskMarker) obj1).getPriority();
125         int priority2 = ((TaskMarker) obj2).getPriority();
126         return priority1 - priority2;
127     }
128     
129     /* (non-Javadoc)
130      * @see org.eclipse.ui.views.markers.internal.IField#getDefaultDirection()
131      */

132     public int getDefaultDirection() {
133         return TableComparator.DESCENDING;
134     }
135     
136     /* (non-Javadoc)
137      * @see org.eclipse.ui.views.markers.internal.IField#getPreferredWidth()
138      */

139     public int getPreferredWidth() {
140         return 16;
141     }
142 }
143
Popular Tags