]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/core extension/org/eclipse/jdt/internal/corext/template/java/CodeTemplates.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / core extension / org / eclipse / jdt / internal / corext / template / java / CodeTemplates.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 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;
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 TEMPLATE_FILE= "codetemplates.xml"; //$NON-NLS-1$
30
31         /** Singleton. */
32         private static CodeTemplates fgTemplates;
33
34         public static Template getCodeTemplate(String name) {
35                 return getInstance().getFirstTemplate(name);
36         }
37
38         /**
39          * Returns an instance of templates.
40          * @return an instance of templates
41          */
42         public static CodeTemplates getInstance() {
43                 if (fgTemplates == null)
44                         fgTemplates= new CodeTemplates();
45
46                 return fgTemplates;
47         }
48
49         private CodeTemplates() {
50                 super("codetemplate", JavaPlugin.getDefault().getCodeTemplateContextRegistry()); //$NON-NLS-1$
51                 create();
52         }
53
54         private void create() {
55
56                 try {
57                         File templateFile= getTemplateFile();
58                         if (templateFile.exists()) {
59                                 addFromFile(templateFile, false);
60                         }
61
62                 } catch (CoreException e) {
63                         JavaPlugin.log(e);
64                         clear();
65                 }
66
67         }
68
69         /**
70          * Resets the template set.
71          * @throws CoreException
72          */
73         public void reset() throws CoreException {
74         }
75
76         /**
77          * Resets the template set with the default templates.
78          * @throws CoreException
79          */
80         public void restoreDefaults() throws CoreException {
81         }
82
83         /**
84          * Saves the template set.
85          * @throws CoreException
86          */
87         public void save() throws CoreException {
88         }
89
90         private static File getTemplateFile() {
91                 IPath path= JavaPlugin.getDefault().getStateLocation();
92                 path= path.append(TEMPLATE_FILE);
93
94                 return path.toFile();
95         }
96
97 }