Package org.kacprzak.eclipse.django_editor.templates

Source Code of org.kacprzak.eclipse.django_editor.templates.TemplateManager

package org.kacprzak.eclipse.django_editor.templates;

import java.io.IOException;

import org.eclipse.jface.text.templates.ContextTypeRegistry;
import org.eclipse.jface.text.templates.persistence.TemplateStore;
import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
import org.kacprzak.eclipse.django_editor.DjangoActivator;

/**
* Predefined templates manager
* @author Zbigniew Kacprzak
*/
public class TemplateManager {

  private static final String DJANGO_CUSTOM_TEMPLATES_KEY = "_django.editor.custom.templates";

    private static TemplateStore           templatesStore = null;
    private static ContributionContextTypeRegistry  contextTypeRegistry = null;


    public static TemplateStore getDjangoTemplateStore() {
        if (templatesStore == null) {
          templatesStore = new ContributionTemplateStore(
                      getDjangoContextTypeRegistry(),
                      DjangoActivator.getDefault().getPreferenceStore(),
                      DJANGO_CUSTOM_TEMPLATES_KEY
                    );
            try {
              templatesStore.load();
            } catch (IOException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        return templatesStore;
    }

    public static ContextTypeRegistry getDjangoContextTypeRegistry() {
        if (contextTypeRegistry == null) {
          contextTypeRegistry = new ContributionContextTypeRegistry();
          contextTypeRegistry.addContextType(DjangoContextType.DJANGO_CONTEXT_TYPE_TAG);
          contextTypeRegistry.addContextType(DjangoContextType.DJANGO_CONTEXT_TYPE_FILTER);
        }
      return contextTypeRegistry;
    }

  @SuppressWarnings("deprecation")
  public static void savePluginPreferences(){
    DjangoActivator.getDefault().savePluginPreferences();
  }

}
TOP

Related Classes of org.kacprzak.eclipse.django_editor.templates.TemplateManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.