KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > SourceLookupUIUtils


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.sourcelookup;
12
13 import java.util.Hashtable JavaDoc;
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 /**
27  * Utility methods for the UI portion of the source lookup solution.
28  *
29  * @since 3.0
30  */

31 public class SourceLookupUIUtils {
32     /**
33      * Constant for the container presentation extension id.
34      * @since 3.0
35      */

36     public static final String JavaDoc CONTAINER_PRESENTATION_EXTENSION = "sourceContainerPresentations"; //$NON-NLS-1$
37
/**
38      * Constant for the container presentation icon attribute.
39      * @since 3.0
40      */

41     public static final String JavaDoc ICON_ATTRIBUTE = "icon"; //$NON-NLS-1$
42
/**
43      * Constant for the container presentation browser attribute.
44      * @since 3.0
45      */

46     public static final String JavaDoc BROWSER_CLASS_ATTRIBUTE = "browserClass"; //$NON-NLS-1$
47
/**
48      * Constant for the container presentation type id attribute.
49      * @since 3.0
50      */

51     public static final String JavaDoc CONTAINER_ID_ATTRIBUTE = "containerTypeID"; //$NON-NLS-1$
52

53     private static Hashtable JavaDoc fSourceContainerPresentationHashtable;
54     
55     /**
56      * Constructor. Reads in Source Container Presentation extension implementations.
57      */

58     public SourceLookupUIUtils(){
59         IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), CONTAINER_PRESENTATION_EXTENSION);
60         //read in SourceContainer presentation extensions
61
IConfigurationElement[] sourceContainerPresentationExtensions =extensionPoint.getConfigurationElements();
62         fSourceContainerPresentationHashtable = new Hashtable JavaDoc();
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     /**
73      * Retrieves the icon associated with a source container type.
74      * @param id the container type id
75      * @return the image for the type specified
76      */

77     public static Image getSourceContainerImage(String JavaDoc id){
78         if(fSourceContainerPresentationHashtable == null)
79             new SourceLookupUIUtils();
80         return DebugPluginImages.getImage(id);
81     }
82     
83     /**
84      * Retrieves the browser class associated with the source container type specified.
85      * @param typeID the source container type id
86      * @return the browser class
87      */

88     public static ISourceContainerBrowser getSourceContainerBrowser(String JavaDoc 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 JavaDoc configTypeID = configElement.getAttribute(CONTAINER_ID_ATTRIBUTE);
107         ImageRegistry imageRegistry = DebugPluginImages.getImageRegistry();
108         imageRegistry.put(configTypeID, imageDescriptor);
109     }
110     
111 }
112
Popular Tags