Search in sources :

Example 66 with Template

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

the class NewTagTemplatesWizardPage method saveLastSavedPreferences.

/**
 * Save template name used for next call to New JSP File wizard.
 */
void saveLastSavedPreferences() {
    // $NON-NLS-1$
    String templateName = "";
    Template template = getSelectedTemplate();
    if (template != null) {
        templateName = template.getName();
    }
    JSPUIPlugin.getDefault().getPreferenceStore().setValue(JSPUIPreferenceNames.NEW_TAG_FILE_TEMPLATE_NAME, templateName);
    JSPUIPlugin.getDefault().savePluginPreferences();
}
Also used : Template(org.eclipse.jface.text.templates.Template)

Example 67 with Template

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

the class JSPTemplateCompletionProcessor method getTemplates.

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 68 with Template

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

the class JSPTemplateCompletionProcessor method computeCompletionProposals.

/*
	 * Copied from super class except instead of calling createContext(viewer,
	 * region) call createContext(viewer, region, offset) instead
	 */
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
    // adjust offset to end of normalized selection
    if (selection.getOffset() == offset)
        offset = selection.getOffset() + selection.getLength();
    String prefix = extractPrefix(viewer, offset);
    Region region = new Region(offset - prefix.length(), prefix.length());
    // If there's no prefix, check if we're in a tag open region
    if (prefix.trim().length() == 0) {
        IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, offset);
        if (treeNode instanceof IDOMText) {
            IDOMNode node = (IDOMNode) treeNode;
            // Check each region in the node, if the offset is after a tag region, replace it with the template
            IStructuredDocumentRegion cursor = node.getFirstStructuredDocumentRegion();
            IStructuredDocumentRegion end = node.getLastStructuredDocumentRegion();
            do {
                if (cursor != null && DOMRegionContext.XML_TAG_OPEN.equals(cursor.getType()) && cursor.getStartOffset() == offset - 1) {
                    // We have a tag to replace
                    offset = cursor.getStartOffset();
                    region = new Region(cursor.getStartOffset(), cursor.getLength());
                    break;
                }
            } while (cursor != end && (cursor = cursor.getNext()) != null);
        }
    }
    TemplateContext context = createContext(viewer, region, offset);
    if (context == null)
        return new ICompletionProposal[0];
    // name of the selection variables {line, word}_selection
    // //$NON-NLS-1$
    context.setVariable("selection", selection.getText());
    Template[] templates = getTemplates(context.getContextType().getId());
    List matches = new ArrayList();
    for (int i = 0; i < templates.length; i++) {
        Template template = templates[i];
        try {
            context.getContextType().validate(template.getPattern());
        } catch (TemplateException e) {
            continue;
        }
        if (template.matches(prefix, context.getContextType().getId()))
            matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
    }
    Collections.sort(matches, fgProposalComparator);
    return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) TemplateException(org.eclipse.jface.text.templates.TemplateException) ArrayList(java.util.ArrayList) TemplateContext(org.eclipse.jface.text.templates.TemplateContext) ReplaceNameTemplateContext(org.eclipse.wst.xml.ui.internal.contentassist.ReplaceNameTemplateContext) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ITextSelection(org.eclipse.jface.text.ITextSelection) Template(org.eclipse.jface.text.templates.Template) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMText(org.eclipse.wst.xml.core.internal.provisional.document.IDOMText) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ArrayList(java.util.ArrayList) List(java.util.List)

Example 69 with Template

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

the class DTDUIPreferenceInitializer method initializeDefaultPreferences.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
	 */
public void initializeDefaultPreferences() {
    IPreferenceStore store = DTDUIPlugin.getDefault().getPreferenceStore();
    ColorRegistry registry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
    // DTD Style Preferences
    // $NON-NLS-1$
    String NOBACKGROUNDBOLD = " | null | false";
    // $NON-NLS-1$
    String JUSTITALIC = " | null | false | true";
    String styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_DEFAULT, 0, 0, 0) + NOBACKGROUNDBOLD;
    // black
    store.setDefault(IStyleConstantsDTD.DTD_DEFAULT, styleValue);
    styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_TAG, 63, 63, 191) + NOBACKGROUNDBOLD;
    // blue
    store.setDefault(IStyleConstantsDTD.DTD_TAG, styleValue);
    styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_TAGNAME, 63, 63, 191) + NOBACKGROUNDBOLD;
    // blue
    store.setDefault(IStyleConstantsDTD.DTD_TAGNAME, styleValue);
    styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_COMMENT, 127, 127, 127) + NOBACKGROUNDBOLD;
    // grey
    store.setDefault(IStyleConstantsDTD.DTD_COMMENT, styleValue);
    styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_KEYWORD, 128, 0, 0) + NOBACKGROUNDBOLD;
    // dark
    store.setDefault(IStyleConstantsDTD.DTD_KEYWORD, styleValue);
    // red
    styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_STRING, 63, 159, 95) + JUSTITALIC;
    // green
    store.setDefault(IStyleConstantsDTD.DTD_STRING, styleValue);
    styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_DATA, 191, 95, 95) + NOBACKGROUNDBOLD;
    // light
    store.setDefault(IStyleConstantsDTD.DTD_DATA, styleValue);
    // red
    styleValue = ColorHelper.findRGBString(registry, IStyleConstantsDTD.DTD_SYMBOL, 128, 0, 0) + NOBACKGROUNDBOLD;
    // dark
    store.setDefault(IStyleConstantsDTD.DTD_SYMBOL, styleValue);
    // red
    // set default new xml file template to use in new file wizard
    /*
		 * Need to find template name that goes with default template id (name
		 * may change for differnt language)
		 */
    // $NON-NLS-1$
    String templateName = "";
    // $NON-NLS-1$
    Template template = DTDUIPlugin.getDefault().getTemplateStore().findTemplateById("org.eclipse.wst.dtd.ui.internal.templates.xmldeclaration");
    if (template != null)
        templateName = template.getName();
    store.setDefault(DTDUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName);
    store.setDefault(DTDUIPreferenceNames.ACTIVATE_PROPERTIES, true);
}
Also used : ColorRegistry(org.eclipse.jface.resource.ColorRegistry) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Template(org.eclipse.jface.text.templates.Template)

Example 70 with Template

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

the class NewDTDTemplatesWizardPage method saveLastSavedPreferences.

/**
 * Save template name used for next call to New DTD File wizard.
 */
void saveLastSavedPreferences() {
    // $NON-NLS-1$
    String templateName = "";
    Template template = getSelectedTemplate();
    if (template != null) {
        templateName = template.getName();
    }
    DTDUIPlugin.getDefault().getPreferenceStore().setValue(DTDUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName);
    DTDUIPlugin.getDefault().savePluginPreferences();
}
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