1 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 27 public class CodeTemplates extends org.eclipse.jdt.internal.corext.template.java.TemplateSet { 28 29 private static final String TEMPLATE_FILE= "codetemplates.xml"; 31 32 private static CodeTemplates fgTemplates; 33 34 public static Template getCodeTemplate(String name) { 35 return getInstance().getFirstTemplate(name); 36 } 37 38 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()); create(); 51 } 52 53 private void create() { 54 55 try { 56 File 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 71 public void reset() throws CoreException { 72 } 73 74 77 public void restoreDefaults() throws CoreException { 78 } 79 80 83 public void save() throws CoreException { 84 } 85 86 private static File getTemplateFile() { 87 IPath path= JavaPlugin.getDefault().getStateLocation(); 88 path= path.append(TEMPLATE_FILE); 89 90 return path.toFile(); 91 } 92 93 } 94 | Popular Tags |