KickJava   Java API By Example, From Geeks To Geeks.

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


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.osgi.util.NLS;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.ui.model.IWorkbenchAdapter;
18
19 /**
20  * FieldLineNumber is the field for line numbers.
21  *
22  */

23 public class FieldLineNumber extends AbstractField {
24
25     private String JavaDoc description;
26
27     private Image image;
28
29     /**
30      * Create a new instance of the receiver.
31      */

32     public FieldLineNumber() {
33         description = MarkerMessages.description_lineNumber;
34     }
35
36     /*
37      * (non-Javadoc)
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      * @see org.eclipse.ui.views.markers.internal.IField#getDescriptionImage()
47      */

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

56     public String JavaDoc getColumnHeaderText() {
57         return description;
58     }
59
60     /*
61      * (non-Javadoc)
62      * @see org.eclipse.ui.views.markers.internal.IField#getColumnHeaderImage()
63      */

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

72     public String JavaDoc getValue(Object JavaDoc obj) {
73         if (obj == null) {
74             return MarkerMessages.FieldMessage_NullMessage;
75         }
76
77         if (obj instanceof MarkerNode){
78             MarkerNode node = (MarkerNode) obj;
79             if(node.isConcrete()){
80                 ConcreteMarker concreteNode = (ConcreteMarker) node;
81                 if(concreteNode.getLocationString().length() == 0){
82                     if (concreteNode.getLine() < 0) {
83                         return MarkerMessages.Unknown;
84                     }
85                     return NLS.bind(
86                             MarkerMessages.label_lineNumber,
87                             Integer.toString(concreteNode.getLine()));
88                 }
89                 return concreteNode.getLocationString();
90             }
91             return Util.EMPTY_STRING;
92         }
93         
94         if(obj instanceof IWorkbenchAdapter) {
95             return Util.EMPTY_STRING;//Don't show pending
96
}
97         
98         if(obj instanceof IMarker) {
99             return Util.getProperty(IMarker.LINE_NUMBER, (IMarker) obj);
100         }
101         
102         return NLS.bind(MarkerMessages.FieldMessage_WrongType,obj.toString());
103         
104     }
105
106     /*
107      * (non-Javadoc)
108      * @see org.eclipse.ui.views.markers.internal.IField#getImage(java.lang.Object)
109      */

110     public Image getImage(Object JavaDoc obj) {
111         return null;
112     }
113
114     /*
115      * (non-Javadoc)
116      * @see org.eclipse.ui.views.markers.internal.IField#compare(java.lang.Object, java.lang.Object)
117      */

118     public int compare(Object JavaDoc obj1, Object JavaDoc obj2) {
119         if (obj1 == null || obj2 == null || !(obj1 instanceof ConcreteMarker)
120                 || !(obj2 instanceof ConcreteMarker)) {
121             return 0;
122         }
123
124         ConcreteMarker marker1 = (ConcreteMarker) obj1;
125         ConcreteMarker marker2 = (ConcreteMarker) obj2;
126         
127         String JavaDoc location1 = marker1.getLocationString();
128         String JavaDoc location2 = marker2.getLocationString();
129         
130         if(location1.length() == 0 || location2.length() == 0) {
131             return marker1.getLine() - marker2.getLine();
132         }
133         
134         return location1.compareTo(location2);
135     }
136
137     /* (non-Javadoc)
138      * @see org.eclipse.ui.views.markers.internal.IField#getDefaultDirection()
139      */

140     public int getDefaultDirection() {
141         return TableComparator.ASCENDING;
142     }
143     
144     /* (non-Javadoc)
145      * @see org.eclipse.ui.views.markers.internal.IField#getPreferredWidth()
146      */

147     public int getPreferredWidth() {
148         return 60;
149     }
150 }
151
Popular Tags