use of org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData in project che by eclipse.
the class ContributionTemplateStore method createTemplate.
// private static IConfigurationElement[] getTemplateExtensions() {
// return Platform.getExtensionRegistry().getConfigurationElementsFor(TEMPLATES_EXTENSION_POINT);
// }
private void createTemplate(Collection map, IConfigurationElement element) {
String contextTypeId = element.getAttribute(CONTEXT_TYPE_ID);
// log failures since extension point id and name are mandatory
if (contextExists(contextTypeId)) {
String id = element.getAttribute(ID);
if (isValidTemplateId(id)) {
String name = element.getAttribute(NAME);
if (name != null) {
String pattern = element.getChildren(PATTERN)[0].getValue();
if (pattern != null) {
String desc = element.getAttribute(DESCRIPTION);
if (desc == null)
//$NON-NLS-1$
desc = "";
String autoInsert = element.getAttribute(AUTO_INSERT);
boolean bAutoInsert;
if (autoInsert == null)
bAutoInsert = true;
else
bAutoInsert = Boolean.valueOf(autoInsert).booleanValue();
Template template = new Template(name, desc, contextTypeId, pattern, bAutoInsert);
TemplatePersistenceData data = new TemplatePersistenceData(template, true, id);
if (validateTemplate(template))
map.add(data);
}
}
}
}
}
use of org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData in project che by eclipse.
the class ContributionTemplateStore method loadContributedTemplates.
/**
* Loads the templates contributed via the templates extension point.
*
* @throws IOException {@inheritDoc}
*/
protected void loadContributedTemplates() throws IOException {
// IConfigurationElement[] extensions= getTemplateExtensions();
Collection contributed = readContributedTemplates();
for (Iterator it = contributed.iterator(); it.hasNext(); ) {
TemplatePersistenceData data = (TemplatePersistenceData) it.next();
internalAdd(data);
}
}
use of org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData in project che by eclipse.
the class ContributionTemplateStore method readIncludedTemplates.
private void readIncludedTemplates(Collection templates, /*, IConfigurationElement element*/
String file) throws IOException {
// String file= element.getAttribute(FILE);
if (file != null) {
// Bundle plugin = Platform.getBundle(element.getContributor().getName());
// URL url= FileLocator.find(plugin, Path.fromOSString(file), null);
URL url = ContributionTemplateStore.class.getResource(file);
if (url != null) {
ResourceBundle bundle = null;
InputStream bundleStream = null;
InputStream stream = null;
try {
// String translations= element.getAttribute(TRANSLATIONS);
// if (translations != null) {
//file.substring(0, file.lastIndexOf('.'));
String props = "/org/eclipse/templates/default-templates.properties";
URL bundleURL = ContributionTemplateStore.class.getResource(props);
if (bundleURL != null) {
bundleStream = bundleURL.openStream();
bundle = new PropertyResourceBundle(bundleStream);
}
// }
stream = new BufferedInputStream(url.openStream());
TemplateReaderWriter reader = new TemplateReaderWriter();
TemplatePersistenceData[] datas = reader.read(stream, bundle);
for (int i = 0; i < datas.length; i++) {
TemplatePersistenceData data = datas[i];
if (data.isCustom()) {
if (data.getId() == null)
JavaPlugin.logErrorMessage("Ignoring template ''" + data.getTemplate().getName() + "'' since it has no id.");
else
JavaPlugin.logErrorMessage("Ignoring template ''" + data.getTemplate().getName() + "'' since it is deleted.");
} else if (validateTemplate(data.getTemplate())) {
templates.add(data);
}
}
} finally {
try {
if (bundleStream != null)
bundleStream.close();
} catch (IOException x) {
} finally {
try {
if (stream != null)
stream.close();
} catch (IOException x) {
}
}
}
}
}
}
use of org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData in project che by eclipse.
the class StubUtility method setCodeTemplate.
/**
* Only to be used by tests
*
* @param templateId the template id
* @param pattern the new pattern
* @param project not used
*/
public static void setCodeTemplate(String templateId, String pattern, IJavaProject project) {
TemplateStore codeTemplateStore = JavaPlugin.getDefault().getCodeTemplateStore();
TemplatePersistenceData data = codeTemplateStore.getTemplateData(templateId);
Template orig = data.getTemplate();
Template copy = new Template(orig.getName(), orig.getDescription(), orig.getContextTypeId(), pattern, true);
data.setTemplate(copy);
}
Aggregations