KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > templates > ContextTypeRegistry


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jface.text.templates;
12
13 import java.util.Iterator JavaDoc;
14 import java.util.LinkedHashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 /**
18  * A registry for context types. Editor implementors will usually instantiate a
19  * registry and configure the context types available in their editor.
20  * <p>
21  * In order to pick up templates contributed using the <code>org.eclipse.ui.editors.templates</code>
22  * extension point, use a <code>ContributionContextTypeRegistry</code>.
23  * </p>
24  *
25  * @since 3.0
26  */

27 public class ContextTypeRegistry {
28
29     /** all known context types */
30     private final Map JavaDoc fContextTypes= new LinkedHashMap JavaDoc();
31
32     /**
33      * Adds a context type to the registry. If there already is a context type
34      * with the same ID registered, it is replaced.
35      *
36      * @param contextType the context type to add
37      */

38     public void addContextType(TemplateContextType contextType) {
39         fContextTypes.put(contextType.getId(), contextType);
40     }
41
42     /**
43      * Returns the context type if the id is valid, <code>null</code> otherwise.
44      *
45      * @param id the id of the context type to retrieve
46      * @return the context type if <code>name</code> is valid, <code>null</code> otherwise
47      */

48     public TemplateContextType getContextType(String JavaDoc id) {
49         return (TemplateContextType) fContextTypes.get(id);
50     }
51
52     /**
53      * Returns an iterator over all registered context types.
54      *
55      * @return an iterator over all registered context types
56      */

57     public Iterator JavaDoc contextTypes() {
58         return fContextTypes.values().iterator();
59     }
60 }
61
Popular Tags