KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > callhierarchy > LocationLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10  * (report 36180: Callers/Callees view)
11  *******************************************************************************/

12 package org.eclipse.jdt.internal.ui.callhierarchy;
13
14 import org.eclipse.swt.graphics.Image;
15
16 import org.eclipse.jface.viewers.ITableLabelProvider;
17 import org.eclipse.jface.viewers.LabelProvider;
18
19 import org.eclipse.jdt.internal.ui.JavaPluginImages;
20
21 import org.eclipse.jdt.internal.corext.callhierarchy.CallLocation;
22
23 class LocationLabelProvider extends LabelProvider implements ITableLabelProvider {
24     private static final int COLUMN_ICON= 0;
25     private static final int COLUMN_LINE= 1;
26     private static final int COLUMN_INFO= 2;
27         
28     LocationLabelProvider() {
29         // Do nothing
30
}
31             
32     /* (non-Javadoc)
33      * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
34      */

35     public String JavaDoc getText(Object JavaDoc element) {
36         return getColumnText(element, COLUMN_INFO);
37     }
38
39     public Image getImage(Object JavaDoc element) {
40         return getColumnImage(element, COLUMN_ICON);
41     }
42     
43     private String JavaDoc removeWhitespaceOutsideStringLiterals(CallLocation callLocation) {
44         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
45         boolean withinString = false;
46
47         String JavaDoc s= callLocation.getCallText();
48         for (int i = 0; i < s.length(); i++) {
49             char ch = s.charAt(i);
50
51             if (ch == '"') {
52                 withinString = !withinString;
53             }
54
55             if (withinString) {
56                 buf.append(ch);
57             } else if (Character.isWhitespace(ch)) {
58                 if ((buf.length() == 0) ||
59                             !Character.isWhitespace(buf.charAt(buf.length() - 1))) {
60                     if (ch != ' ') {
61                         ch = ' ';
62                     }
63
64                     buf.append(ch);
65                 }
66             } else {
67                 buf.append(ch);
68             }
69         }
70
71         return buf.toString();
72     }
73
74     /* (non-Javadoc)
75      * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
76      */

77     public Image getColumnImage(Object JavaDoc element, int columnIndex) {
78         if (columnIndex == COLUMN_ICON) {
79             return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_SEARCH_OCCURRENCE);
80         }
81         return null;
82     }
83
84     /* (non-Javadoc)
85      * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
86      */

87     public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
88         if (element instanceof CallLocation) {
89             CallLocation callLocation= (CallLocation) element;
90             
91             switch (columnIndex) {
92                 case COLUMN_LINE:
93                     int lineNumber= callLocation.getLineNumber();
94                     if (lineNumber == CallLocation.UNKNOWN_LINE_NUMBER) {
95                         return CallHierarchyMessages.LocationLabelProvider_unknown;
96                     } else {
97                         return String.valueOf(lineNumber);
98                     }
99                 case COLUMN_INFO:
100                     return removeWhitespaceOutsideStringLiterals(callLocation);
101             }
102         }
103
104         return ""; //$NON-NLS-1$
105
}
106 }
107
Popular Tags