1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import org.eclipse.core.resources.IResource; 14 15 import org.eclipse.swt.graphics.Image; 16 17 import org.eclipse.jdt.core.IImportDeclaration; 18 import org.eclipse.jdt.core.IJavaElement; 19 20 import org.eclipse.jdt.ui.JavaElementLabels; 21 22 import org.eclipse.jdt.internal.ui.viewsupport.ColoredJavaElementLabels; 23 import org.eclipse.jdt.internal.ui.viewsupport.ColoredString; 24 25 public class SortingLabelProvider extends SearchLabelProvider { 26 27 public static final int SHOW_ELEMENT_CONTAINER= 1; public static final int SHOW_CONTAINER_ELEMENT= 2; 29 public static final int SHOW_PATH= 3; 30 31 private static final long FLAGS_QUALIFIED= DEFAULT_SEARCH_TEXTFLAGS | JavaElementLabels.F_FULLY_QUALIFIED | JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.I_FULLY_QUALIFIED 32 | JavaElementLabels.T_FULLY_QUALIFIED | JavaElementLabels.D_QUALIFIED | JavaElementLabels.CF_QUALIFIED | JavaElementLabels.CU_QUALIFIED | ColoredJavaElementLabels.COLORIZE; 33 34 35 private int fCurrentOrder; 36 37 public SortingLabelProvider(JavaSearchResultPage page) { 38 super(page); 39 fCurrentOrder= SHOW_ELEMENT_CONTAINER; 40 } 41 42 public Image getImage(Object element) { 43 Image image= null; 44 if (element instanceof IJavaElement || element instanceof IResource) 45 image= super.getImage(element); 46 if (image != null) 47 return image; 48 return getParticipantImage(element); 49 } 50 51 public final String getText(Object element) { 52 if (element instanceof IImportDeclaration) 53 element= ((IImportDeclaration)element).getParent().getParent(); 54 55 String text= super.getText(element); 56 if (text.length() > 0) { 57 String labelWithCount= getLabelWithCounts(element, text); 58 if (fCurrentOrder == SHOW_ELEMENT_CONTAINER) { 59 labelWithCount += getPostQualification(element, text); 60 } 61 return labelWithCount; 62 } 63 return getParticipantText(element); 64 } 65 66 69 public ColoredString getRichTextLabel(Object element) { 70 if (element instanceof IImportDeclaration) 71 element= ((IImportDeclaration)element).getParent().getParent(); 72 73 ColoredString text= super.getRichTextLabel(element); 74 if (text.length() > 0) { 75 ColoredString countLabel= getColoredLabelWithCounts(element, text); 76 if (fCurrentOrder == SHOW_ELEMENT_CONTAINER) { 77 countLabel.append(getPostQualification(element, text.getString()), ColoredJavaElementLabels.QUALIFIER_STYLE); 78 } 79 return countLabel; 80 } 81 return new ColoredString(getParticipantText(element)); 82 } 83 84 private String getPostQualification(Object element, String text) { 85 String textLabel= JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_POST_QUALIFIED); 86 int indexOf= textLabel.indexOf(JavaElementLabels.CONCAT_STRING); 87 if (indexOf != -1) { 88 return textLabel.substring(indexOf); 89 } 90 return new String (); 91 } 92 93 public void setOrder(int orderFlag) { 94 fCurrentOrder= orderFlag; 95 long flags= 0; 96 if (orderFlag == SHOW_ELEMENT_CONTAINER) 97 flags= DEFAULT_SEARCH_TEXTFLAGS; 98 else if (orderFlag == SHOW_CONTAINER_ELEMENT) 99 flags= FLAGS_QUALIFIED; 100 else if (orderFlag == SHOW_PATH) { 101 flags= FLAGS_QUALIFIED | JavaElementLabels.PREPEND_ROOT_PATH; 102 } 103 setTextFlags(flags); 104 } 105 } 106 | Popular Tags |