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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.template.java;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.jface.text.templates.Template;
20 import org.eclipse.jdt.internal.ui.JavaPlugin;
23 * <code>CodeTemplates</code> gives access to the available code templates.
25 * @deprecated use {@link org.eclipse.jdt.internal.ui.JavaPlugin#getCodeTemplateStore()} instead
27 public class CodeTemplates extends org.eclipse.jdt.internal.corext.template.java.TemplateSet {
29 private static final String TEMPLATE_FILE= "codetemplates.xml"; //$NON-NLS-1$
32 private static CodeTemplates fgTemplates;
34 public static Template getCodeTemplate(String name) {
35 return getInstance().getFirstTemplate(name);
39 * Returns an instance of templates.
40 * @return an instance of templates
42 public static CodeTemplates getInstance() {
43 if (fgTemplates == null)
44 fgTemplates= new CodeTemplates();
49 private CodeTemplates() {
50 super("codetemplate", JavaPlugin.getDefault().getCodeTemplateContextRegistry()); //$NON-NLS-1$
54 private void create() {
57 File templateFile= getTemplateFile();
58 if (templateFile.exists()) {
59 addFromFile(templateFile, false);
62 } catch (CoreException e) {
70 * Resets the template set.
71 * @throws CoreException
73 public void reset() throws CoreException {
77 * Resets the template set with the default templates.
78 * @throws CoreException
80 public void restoreDefaults() throws CoreException {
84 * Saves the template set.
85 * @throws CoreException
87 public void save() throws CoreException {
90 private static File getTemplateFile() {
91 IPath path= JavaPlugin.getDefault().getStateLocation();
92 path= path.append(TEMPLATE_FILE);