Search in sources :

Example 1 with TemplateContextType

use of org.eclipse.jface.text.templates.TemplateContextType in project che by eclipse.

the class ContributionContextTypeRegistry method createContextType.

/**
	 * Tries to create a context type given an id. Contributions to the
	 * <code>org.eclipse.ui.editors.templates</code> extension point are
	 * searched for the given identifier and the specified context type
	 * instantiated if it is found. Any contributed
	 * {@link org.eclipse.jface.text.templates.TemplateVariableResolver}s
	 * are also instantiated and added to the context type.
	 *
	 * @param id the id for the context type as specified in XML
	 * @return the instantiated and configured context type, or
	 *         <code>null</code> if it is not found or cannot be instantiated
	 */
public static TemplateContextType createContextType(String id) {
    Assert.isNotNull(id);
    IConfigurationElement[] extensions = getTemplateExtensions();
    TemplateContextType type;
    try {
        type = createContextType(extensions, id);
        if (type != null) {
            TemplateVariableResolver[] resolvers = createResolvers(extensions, id);
            for (int i = 0; i < resolvers.length; i++) type.addResolver(resolvers[i]);
        }
    } catch (CoreException e) {
        JavaPlugin.log(e);
        type = null;
    }
    return type;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver)

Example 2 with TemplateContextType

use of org.eclipse.jface.text.templates.TemplateContextType in project che by eclipse.

the class TemplateCompletionProposalComputer method createTemplateEngine.

private static TemplateEngine createTemplateEngine(ContextTypeRegistry templateContextRegistry, String contextTypeId) {
    TemplateContextType contextType = templateContextRegistry.getContextType(contextTypeId);
    Assert.isNotNull(contextType);
    return new TemplateEngine(contextType);
}
Also used : TemplateEngine(org.eclipse.jdt.internal.ui.text.template.contentassist.TemplateEngine) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 3 with TemplateContextType

use of org.eclipse.jface.text.templates.TemplateContextType in project che by eclipse.

the class JavaPlugin method getTemplateContextRegistry.

/**
     * Returns the template context type registry for the java plug-in.
     *
     * @return the template context type registry for the java plug-in
     * @since 3.0
     */
public synchronized ContextTypeRegistry getTemplateContextRegistry() {
    if (fContextTypeRegistry == null) {
        ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry(ID_CU_EDITOR);
        TemplateContextType all_contextType = registry.getContextType(JavaContextType.ID_ALL);
        ((AbstractJavaContextType) all_contextType).initializeContextTypeResolvers();
        registerJavaContext(registry, JavaContextType.ID_MEMBERS, all_contextType);
        registerJavaContext(registry, JavaContextType.ID_STATEMENTS, all_contextType);
        //            registerJavaContext(registry, SWTContextType.ID_ALL, all_contextType);
        //            all_contextType= registry.getContextType(SWTContextType.ID_ALL);
        //
        //            registerJavaContext(registry, SWTContextType.ID_MEMBERS, all_contextType);
        //            registerJavaContext(registry, SWTContextType.ID_STATEMENTS, all_contextType);
        fContextTypeRegistry = registry;
    }
    return fContextTypeRegistry;
}
Also used : AbstractJavaContextType(org.eclipse.jdt.internal.corext.template.java.AbstractJavaContextType) ContributionContextTypeRegistry(org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) CodeTemplateContextType(org.eclipse.jdt.internal.corext.template.java.CodeTemplateContextType)

Example 4 with TemplateContextType

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

the class DefaultTemplateProposalProvider method createTemplates.

@Override
protected void createTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor acceptor) {
    TemplateContextType contextType = templateContext.getContextType();
    Template[] templates = templateStore.getTemplates(contextType.getId());
    for (Template template : templates) {
        if (!acceptor.canAcceptMoreTemplates())
            return;
        if (validate(template, templateContext)) {
            acceptor.accept(createProposal(template, templateContext, context, getImage(template), getRelevance(template)));
        }
    }
}
Also used : TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) Template(org.eclipse.jface.text.templates.Template)

Example 5 with TemplateContextType

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

the class DefaultTemplateProposalProvider method getContextTypes.

@Override
protected TemplateContextType[] getContextTypes(final ContentAssistContext context) {
    final Set<TemplateContextType> result = Sets.newLinkedHashSet();
    IFollowElementAcceptor acceptor = createFollowElementAcceptor(result);
    List<AbstractElement> grammarElements = context.getFirstSetGrammarElements();
    for (AbstractElement element : grammarElements) acceptor.accept(element);
    return result.toArray(new TemplateContextType[result.size()]);
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) IFollowElementAcceptor(org.eclipse.xtext.ui.editor.contentassist.IFollowElementAcceptor) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Aggregations

TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)54 ContextTypeRegistry (org.eclipse.jface.text.templates.ContextTypeRegistry)17 Template (org.eclipse.jface.text.templates.Template)14 Document (org.eclipse.jface.text.Document)11 IDocument (org.eclipse.jface.text.IDocument)11 DocumentTemplateContext (org.eclipse.jface.text.templates.DocumentTemplateContext)9 TemplateVariableResolver (org.eclipse.jface.text.templates.TemplateVariableResolver)9 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)8 CoreException (org.eclipse.core.runtime.CoreException)7 TemplateContext (org.eclipse.jface.text.templates.TemplateContext)7 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)4 TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)4 TemplateStore (org.eclipse.jface.text.templates.persistence.TemplateStore)4 ContextTypeIdHelper (org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper)4 IFile (org.eclipse.core.resources.IFile)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StyledString (org.eclipse.jface.viewers.StyledString)3