Package: VdmTemplateManager

VdmTemplateManager

nameinstructionbranchcomplexitylinemethod
VdmTemplateManager()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getContextTypeRegistry()
M: 41 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getInstance()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getPreferenceStore()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTemplateStore()
M: 23 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
savePluginPreferences()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.ui
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.ui.templates;
23:
24: import java.io.IOException;
25:
26: import org.eclipse.core.runtime.IConfigurationElement;
27: import org.eclipse.core.runtime.IExtensionRegistry;
28: import org.eclipse.core.runtime.Platform;
29: import org.eclipse.jface.preference.IPreferenceStore;
30: import org.eclipse.jface.text.templates.ContextTypeRegistry;
31: import org.eclipse.jface.text.templates.persistence.TemplateStore;
32: import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
33: import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
34: import org.overture.ide.ui.IVdmUiConstants;
35: import org.overture.ide.ui.VdmUIPlugin;
36:
37:
38: public class VdmTemplateManager {
39:
40:         private static final String VDM_TEMPLATES_KEY = IVdmUiConstants.PLUGIN_ID
41:                         + ".vdmtemplates";
42:         private static VdmTemplateManager instance;
43:         private TemplateStore fStore = null;
44:         private ContributionContextTypeRegistry fRegistry;
45: //        private TemplatePersistenceData[] templateData;
46:
47:         private VdmTemplateManager() {
48:         }
49:
50:         public static VdmTemplateManager getInstance() {
51:•                if (instance == null) {
52:                         instance = new VdmTemplateManager();
53:                 }
54:                 return instance;
55:         }
56:
57:         public TemplateStore getTemplateStore() {
58:
59:•                if (fStore == null) {
60:                         fStore = new ContributionTemplateStore(getContextTypeRegistry(),
61:                                         VdmUIPlugin.getDefault().getPreferenceStore(),
62:                                         VDM_TEMPLATES_KEY);
63:                         try {
64:                                 fStore.load();
65:                         } catch (IOException e) {
66:                                 e.printStackTrace();
67:
68:                         }
69:                 }
70:                 return fStore;
71:         }
72:
73:         public ContextTypeRegistry getContextTypeRegistry() {
74:•                if (fRegistry == null) {
75:                         fRegistry = new ContributionContextTypeRegistry();
76:                 }
77:                 IExtensionRegistry reg = Platform.getExtensionRegistry();
78:                 IConfigurationElement[] extensions = reg.getConfigurationElementsFor(IVdmUiConstants.TEMPLATE_EXTENTION_POINT_ID);
79:                 
80:•                for (IConfigurationElement iConfigurationElement : extensions) {
81:                         String id = iConfigurationElement.getAttribute(IVdmUiConstants.TEMPLATE_EXTENTION_POINT_ID_ATTRIBUTE);
82:                         fRegistry.addContextType(id);
83:                 }
84:                 
85:                 //fRegistry.addContextType(VdmUniversalTemplateContextType.CONTEXT_TYPE);
86:                 return fRegistry;
87:         }
88:
89:         public IPreferenceStore getPreferenceStore() {
90:                 return VdmUIPlugin.getDefault().getPreferenceStore();
91:         }
92:
93:         public void savePluginPreferences() {
94:                 VdmUIPlugin.getDefault().savePluginPreferences();
95:         }
96:
97: }