Search in sources :

Example 1 with TemplatePersistenceData

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);
                }
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData) Template(org.eclipse.jface.text.templates.Template)

Example 2 with TemplatePersistenceData

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);
    }
}
Also used : TemplatePersistenceData(org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 3 with TemplatePersistenceData

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) {
                    }
                }
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) TemplateReaderWriter(org.eclipse.che.jface.text.templates.persistence.TemplateReaderWriter) IOException(java.io.IOException) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Example 4 with TemplatePersistenceData

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);
}
Also used : TemplatePersistenceData(org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData) TemplateStore(org.eclipse.che.jface.text.templates.persistence.TemplateStore) Template(org.eclipse.jface.text.templates.Template)

Aggregations

TemplatePersistenceData (org.eclipse.che.jface.text.templates.persistence.TemplatePersistenceData)4 Template (org.eclipse.jface.text.templates.Template)2 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 PropertyResourceBundle (java.util.PropertyResourceBundle)1 ResourceBundle (java.util.ResourceBundle)1 TemplateReaderWriter (org.eclipse.che.jface.text.templates.persistence.TemplateReaderWriter)1 TemplateStore (org.eclipse.che.jface.text.templates.persistence.TemplateStore)1