KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 java.util.Collection JavaDoc;
15
16 import org.eclipse.swt.graphics.Image;
17
18 import org.eclipse.jface.viewers.ILabelDecorator;
19
20 import org.eclipse.ui.model.IWorkbenchAdapter;
21
22 import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper;
23 import org.eclipse.jdt.internal.corext.util.Messages;
24
25 import org.eclipse.jdt.ui.JavaElementLabels;
26
27 import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
28 import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels;
29 import org.eclipse.jdt.internal.ui.viewsupport.ColoredString;
30 import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
31
32 class CallHierarchyLabelProvider extends AppearanceAwareLabelProvider {
33     private static final long TEXTFLAGS= DEFAULT_TEXTFLAGS | JavaElementLabels.ALL_POST_QUALIFIED | JavaElementLabels.P_COMPRESSED;
34     private static final int IMAGEFLAGS= DEFAULT_IMAGEFLAGS | JavaElementImageProvider.SMALL_ICONS;
35
36     private ILabelDecorator fDecorator;
37     
38     CallHierarchyLabelProvider() {
39         super(TEXTFLAGS, IMAGEFLAGS);
40         fDecorator= new CallHierarchyLabelDecorator();
41     }
42     /*
43      * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
44      */

45     public Image getImage(Object JavaDoc element) {
46         Image result= null;
47         if (element instanceof MethodWrapper) {
48             MethodWrapper methodWrapper = (MethodWrapper) element;
49
50             if (methodWrapper.getMember() != null) {
51                 result= fDecorator.decorateImage(super.getImage(methodWrapper.getMember()), methodWrapper);
52             }
53         } else if (isPendingUpdate(element)) {
54             return null;
55         } else {
56             result= super.getImage(element);
57         }
58         
59         return result;
60     }
61
62     /*
63      * @see ILabelProvider#getText(Object)
64      */

65     public String JavaDoc getText(Object JavaDoc element) {
66         if (element instanceof MethodWrapper && ((MethodWrapper) element).getMember() != null) {
67             return getElementLabel((MethodWrapper) element);
68         }
69         return getSpecialLabel(element);
70     }
71     
72     /* (non-Javadoc)
73      * @see org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider#getRichTextLabel(java.lang.Object)
74      */

75     public ColoredString getRichTextLabel(Object JavaDoc element) {
76         if (element instanceof MethodWrapper && ((MethodWrapper) element).getMember() != null) {
77             MethodWrapper wrapper= (MethodWrapper) element;
78             String JavaDoc decorated= getElementLabel(wrapper);
79             ColoredString text= super.getRichTextLabel(wrapper.getMember());
80             return ColoredJavaElementLabels.decorateColoredString(text, decorated, ColoredJavaElementLabels.COUNTER_STYLE);
81         }
82         return new ColoredString(getSpecialLabel(element));
83     }
84     
85     private String JavaDoc getSpecialLabel(Object JavaDoc element) {
86         if (element instanceof MethodWrapper) {
87             return CallHierarchyMessages.CallHierarchyLabelProvider_root;
88         } else if (element == TreeTermination.SEARCH_CANCELED) {
89             return CallHierarchyMessages.CallHierarchyLabelProvider_searchCanceled;
90         } else if (isPendingUpdate(element)) {
91             return CallHierarchyMessages.CallHierarchyLabelProvider_updatePending;
92         }
93         return CallHierarchyMessages.CallHierarchyLabelProvider_noMethodSelected;
94     }
95     
96     private boolean isPendingUpdate(Object JavaDoc element) {
97         return element instanceof IWorkbenchAdapter;
98     }
99     
100     private String JavaDoc getElementLabel(MethodWrapper methodWrapper) {
101         String JavaDoc label = super.getText(methodWrapper.getMember());
102
103         Collection JavaDoc callLocations = methodWrapper.getMethodCall().getCallLocations();
104
105         if ((callLocations != null) && (callLocations.size() > 1)) {
106             return Messages.format(CallHierarchyMessages.CallHierarchyLabelProvider_matches, new String JavaDoc[]{label, String.valueOf(callLocations.size())});
107         }
108
109         return label;
110     }
111 }
112
Popular Tags