1 11 package org.eclipse.ui.internal.navigator; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.jface.viewers.ILabelProvider; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.ui.navigator.ICommonLabelProvider; 18 import org.eclipse.ui.navigator.IDescriptionProvider; 19 20 32 public final class NavigatorContentServiceDescriptionProvider implements 33 IDescriptionProvider { 34 35 private final NavigatorContentService contentService; 36 37 43 public NavigatorContentServiceDescriptionProvider( 44 NavigatorContentService aContentService) { 45 Assert.isNotNull(aContentService); 46 contentService = aContentService; 47 } 48 49 public String getDescription(Object anElement) { 50 51 Object target; 52 53 if (anElement instanceof IStructuredSelection) { 54 55 IStructuredSelection structuredSelection = (IStructuredSelection) anElement; 56 if (structuredSelection.size() > 1) { 57 return getDefaultStatusBarMessage(structuredSelection.size()); 58 } 59 target = structuredSelection.getFirstElement(); 60 } else { 61 target = anElement; 62 } 63 String message = null; 64 ILabelProvider[] providers = contentService 65 .findRelevantLabelProviders(target); 66 if (providers.length == 0) { 67 return getDefaultStatusBarMessage(0); 68 } 69 for (int i = 0; i < providers.length && (message == null || message.length() == 0); i++) { 70 if (providers[i] instanceof ICommonLabelProvider) { 71 message = ((ICommonLabelProvider) providers[i]) 72 .getDescription(target); 73 } 74 } 75 message = (message != null) ? message : getDefaultStatusBarMessage(1); 76 return message; 77 78 } 79 80 85 protected final String getDefaultStatusBarMessage(int aSize) { 86 return NLS.bind( 87 CommonNavigatorMessages.Navigator_statusLineMultiSelect, 88 new Object [] { new Integer (aSize) }); 89 90 } 91 92 } 93 | Popular Tags |