Search in sources :

Example 71 with Template

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

the class NewDTDTemplatesWizardPage method getSelectedTemplate.

/**
 * Get the currently selected template.
 *
 * @return
 */
private Template getSelectedTemplate() {
    Template template = null;
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
    if (selection.size() == 1) {
        template = (Template) selection.getFirstElement();
    }
    return template;
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Template(org.eclipse.jface.text.templates.Template)

Example 72 with Template

use of org.eclipse.jface.text.templates.Template 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 73 with Template

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

the class XSLTemplateCompletionProcessor method getTemplates.

@Override
protected Template[] getTemplates(String contextTypeId) {
    Template[] templates = null;
    TemplateStore store = getTemplateStore();
    if (store != null) {
        templates = store.getTemplates(contextTypeId);
    }
    return templates;
}
Also used : TemplateStore(org.eclipse.jface.text.templates.persistence.TemplateStore) Template(org.eclipse.jface.text.templates.Template)

Example 74 with Template

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

the class NewXSLFileTemplatesWizardPage method saveLastSavedPreferences.

void saveLastSavedPreferences() {
    // $NON-NLS-1$
    String templateName = "";
    Template template = getSelectedTemplate();
    if (template != null) {
        templateName = template.getName();
    }
    XSLUIPlugin.getDefault().getPreferenceStore().setValue(XSLUIConstants.NEW_FILE_TEMPLATE_NAME, templateName);
    XSLUIPlugin.getDefault().savePluginPreferences();
}
Also used : Template(org.eclipse.jface.text.templates.Template)

Example 75 with Template

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

the class NewXSLFileTemplatesWizardPage method enableTemplates.

void enableTemplates() {
    boolean enabled = fUseTemplateButton.getSelection();
    if (enabled) {
        setSelectedTemplate(fLastSelectedTemplateName);
    } else {
        // save last selected template
        Template template = getSelectedTemplate();
        if (template != null)
            fLastSelectedTemplateName = template.getName();
        else
            // $NON-NLS-1$
            fLastSelectedTemplateName = "";
        fTableViewer.setSelection(null);
    }
    fTableViewer.getControl().setEnabled(enabled);
    fPatternViewer.getControl().setEnabled(enabled);
}
Also used : Template(org.eclipse.jface.text.templates.Template)

Aggregations

Template (org.eclipse.jface.text.templates.Template)158 CodeTemplateContext (org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext)27 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)22 TemplateException (org.eclipse.jface.text.templates.TemplateException)21 TemplateContext (org.eclipse.jface.text.templates.TemplateContext)19 IDocument (org.eclipse.jface.text.IDocument)18 Document (org.eclipse.jface.text.Document)17 ArrayList (java.util.ArrayList)15 BadLocationException (org.eclipse.jface.text.BadLocationException)15 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)15 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)14 TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)13 TemplateStore (org.eclipse.jface.text.templates.persistence.TemplateStore)12 CoreException (org.eclipse.core.runtime.CoreException)11 Region (org.eclipse.jface.text.Region)11 DocumentTemplateContext (org.eclipse.jface.text.templates.DocumentTemplateContext)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)11 IRegion (org.eclipse.jface.text.IRegion)10 ITextSelection (org.eclipse.jface.text.ITextSelection)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)10