Search in sources :

Example 21 with TemplateContextType

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

the class NewCSSTemplatesWizardPage method getTemplateString.

/**
 * Returns template string to insert.
 *
 * @return String to insert or null if none is to be inserted
 */
String getTemplateString() {
    String templateString = null;
    Template template = getSelectedTemplate();
    if (template != null) {
        TemplateContextType contextType = CSSUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsCSS.NEW);
        IDocument document = new Document();
        TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
        try {
            TemplateBuffer buffer = context.evaluate(template);
            templateString = buffer.getString();
        } catch (Exception e) {
            // $NON-NLS-1$
            Logger.log(Logger.WARNING_DEBUG, "Could not create template for new css", e);
        }
    }
    return templateString;
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) TemplateContext(org.eclipse.jface.text.templates.TemplateContext) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) Template(org.eclipse.jface.text.templates.Template)

Example 22 with TemplateContextType

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

the class JSPTemplateCompletionProcessor method getContextType.

protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) {
    TemplateContextType type = null;
    ContextTypeRegistry registry = getTemplateContextRegistry();
    if (registry != null)
        type = registry.getContextType(fContextTypeId);
    return type;
}
Also used : ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 23 with TemplateContextType

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

the class NewDTDTemplatesWizardPage method getTemplateString.

/**
 * Returns template string to insert.
 *
 * @return String to insert or null if none is to be inserted
 */
String getTemplateString() {
    String templateString = null;
    Template template = getSelectedTemplate();
    if (template != null) {
        TemplateContextType contextType = DTDUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsDTD.NEW);
        IDocument document = new Document();
        TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
        try {
            TemplateBuffer buffer = context.evaluate(template);
            templateString = buffer.getString();
        } catch (Exception e) {
            // $NON-NLS-1$
            Logger.log(Logger.WARNING_DEBUG, "Could not create template for new dtd", e);
        }
    }
    return templateString;
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) TemplateContext(org.eclipse.jface.text.templates.TemplateContext) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) Template(org.eclipse.jface.text.templates.Template)

Example 24 with TemplateContextType

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

the class XSLTemplateCompletionProcessor method getContextType.

@Override
protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) {
    TemplateContextType type = null;
    ContextTypeRegistry registry = getTemplateContextRegistry();
    if (registry != null) {
        type = registry.getContextType(fContextTypeId);
    }
    return type;
}
Also used : ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 25 with TemplateContextType

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

the class NewXMLTemplatesWizardPage method getTemplateString.

/**
 * Returns template string to insert.
 *
 * @return String to insert or null if none is to be inserted
 */
String getTemplateString() {
    String templateString = null;
    Template template = getSelectedTemplate();
    if (template != null) {
        TemplateContextType contextType = XMLUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsXML.NEW);
        IDocument document = new Document();
        TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
        try {
            TemplateBuffer buffer = context.evaluate(template);
            templateString = buffer.getString();
        } catch (Exception e) {
            // $NON-NLS-1$
            Logger.log(Logger.WARNING_DEBUG, "Could not create template for new xml", e);
        }
    }
    return templateString;
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) TemplateContext(org.eclipse.jface.text.templates.TemplateContext) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) Template(org.eclipse.jface.text.templates.Template)

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