Search in sources :

Example 36 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project dbeaver by dbeaver.

the class SQLTemplateStore method readIncludedTemplates.

private void readIncludedTemplates(String contributorId, Collection<TemplatePersistenceData> templates, String file, String translations) throws IOException {
    if (file != null) {
        Bundle plugin = Platform.getBundle(contributorId);
        URL url = FileLocator.find(plugin, Path.fromOSString(file), null);
        if (url != null) {
            ResourceBundle bundle = null;
            if (translations != null) {
                URL bundleURL = FileLocator.find(plugin, Path.fromOSString(translations), null);
                if (bundleURL != null) {
                    InputStream bundleStream = bundleURL.openStream();
                    try {
                        bundle = new PropertyResourceBundle(bundleStream);
                    } finally {
                        ContentUtils.close(bundleStream);
                    }
                }
            }
            InputStream stream = new BufferedInputStream(url.openStream());
            try {
                TemplateReaderWriter reader = new TemplateReaderWriter();
                TemplatePersistenceData[] datas = reader.read(stream, bundle);
                for (TemplatePersistenceData data : datas) {
                    if (data.isCustom()) {
                        if (data.getId() == null)
                            log.error("No template id specified");
                        else
                            log.error("Template " + data.getTemplate().getName() + " deleted");
                    } else if (validateTemplate(data.getTemplate())) {
                        templates.add(data);
                    }
                }
            } finally {
                ContentUtils.close(stream);
            }
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) PropertyResourceBundle(java.util.PropertyResourceBundle) ResourceBundle(java.util.ResourceBundle) PropertyResourceBundle(java.util.PropertyResourceBundle) TemplateReaderWriter(org.eclipse.jface.text.templates.persistence.TemplateReaderWriter) URL(java.net.URL) PropertyResourceBundle(java.util.PropertyResourceBundle)

Aggregations

TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)36 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)17 Template (org.eclipse.jface.text.templates.Template)13 TemplateReaderWriter (org.eclipse.jface.text.templates.persistence.TemplateReaderWriter)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 InputStream (java.io.InputStream)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 URL (java.net.URL)4 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)4 BufferedInputStream (java.io.BufferedInputStream)3 PropertyResourceBundle (java.util.PropertyResourceBundle)3 ResourceBundle (java.util.ResourceBundle)3 Point (org.eclipse.swt.graphics.Point)3 Bundle (org.osgi.framework.Bundle)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Action (org.eclipse.jface.action.Action)2 IAction (org.eclipse.jface.action.IAction)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2