Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2608bf0ccffd54b1a192f16ebb50e38e951e77de (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
/*******************************************************************************
 * Copyright (c) 2004, 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 implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui;

import java.util.HashMap;
import java.util.Map;

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.ui.IDebugUIConstants;
import org.eclipse.debug.ui.actions.IVariableValueEditor;

/**
 * Manager which provides the variable value editors contributed
 * via the org.eclipse.debug.ui.variableValueEditors extension
 * point.
 *
 * @see org.eclipse.debug.ui.actions.IVariableValueEditor
 * @since 3.1
 */
public class VariableValueEditorManager {

	/**
	 * Mapping of debug model identifiers to variable value editors.
	 * The keys in this map are always Strings (model ids).
	 * The values in the map are IConfigurationElements at startup,
	 * which are replaced by IVariableValueEditors as the editors
	 * are instantiated (editors are loaded lazily, then cached).
	 */
	private Map<String, Object> fEditorMap = new HashMap<>();

	/**
	 * The singleton instance of this manager.
	 */
	private static VariableValueEditorManager fgManager;

	/**
	 * Creates a new variable value editor manager. Clients
	 * should access the singleton instance of this manager
	 * by calling getDefault()
	 */
	private VariableValueEditorManager() {
		loadVariableEditors();
	}

	/**
	 * Returns the singleton instance of this manager.
	 * @return the singleton instance of this manager
	 */
	public static VariableValueEditorManager getDefault() {
		if (fgManager == null) {
			fgManager= new VariableValueEditorManager();
		}
		return fgManager;
	}

	/**
	 * Returns the variable value editor associated with the given debug
	 * model identifier or <code>null</code> if no editor has been supplied
	 * for the given debug model.
	 * @param modelIdentifier the debug model identifier
	 * @return the variable value editor associated with the given debug model
	 *  identifier or <code>null</code>
	 */
	public IVariableValueEditor getVariableValueEditor(String modelIdentifier) {
		Object object = fEditorMap.get(modelIdentifier);
		IVariableValueEditor editor= null;
		if (object instanceof IVariableValueEditor) {
			editor= (IVariableValueEditor) object;
		} else if (object instanceof IConfigurationElement) {
			try {
				editor = (IVariableValueEditor) ((IConfigurationElement) object).createExecutableExtension("class"); //$NON-NLS-1$
				fEditorMap.put(modelIdentifier, editor);
			} catch (CoreException e) {
				// If an exception occurs, loading the extension, just log it and
				// return null.
				DebugUIPlugin.log(e);
			}
		}
		return editor;
	}

	/**
	 * Loads contributors to the org.eclipse.debug.ui.variableValueEditors extension point,
	 * for use when the user runs this action.
	 */
	private void loadVariableEditors() {
		IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.EXTENSION_POINT_VARIABLE_VALUE_EDITORS);
		IConfigurationElement[] elements = ep.getConfigurationElements();
		for (IConfigurationElement element : elements) {
			String modelId = element.getAttribute("modelId"); //$NON-NLS-1$
			if (modelId != null) {
				fEditorMap.put(modelId, element);
			}
		}
	}
}

Back to the top