1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import org.eclipse.swt.graphics.Image; 14 15 import org.eclipse.jface.viewers.ITreeContentProvider; 16 17 import org.eclipse.jdt.core.IClassFile; 18 import org.eclipse.jdt.core.ICompilationUnit; 19 import org.eclipse.jdt.core.IJavaModel; 20 import org.eclipse.jdt.core.IType; 21 22 import org.eclipse.jdt.ui.JavaElementLabels; 23 24 import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; 25 import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; 26 27 public class PostfixLabelProvider extends SearchLabelProvider { 28 private ITreeContentProvider fContentProvider; 29 30 public PostfixLabelProvider(JavaSearchResultPage page) { 31 super(page); 32 fContentProvider= new LevelTreeContentProvider.FastJavaElementProvider(); 33 } 34 35 public Image getImage(Object element) { 36 Image image= super.getImage(element); 37 if (image != null) 38 return image; 39 return getParticipantImage(element); 40 } 41 42 public String getText(Object element) { 43 String labelWithCounts= getLabelWithCounts(element, internalGetText(element)); 44 return labelWithCounts + getQualification(element); 45 } 46 47 private String getQualification(Object element) { 48 StringBuffer res= new StringBuffer (); 49 50 ITreeContentProvider provider= (ITreeContentProvider) fPage.getViewer().getContentProvider(); 51 Object visibleParent= provider.getParent(element); 52 Object realParent= fContentProvider.getParent(element); 53 Object lastElement= element; 54 while (realParent != null && !(realParent instanceof IJavaModel) && !realParent.equals(visibleParent)) { 55 if (!isSameInformation(realParent, lastElement)) { 56 res.append(JavaElementLabels.CONCAT_STRING).append(internalGetText(realParent)); 57 } 58 lastElement= realParent; 59 realParent= fContentProvider.getParent(realParent); 60 } 61 return res.toString(); 62 } 63 64 protected boolean hasChildren(Object element) { 65 ITreeContentProvider contentProvider= (ITreeContentProvider) fPage.getViewer().getContentProvider(); 66 return contentProvider.hasChildren(element); 67 } 68 69 private String internalGetText(Object element) { 70 String text= super.getText(element); 71 if (text != null && text.length() > 0) 72 return text; 73 return getParticipantText(element); 74 } 75 76 private boolean isSameInformation(Object realParent, Object lastElement) { 77 if (lastElement instanceof IType) { 78 IType type= (IType) lastElement; 79 if (realParent instanceof IClassFile) { 80 if (type.getClassFile().equals(realParent)) 81 return true; 82 } else if (realParent instanceof ICompilationUnit) { 83 if (type.getCompilationUnit().equals(realParent)) 84 return true; 85 } 86 } 87 return false; 88 } 89 90 93 public ColoredString getRichTextLabel(Object element) { 94 ColoredString coloredString= getColoredLabelWithCounts(element, super.getRichTextLabel(element)); 95 coloredString.append(getQualification(element), ColoredJavaElementLabels.QUALIFIER_STYLE); 96 return coloredString; 97 } 98 99 } 100 | Popular Tags |