Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3406fdef929b4271064b0bbd1850a094b11a8097 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*******************************************************************************
 * Copyright (c) 2003, 2013 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.sourcelookup;

import java.util.Hashtable;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.internal.ui.DebugPluginImages;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

/**
 * Utility methods for the UI portion of the source lookup solution.
 *
 * @since 3.0
 */
public class SourceLookupUIUtils {
	/**
	 * Constant for the container presentation extension id.
	 * @since 3.0
	 */
	public static final String CONTAINER_PRESENTATION_EXTENSION = "sourceContainerPresentations"; //$NON-NLS-1$
	/**
	 * Constant for the container presentation icon attribute.
	 * @since 3.0
	 */
	public static final String ICON_ATTRIBUTE = "icon";	 //$NON-NLS-1$
	/**
	 * Constant for the container presentation browser attribute.
	 * @since 3.0
	 */
	public static final String BROWSER_CLASS_ATTRIBUTE = "browserClass"; //$NON-NLS-1$
	/**
	 * Constant for the container presentation type id attribute.
	 * @since 3.0
	 */
	public static final String CONTAINER_ID_ATTRIBUTE = "containerTypeID";	//$NON-NLS-1$

	private static Hashtable<String, IConfigurationElement> fSourceContainerPresentationHashtable;

	/**
	 * Constructor. Reads in Source Container Presentation extension implementations.
	 */
	public SourceLookupUIUtils(){
		IExtensionPoint extensionPoint= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), CONTAINER_PRESENTATION_EXTENSION);
		//read in SourceContainer presentation extensions
		IConfigurationElement[] sourceContainerPresentationExtensions =extensionPoint.getConfigurationElements();
		fSourceContainerPresentationHashtable = new Hashtable<>();
		for (int i = 0; i < sourceContainerPresentationExtensions.length; i++) {
			fSourceContainerPresentationHashtable.put(
					sourceContainerPresentationExtensions[i].getAttribute(CONTAINER_ID_ATTRIBUTE),
					sourceContainerPresentationExtensions[i]);
			registerContainerImages(sourceContainerPresentationExtensions[i]);
		}
	}


	/**
	 * Retrieves the icon associated with a source container type.
	 * @param id the container type id
	 * @return the image for the type specified
	 */
	public static Image getSourceContainerImage(String id){
		if(fSourceContainerPresentationHashtable == null) {
			new SourceLookupUIUtils();
		}
		return DebugPluginImages.getImage(id);
	}

	/**
	 * Retrieves the browser class associated with the source container type specified.
	 * @param typeID the source container type id
	 * @return the browser class
	 */
	public static ISourceContainerBrowser getSourceContainerBrowser(String typeID)
	{
		if(fSourceContainerPresentationHashtable == null) {
			new SourceLookupUIUtils();
		}
		IConfigurationElement element = fSourceContainerPresentationHashtable.get(typeID);
		ISourceContainerBrowser browser = null;
		try{
			if(element!= null && element.getAttribute(BROWSER_CLASS_ATTRIBUTE) != null) {
				browser = (ISourceContainerBrowser) element.createExecutableExtension(BROWSER_CLASS_ATTRIBUTE);
			}
		}catch(CoreException e){}
		return browser;
	}

	private void registerContainerImages(IConfigurationElement configElement){
		ImageDescriptor imageDescriptor = DebugUIPlugin.getImageDescriptor(configElement, ICON_ATTRIBUTE);
		if (imageDescriptor == null) {
			imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
		}
		String configTypeID = configElement.getAttribute(CONTAINER_ID_ATTRIBUTE);
		ImageRegistry imageRegistry = DebugPluginImages.getImageRegistry();
		imageRegistry.put(configTypeID, imageDescriptor);
	}

}

Back to the top