KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.eclipse.ui.views.markers.internal;
12
13 import com.ibm.icu.text.CollationKey;
14 import com.ibm.icu.text.Collator;
15
16 import org.eclipse.core.resources.IMarker;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.runtime.CoreException;
19
20 /**
21  * This is a concrete class that stores the same type of information as the IMarkers
22  * used by the IDE. This class exists as an optimization. The various get* methods
23  * on IMarker are extremely slow, which makes it very slow to sort markers (for example,
24  * in the problems view). This marker class stores the fields in the most efficient form
25  * for sorting and display, but necessarily removes some generality from IMarker.
26  */

27 public class ConcreteMarker extends MarkerNode{
28
29     private String JavaDoc description;
30
31     private String JavaDoc resourceName;
32
33     private String JavaDoc inFolder;
34
35     private CollationKey descriptionKey;
36
37     private CollationKey resourceNameKey;
38
39     private int line;
40     
41     private String JavaDoc locationString;
42
43     private long creationTime;
44
45     private String JavaDoc type;
46
47     private IMarker marker;
48
49     /**
50      * Cache for the marker ID.
51      */

52     private long id = -1L;
53
54     private MarkerNode markerCategory;
55
56     private String JavaDoc shortFolder;
57     
58     private Object JavaDoc group;
59
60     public ConcreteMarker(IMarker toCopy) {
61         marker = toCopy;
62         refresh();
63     }
64
65     /**
66      * Clears any cached information. This frees up some memory, but will slow down
67      * the next comparison operation. It is a good idea to call this on a set of markers
68      * after sorting them, in order to reduce their memory cost.
69      */

70     public void clearCache() {
71         resourceNameKey = null;
72         descriptionKey = null;
73     }
74
75     /**
76      * Refresh the properties of this marker from the underlying IMarker instance
77      */

78     public void refresh() {
79         clearCache();
80
81         description = Util.getProperty(IMarker.MESSAGE, marker);
82         resourceName = Util.getResourceName(marker);
83         inFolder = Util.getContainerName(marker);
84         shortFolder = null;
85         line = marker.getAttribute(IMarker.LINE_NUMBER, -1);
86         locationString = marker.getAttribute(IMarker.LOCATION,
87                 Util.EMPTY_STRING);
88         
89         try {
90             creationTime = marker.getCreationTime();
91         } catch (CoreException e) {
92             creationTime = 0;
93         }
94
95         try {
96             type = marker.getType();
97         } catch (CoreException e1) {
98             type = Util.EMPTY_STRING;
99         }
100         
101         // store the marker ID locally
102
id = marker.getId();
103     }
104
105     public IResource getResource() {
106         return marker.getResource();
107     }
108
109     public String JavaDoc getType() {
110         return type;
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.ui.views.markers.internal.MarkerNode#getDescription()
115      */

116     public String JavaDoc getDescription() {
117         return description;
118     }
119
120     public CollationKey getDescriptionKey() {
121         if (descriptionKey == null) {
122             descriptionKey = Collator.getInstance()
123                     .getCollationKey(description);
124         }
125
126         return descriptionKey;
127     }
128
129     public String JavaDoc getResourceName() {
130         return resourceName;
131     }
132
133     public CollationKey getResourceNameKey() {
134         if (resourceNameKey == null) {
135             resourceNameKey = Collator.getInstance().getCollationKey(
136                     resourceName);
137         }
138         return resourceNameKey;
139     }
140
141     public int getLine() {
142         return line;
143     }
144
145     public String JavaDoc getFolder() {
146         return inFolder;
147     }
148
149     public long getCreationTime() {
150         return creationTime;
151     }
152     
153     /**
154      * The underlying marker ID value.
155      * @return the marker's ID.
156      */

157     public long getId() {
158         return id;
159     }
160
161     public IMarker getMarker() {
162         return marker;
163     }
164
165     public boolean equals(Object JavaDoc object) {
166         if (!(object instanceof ConcreteMarker)) {
167             return false;
168         }
169
170         ConcreteMarker other = (ConcreteMarker) object;
171
172         return other.getMarker().equals(getMarker());
173     }
174
175     public int hashCode() {
176         return getMarker().hashCode();
177     }
178
179     /**
180      * Set the category the receiver is in.
181      * @param category
182      */

183     public void setCategory(MarkerNode category) {
184         markerCategory = category;
185         
186     }
187
188     /* (non-Javadoc)
189      * @see org.eclipse.ui.views.markers.internal.MarkerNode#getChildren()
190      */

191     public MarkerNode[] getChildren() {
192         return Util.EMPTY_MARKER_ARRAY;
193     }
194
195     /* (non-Javadoc)
196      * @see org.eclipse.ui.views.markers.internal.MarkerNode#getParent()
197      */

198     public MarkerNode getParent() {
199         return markerCategory;
200     }
201
202     /* (non-Javadoc)
203      * @see org.eclipse.ui.views.markers.internal.MarkerNode#isConcrete()
204      */

205     public boolean isConcrete() {
206         return true;
207     }
208
209     /**
210      * Return the short name for the folder.
211      * @return String
212      */

213     public String JavaDoc getShortFolder() {
214         if(shortFolder == null) {
215             shortFolder = Util.getShortContainerName(marker);
216         }
217         return shortFolder;
218     }
219
220
221     /**
222      * Get the location string. If the {@link IMarker#LOCATION }
223      * attribute was not set then return an empty String.
224      * @return String
225      */

226     public String JavaDoc getLocationString() {
227         return locationString;
228     }
229
230
231     /**
232      * Get the group for the reciever.
233      * @return Returns the group.
234      */

235     public Object JavaDoc getGroup() {
236         return group;
237     }
238
239     /**
240      * Set the group name.
241      * @param group the group name
242      */

243     public void setGroup(Object JavaDoc group) {
244         this.group = group;
245     }
246     
247     /* (non-Javadoc)
248      * @see org.eclipse.ui.views.markers.internal.MarkerNode#getConcreteRepresentative()
249      */

250     public ConcreteMarker getConcreteRepresentative() {
251         return this;
252     }
253 }
254
Popular Tags