package tool.editors.contentassist;
import java.io.IOException;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.templates.ContextTypeRegistry;
import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData;
import org.eclipse.jface.text.templates.persistence.TemplateStore;
import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
import tool.ToolPlugin;
public class ToolTemplateManager {
private static final String TOOL_TEMPLATES_KEY
= ToolPlugin.PLUGIN_ID + ".tooltemplates";
private static ToolTemplateManager instance;
private TemplateStore fStore;
private ContributionContextTypeRegistry fRegistry;
private TemplatePersistenceData[] templateData;
private ToolTemplateManager(){}
public static ToolTemplateManager getInstance(){
if(instance==null){
instance = new ToolTemplateManager();
}
return instance;
}
public TemplateStore getTemplateStore(){
if (fStore == null){
fStore = new ContributionTemplateStore(getContextTypeRegistry(),
ToolPlugin.getDefault().getPreferenceStore(), TOOL_TEMPLATES_KEY);
try {
fStore.load();
} catch (IOException e){
ToolPlugin.showError("Error Template Store", e);
}
}
return fStore;
}
public ContextTypeRegistry getContextTypeRegistry(){
if (fRegistry == null){
fRegistry = new ContributionContextTypeRegistry();
}
fRegistry.addContextType(ToolTemplateContextType.CONTEXT_TYPE);
return fRegistry;
}
public IPreferenceStore getPreferenceStore(){
return ToolPlugin.getDefault().getPreferenceStore();
}
public void savePluginPreferences(){
ToolPlugin.getDefault().savePluginPreferences();
}
}