KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > search > OccurrencesInFileLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.search;
13
14 import org.eclipse.core.resources.IMarker;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jdt.internal.ui.JavaPluginImages;
17 import org.eclipse.swt.graphics.Image;
18
19 /**
20  * Label provider for the <code>FindOccurrencesInFile</code> results.
21  * @see org.eclipse.jdt.ui.actions.FindOccurrencesInFileAction
22  */

23 class OccurrencesInFileLabelProvider extends JavaSearchResultLabelProvider {
24
25     public String JavaDoc getText(Object JavaDoc o) {
26         IMarker marker= getMarker(o);
27         try {
28             String JavaDoc text= (String JavaDoc)marker.getAttribute(IMarker.MESSAGE);
29             if (text != null)
30                 return text.replace('\t', ' ');
31         } catch (CoreException ex) {
32             return ""; //$NON-NLS-1$
33
}
34         return super.getText(o);
35     }
36     
37     public Image getImage(Object JavaDoc element) {
38         IMarker marker= getMarker(element);
39         if (isVariableAccess(marker)) {
40             if (isWriteAccess(marker))
41                 return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SEARCH_WRITEACCESS);
42             return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SEARCH_READACCESS);
43         }
44         return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SEARCH_OCCURRENCE);
45     }
46     
47     private boolean isWriteAccess(IMarker marker) {
48         Boolean JavaDoc write= null;
49         boolean writeValue= false;
50         try {
51             write= (Boolean JavaDoc)marker.getAttribute(OccurrencesFinder.IS_WRITEACCESS);
52             writeValue= write != null && write.booleanValue();
53         } catch (CoreException e) {
54         }
55         return writeValue;
56     }
57     
58     private boolean isVariableAccess(IMarker marker) {
59         Boolean JavaDoc variable= null;
60         boolean variableValue= false;
61         try {
62             variable= (Boolean JavaDoc)marker.getAttribute(OccurrencesFinder.IS_VARIABLE);
63             variableValue= variable != null && variable.booleanValue();
64         } catch (CoreException e) {
65         }
66         return variableValue;
67     }
68 }
69
Popular Tags