KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 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 package org.eclipse.ui.views.markers.internal;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.swt.graphics.Image;
15
16 /**
17  * FieldCategory is the field for showing categories of markers.
18  *
19  */

20 public class FieldCategory extends AbstractField {
21
22     /*
23      * (non-Javadoc)
24      *
25      * @see org.eclipse.ui.views.markers.internal.IField#getDescription()
26      */

27     public String JavaDoc getDescription() {
28         return MarkerMessages.description_type;
29     }
30
31     /*
32      * (non-Javadoc)
33      *
34      * @see org.eclipse.ui.views.markers.internal.IField#getDescriptionImage()
35      */

36     public Image getDescriptionImage() {
37         return null;
38     }
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderText()
44      */

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

54     public Image getColumnHeaderImage() {
55         return null;
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see org.eclipse.ui.views.markers.internal.IField#getValue(java.lang.Object)
62      */

63     public String JavaDoc getValue(Object JavaDoc obj) {
64
65         if (obj instanceof ConcreteMarker) {
66             ConcreteMarker marker = (ConcreteMarker) obj;
67
68             if (marker.getGroup() == null) {
69                 if (!marker.getMarker().exists())
70                     return MarkerMessages.FieldCategory_Uncategorized;
71                 String JavaDoc groupName = MarkerSupportRegistry.getInstance()
72                         .getCategory(marker.getMarker());
73                 if (groupName == null) {
74
75                     String JavaDoc typeId;
76                     try {
77                         typeId = marker.getMarker().getType();
78                     } catch (CoreException e) {
79                         Util.log(e);
80                         return MarkerMessages.FieldCategory_Uncategorized;
81                     }
82                     MarkerType type = MarkerTypesModel.getInstance().getType(
83                             typeId);
84                     groupName = type.getLabel();
85                 }
86                 marker.setGroup(groupName);
87             }
88
89             return (String JavaDoc) marker.getGroup();
90
91         }
92         return Util.EMPTY_STRING;
93     }
94
95     /*
96      * (non-Javadoc)
97      *
98      * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
99      */

100     public Image getImage(Object JavaDoc obj) {
101         return null;
102     }
103
104     /*
105      * (non-Javadoc)
106      *
107      * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object,
108      * java.lang.Object)
109      */

110     public int compare(Object JavaDoc obj1, Object JavaDoc obj2) {
111         return getValue(obj1).compareTo(getValue(obj2));
112     }
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see org.eclipse.ui.views.markers.internal.IField#getDefaultDirection()
118      */

119     public int getDefaultDirection() {
120         return TableComparator.ASCENDING;
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see org.eclipse.ui.views.markers.internal.IField#getPreferredWidth()
127      */

128     public int getPreferredWidth() {
129         return 200;
130     }
131
132 }
133
Popular Tags