KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > stringsubstitution > StringVariablePresentationManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.stringsubstitution;
12
13 import com.ibm.icu.text.MessageFormat;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IConfigurationElement;
19 import org.eclipse.core.runtime.IExtensionPoint;
20 import org.eclipse.core.runtime.Platform;
21 import org.eclipse.core.variables.IStringVariable;
22 import org.eclipse.debug.internal.ui.DebugUIPlugin;
23
24 /**
25  * Manages argument selectors (choosers) for string variables.
26  *
27  * @since 3.0
28  */

29 public class StringVariablePresentationManager {
30     
31     /**
32      * String variable presentation extension point identifier
33      * (value <code>"stringVariablePresentations"</code>).
34      *
35      * @since 3.0
36      */

37     public static final String JavaDoc EXTENSION_POINT_STRING_VARIABLE_PRESENTATIONS = "stringVariablePresentations"; //$NON-NLS-1$
38

39     // default manager
40
private static StringVariablePresentationManager fgManager;
41     
42     // extension point attributes
43
public static final String JavaDoc ATTR_NAME = "variableName"; //$NON-NLS-1$
44
public static final String JavaDoc ATTR_ARGUMENT_SELECTOR = "argumentSelector"; //$NON-NLS-1$
45

46     /**
47      * Table of configuration elements for variable presentations,
48      * keyed by variable name.
49      */

50     private Map JavaDoc fConfigurations;
51     
52     /**
53      * Returns the singleton string variable presentation manager.
54      *
55      * @return the singleton string variable presentation manager
56      */

57     public static StringVariablePresentationManager getDefault() {
58         if (fgManager == null) {
59             fgManager = new StringVariablePresentationManager();
60         }
61         return fgManager;
62     }
63     
64     /**
65      * Returns an argument selector contributed for the given
66      * variable, or <code>null</code> if none.
67      *
68      * @param variable string substitution variable
69      * @return argument selector or <code>null</code>
70      */

71     public IArgumentSelector getArgumentSelector(IStringVariable variable) {
72         IConfigurationElement element = (IConfigurationElement) fConfigurations.get(variable.getName());
73         if (element != null) {
74             try {
75                 return (IArgumentSelector)element.createExecutableExtension(ATTR_ARGUMENT_SELECTOR);
76             } catch (CoreException e) {
77                 DebugUIPlugin.log(e);
78             }
79         }
80         return null;
81     }
82     
83     /**
84      * Constructs the manager, loading extensions.
85      */

86     private StringVariablePresentationManager() {
87         initialize();
88     }
89
90     /**
91      * Load extensions
92      */

93     private void initialize() {
94         fConfigurations = new HashMap JavaDoc();
95         IExtensionPoint point= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), EXTENSION_POINT_STRING_VARIABLE_PRESENTATIONS);
96         IConfigurationElement elements[]= point.getConfigurationElements();
97         for (int i = 0; i < elements.length; i++) {
98             IConfigurationElement element = elements[i];
99             String JavaDoc name= element.getAttribute(ATTR_NAME);
100             if (name == null) {
101                 DebugUIPlugin.logErrorMessage(MessageFormat.format("String variable presentation extension missing required 'variableName' attribute: {0}", new String JavaDoc[] {element.getDeclaringExtension().getLabel()})); //$NON-NLS-1$
102
continue;
103             }
104             fConfigurations.put(name, element);
105         }
106     }
107     
108
109 }
110
Popular Tags