KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > editor > templates > AntTemplateAccess


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.ant.internal.ui.editor.templates;
12
13 import java.io.IOException JavaDoc;
14
15 import org.eclipse.ant.internal.ui.AntUIPlugin;
16 import org.eclipse.jface.text.templates.ContextTypeRegistry;
17 import org.eclipse.jface.text.templates.persistence.TemplateStore;
18 import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
19 import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
20
21
22 public class AntTemplateAccess {
23     /** Key to store custom templates. */
24     private static final String JavaDoc CUSTOM_TEMPLATES_KEY= "org.eclipse.ant.ui.customtemplates"; //$NON-NLS-1$
25

26     /** The shared instance. */
27     private static AntTemplateAccess fgInstance;
28     
29     /** The template store. */
30     private TemplateStore fStore;
31     
32     /** The context type registry. */
33     private ContributionContextTypeRegistry fRegistry;
34     
35     private AntTemplateAccess() {
36     }
37
38     /**
39      * Returns the shared instance.
40      *
41      * @return the shared instance
42      */

43     public static AntTemplateAccess getDefault() {
44         if (fgInstance == null) {
45             fgInstance= new AntTemplateAccess();
46         }
47         return fgInstance;
48     }
49
50     /**
51      * Returns this plug-in's template store.
52      *
53      * @return the template store of this plug-in instance
54      */

55     public TemplateStore getTemplateStore() {
56         if (fStore == null) {
57             fStore= new ContributionTemplateStore(getContextTypeRegistry(),AntUIPlugin.getDefault().getPreferenceStore(), CUSTOM_TEMPLATES_KEY);
58             try {
59                 fStore.load();
60             } catch (IOException JavaDoc e) {
61                 AntUIPlugin.log(e);
62             }
63         }
64         return fStore;
65     }
66
67     /**
68      * Returns this plug-in's context type registry.
69      *
70      * @return the context type registry for this plug-in instance
71      */

72     public ContextTypeRegistry getContextTypeRegistry() {
73         if (fRegistry == null) {
74             // create and configure the contexts available in the template editor
75
fRegistry= new ContributionContextTypeRegistry();
76             fRegistry.addContextType(BuildFileContextType.BUILDFILE_CONTEXT_TYPE);
77             fRegistry.addContextType(TargetContextType.TARGET_CONTEXT_TYPE);
78             fRegistry.addContextType(TaskContextType.TASK_CONTEXT_TYPE);
79         }
80         return fRegistry;
81     }
82 }
83
Popular Tags