Search in sources :

Example 31 with TemplatePersistenceData

use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project flux 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.jface.text.templates.persistence.TemplatePersistenceData) TemplateStore(org.eclipse.jface.text.templates.persistence.TemplateStore) Template(org.eclipse.jface.text.templates.Template)

Example 32 with TemplatePersistenceData

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

the class XtextTemplateStore method loadContributedTemplates.

@Override
protected void loadContributedTemplates() throws IOException {
    if (resource == null)
        return;
    TemplateReaderWriter reader = new TemplateReaderWriter();
    InputStream openStream = null;
    try {
        openStream = resource.openStream();
        try {
            TemplatePersistenceData[] read = reader.read(openStream, null);
            for (TemplatePersistenceData templatePersistenceData : read) {
                internalAdd(templatePersistenceData);
            }
        } finally {
            openStream.close();
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) InputStream(java.io.InputStream) TemplateReaderWriter(org.eclipse.jface.text.templates.persistence.TemplateReaderWriter) IOException(java.io.IOException)

Example 33 with TemplatePersistenceData

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

the class SQLTemplateStore method readContributedTemplates.

private Collection<TemplatePersistenceData> readContributedTemplates() throws IOException {
    Collection<TemplatePersistenceData> templates = new ArrayList<>();
    readIncludedTemplates(SQLEditorActivator.PLUGIN_ID, templates, "templates/default-templates.xml", "$nl$/templates/default-templates.properties");
    // Read templates for DS providers
    for (DBPDataSourceProviderDescriptor provider : DBWorkbench.getPlatform().getDataSourceProviderRegistry().getDataSourceProviders()) {
        readIncludedTemplates(provider.getPluginId(), templates, "templates/" + provider.getId() + "-templates.xml", "$nl$/templates/" + provider.getId() + "-templates.properties");
    }
    return templates;
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) ArrayList(java.util.ArrayList) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)

Example 34 with TemplatePersistenceData

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

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)

Example 35 with TemplatePersistenceData

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

the class SQLTemplateStore method readContributedTemplates.

private Collection<TemplatePersistenceData> readContributedTemplates() throws IOException {
    Collection<TemplatePersistenceData> templates = new ArrayList<>();
    readIncludedTemplates(SQLEditorActivator.PLUGIN_ID, templates, "templates/default-templates.xml", "$nl$/templates/default-templates.properties");
    // Read templates for DS providers
    for (DBPDataSourceProviderDescriptor provider : DBWorkbench.getPlatform().getDataSourceProviderRegistry().getDataSourceProviders()) {
        readIncludedTemplates(provider.getPluginId(), templates, "templates/" + provider.getId() + "-templates.xml", "$nl$/templates/" + provider.getId() + "-templates.properties");
    }
    return templates;
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) ArrayList(java.util.ArrayList) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)

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