1 11 package org.eclipse.search.internal.ui; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IConfigurationElement; 15 import org.eclipse.core.runtime.Path; 16 import org.eclipse.core.runtime.Platform; 17 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.viewers.ViewerSorter; 20 21 import org.eclipse.search.internal.ui.util.ExceptionHandler; 22 23 import org.osgi.framework.Bundle; 24 25 28 class SorterDescriptor { 29 30 public final static String SORTER_TAG= "sorter"; private final static String ID_ATTRIBUTE= "id"; private final static String PAGE_ID_ATTRIBUTE= "pageId"; private final static String ICON_ATTRIBUTE= "icon"; private final static String CLASS_ATTRIBUTE= "class"; private final static String LABEL_ATTRIBUTE= "label"; private final static String TOOLTIP_ATTRIBUTE= "tooltip"; 38 private IConfigurationElement fElement; 39 40 45 public SorterDescriptor(IConfigurationElement element) { 46 fElement= element; 47 } 48 49 52 public ViewerSorter createObject() { 53 try { 54 return (ViewerSorter)fElement.createExecutableExtension(CLASS_ATTRIBUTE); 55 } catch (CoreException ex) { 56 ExceptionHandler.handle(ex, SearchMessages.Search_Error_createSorter_title, SearchMessages.Search_Error_createSorter_message); 57 return null; 58 } catch (ClassCastException ex) { 59 ExceptionHandler.displayMessageDialog(ex, SearchMessages.Search_Error_createSorter_title, SearchMessages.Search_Error_createSorter_message); 60 return null; 61 } 62 } 63 64 66 69 public String getId() { 70 return fElement.getAttribute(ID_ATTRIBUTE); 71 } 72 73 76 public ImageDescriptor getImage() { 77 String imageName= fElement.getAttribute(ICON_ATTRIBUTE); 78 if (imageName == null) 79 return null; 80 Bundle bundle = Platform.getBundle(fElement.getContributor().getName()); 81 return SearchPluginImages.createImageDescriptor(bundle, new Path(imageName), true); 82 } 83 84 87 public String getLabel() { 88 return fElement.getAttribute(LABEL_ATTRIBUTE); 89 } 90 91 94 public String getToolTipText() { 95 return fElement.getAttribute(TOOLTIP_ATTRIBUTE); 96 } 97 98 101 public String getPageId() { 102 return fElement.getAttribute(PAGE_ID_ATTRIBUTE); 103 } 104 } 105 | Popular Tags |