1 11 package org.eclipse.debug.internal.ui.sourcelookup; 12 13 import java.util.Hashtable ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.IExtensionPoint; 18 import org.eclipse.core.runtime.Platform; 19 import org.eclipse.debug.internal.ui.DebugPluginImages; 20 import org.eclipse.debug.internal.ui.DebugUIPlugin; 21 import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser; 22 import org.eclipse.jface.resource.ImageDescriptor; 23 import org.eclipse.jface.resource.ImageRegistry; 24 import org.eclipse.swt.graphics.Image; 25 26 31 public class SourceLookupUIUtils { 32 36 public static final String CONTAINER_PRESENTATION_EXTENSION = "sourceContainerPresentations"; 41 public static final String ICON_ATTRIBUTE = "icon"; 46 public static final String BROWSER_CLASS_ATTRIBUTE = "browserClass"; 51 public static final String CONTAINER_ID_ATTRIBUTE = "containerTypeID"; 53 private static Hashtable fSourceContainerPresentationHashtable; 54 55 58 public SourceLookupUIUtils(){ 59 IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), CONTAINER_PRESENTATION_EXTENSION); 60 IConfigurationElement[] sourceContainerPresentationExtensions =extensionPoint.getConfigurationElements(); 62 fSourceContainerPresentationHashtable = new Hashtable (); 63 for (int i = 0; i < sourceContainerPresentationExtensions.length; i++) { 64 fSourceContainerPresentationHashtable.put( 65 sourceContainerPresentationExtensions[i].getAttribute(CONTAINER_ID_ATTRIBUTE), 66 sourceContainerPresentationExtensions[i]); 67 registerContainerImages(sourceContainerPresentationExtensions[i]); 68 } 69 } 70 71 72 77 public static Image getSourceContainerImage(String id){ 78 if(fSourceContainerPresentationHashtable == null) 79 new SourceLookupUIUtils(); 80 return DebugPluginImages.getImage(id); 81 } 82 83 88 public static ISourceContainerBrowser getSourceContainerBrowser(String typeID) 89 { 90 if(fSourceContainerPresentationHashtable == null) 91 new SourceLookupUIUtils(); 92 IConfigurationElement element = (IConfigurationElement)fSourceContainerPresentationHashtable.get(typeID); 93 ISourceContainerBrowser browser = null; 94 try{ 95 if(element!= null && element.getAttribute(BROWSER_CLASS_ATTRIBUTE) != null) 96 browser = (ISourceContainerBrowser) element.createExecutableExtension(BROWSER_CLASS_ATTRIBUTE); 97 }catch(CoreException e){} 98 return browser; 99 } 100 101 private void registerContainerImages(IConfigurationElement configElement){ 102 ImageDescriptor imageDescriptor = DebugUIPlugin.getImageDescriptor(configElement, ICON_ATTRIBUTE); 103 if (imageDescriptor == null) { 104 imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); 105 } 106 String configTypeID = configElement.getAttribute(CONTAINER_ID_ATTRIBUTE); 107 ImageRegistry imageRegistry = DebugPluginImages.getImageRegistry(); 108 imageRegistry.put(configTypeID, imageDescriptor); 109 } 110 111 } 112 | Popular Tags |