1 11 package org.eclipse.search.internal.ui; 12 13 import org.eclipse.swt.graphics.Image; 14 15 import org.eclipse.jface.viewers.ILabelProvider; 16 import org.eclipse.jface.viewers.ILabelProviderListener; 17 import org.eclipse.jface.viewers.LabelProvider; 18 19 import org.eclipse.ui.PlatformUI; 20 21 import org.eclipse.search.ui.ISearchResultViewEntry; 22 23 26 class SearchResultLabelProvider extends LabelProvider { 27 28 private static final String MATCHES_POSTFIX= " " + SearchMessages.SearchResultView_matches + ")"; 30 private ILabelProvider fLabelProvider; 31 32 33 SearchResultLabelProvider(ILabelProvider provider) { 34 fLabelProvider= provider; 35 } 36 37 public String getText(Object element) { 38 StringBuffer buf= new StringBuffer (getLabelProvider().getText(element)); 39 int count= ((ISearchResultViewEntry)element).getMatchCount(); 40 if (count > 1) { 41 buf.append(" ("); buf.append(count); 43 buf.append(MATCHES_POSTFIX); 44 } 45 return buf.toString(); 46 } 47 48 public Image getImage(Object element) { 49 return fLabelProvider.getImage(element); 50 } 51 52 public void dispose() { 54 } 55 56 ILabelProvider getLabelProvider() { 57 return fLabelProvider; 58 } 59 60 public void addListener(ILabelProviderListener listener) { 61 super.addListener(listener); 62 fLabelProvider.addListener(listener); 63 PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator().addListener(listener); 64 } 65 66 public boolean isLabelProperty(Object element, String property) { 67 return fLabelProvider.isLabelProperty(element, property); 68 } 69 70 public void removeListener(ILabelProviderListener listener) { 71 super.removeListener(listener); 72 fLabelProvider.removeListener(listener); 73 PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator().removeListener(listener); 74 } 75 } 76 | Popular Tags |