KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > VariableValueEditorManager


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IExtensionPoint;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.debug.ui.IDebugUIConstants;
21 import org.eclipse.debug.ui.actions.IVariableValueEditor;
22
23 /**
24  * Manager which provides the variable value editors contributed
25  * via the org.eclipse.debug.ui.variableValueEditors extension
26  * point.
27  *
28  * @see org.eclipse.debug.ui.actions.IVariableValueEditor
29  * @since 3.1
30  */

31 public class VariableValueEditorManager {
32     
33     /**
34      * Mapping of debug model identifiers to variable value editors.
35      * The keys in this map are always Strings (model ids).
36      * The values in the map are IConfigurationElements at startup,
37      * which are replaced by IVariableValueEditors as the editors
38      * are instantiated (editors are loaded lazily, then cached).
39      */

40     private Map JavaDoc fEditorMap= new HashMap JavaDoc();
41     
42     /**
43      * The singleton instance of this manager.
44      */

45     private static VariableValueEditorManager fgManager;
46
47     /**
48      * Creates a new variable value editor manager. Clients
49      * should access the singleton instance of this manager
50      * by calling getDefault()
51      */

52     private VariableValueEditorManager() {
53         loadVariableEditors();
54     }
55
56     /**
57      * Returns the singleton instance of this manager.
58      * @return the singleton instance of this manager
59      */

60     public static VariableValueEditorManager getDefault() {
61         if (fgManager == null) {
62             fgManager= new VariableValueEditorManager();
63         }
64         return fgManager;
65     }
66     
67     /**
68      * Returns the variable value editor associated with the given debug
69      * model identifier or <code>null</code> if no editor has been supplied
70      * for the given debug model.
71      * @param modelIdentifier the debug model identifier
72      * @return the variable value editor associated with the given debug model
73      * identifier or <code>null</code>
74      */

75     public IVariableValueEditor getVariableValueEditor(String JavaDoc modelIdentifier) {
76         Object JavaDoc object = fEditorMap.get(modelIdentifier);
77         IVariableValueEditor editor= null;
78         if (object instanceof IVariableValueEditor) {
79             editor= (IVariableValueEditor) object;
80         } else if (object instanceof IConfigurationElement) {
81             try {
82                 editor = (IVariableValueEditor) ((IConfigurationElement) object).createExecutableExtension("class"); //$NON-NLS-1$
83
fEditorMap.put(modelIdentifier, editor);
84             } catch (CoreException e) {
85                 // If an exception occurs, loading the extension, just log it and
86
// return null.
87
DebugUIPlugin.log(e);
88             }
89         }
90         return editor;
91     }
92     
93     /**
94      * Loads contributors to the org.eclipse.debug.ui.variableValueEditors extension point,
95      * for use when the user runs this action.
96      */

97     private void loadVariableEditors() {
98         IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.EXTENSION_POINT_VARIABLE_VALUE_EDITORS);
99         IConfigurationElement[] elements = ep.getConfigurationElements();
100         for (int i = 0; i < elements.length; i++) {
101             IConfigurationElement element = elements[i];
102             String JavaDoc modelId = element.getAttribute("modelId"); //$NON-NLS-1$
103
if (modelId != null) {
104                 fEditorMap.put(modelId, element);
105             }
106         }
107     }
108 }
109
Popular Tags