1 12 package org.eclipse.jdt.internal.ui.callhierarchy; 13 14 import java.util.Collection ; 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 45 public Image getImage(Object 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 65 public String getText(Object element) { 66 if (element instanceof MethodWrapper && ((MethodWrapper) element).getMember() != null) { 67 return getElementLabel((MethodWrapper) element); 68 } 69 return getSpecialLabel(element); 70 } 71 72 75 public ColoredString getRichTextLabel(Object element) { 76 if (element instanceof MethodWrapper && ((MethodWrapper) element).getMember() != null) { 77 MethodWrapper wrapper= (MethodWrapper) element; 78 String 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 getSpecialLabel(Object 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 element) { 97 return element instanceof IWorkbenchAdapter; 98 } 99 100 private String getElementLabel(MethodWrapper methodWrapper) { 101 String label = super.getText(methodWrapper.getMember()); 102 103 Collection callLocations = methodWrapper.getMethodCall().getCallLocations(); 104 105 if ((callLocations != null) && (callLocations.size() > 1)) { 106 return Messages.format(CallHierarchyMessages.CallHierarchyLabelProvider_matches, new String []{label, String.valueOf(callLocations.size())}); 107 } 108 109 return label; 110 } 111 } 112 | Popular Tags |