KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > template > java > CodeTemplates


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.jdt.internal.corext.template.java;
12
13 import java.io.File JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IPath;
17
18 import org.eclipse.jface.text.templates.Template;
19
20 import org.eclipse.jdt.internal.ui.JavaPlugin;
21
22 /**
23  * <code>CodeTemplates</code> gives access to the available code templates.
24  * @since 3.0
25  * @deprecated use {@link org.eclipse.jdt.internal.ui.JavaPlugin#getCodeTemplateStore()} instead
26  */

27 public class CodeTemplates extends org.eclipse.jdt.internal.corext.template.java.TemplateSet {
28
29     private static final String JavaDoc TEMPLATE_FILE= "codetemplates.xml"; //$NON-NLS-1$
30

31     /** Singleton. */
32     private static CodeTemplates fgTemplates;
33
34     public static Template getCodeTemplate(String JavaDoc name) {
35         return getInstance().getFirstTemplate(name);
36     }
37
38     /**
39      * Returns an instance of templates.
40      */

41     public static CodeTemplates getInstance() {
42         if (fgTemplates == null)
43             fgTemplates= new CodeTemplates();
44         
45         return fgTemplates;
46     }
47     
48     private CodeTemplates() {
49         super("codetemplate", JavaPlugin.getDefault().getCodeTemplateContextRegistry()); //$NON-NLS-1$
50
create();
51     }
52     
53     private void create() {
54         
55         try {
56             File JavaDoc templateFile= getTemplateFile();
57             if (templateFile.exists()) {
58                 addFromFile(templateFile, false);
59             }
60
61         } catch (CoreException e) {
62             JavaPlugin.log(e);
63             clear();
64         }
65
66     }
67     
68     /**
69      * Resets the template set.
70      */

71     public void reset() throws CoreException {
72     }
73
74     /**
75      * Resets the template set with the default templates.
76      */

77     public void restoreDefaults() throws CoreException {
78     }
79
80     /**
81      * Saves the template set.
82      */

83     public void save() throws CoreException {
84     }
85
86     private static File JavaDoc getTemplateFile() {
87         IPath path= JavaPlugin.getDefault().getStateLocation();
88         path= path.append(TEMPLATE_FILE);
89         
90         return path.toFile();
91     }
92
93 }
94
Popular Tags