Search in sources :

Example 16 with TemplateContextType

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

the class Activator method registerTemplateVariableResolvers.

private void registerTemplateVariableResolvers() {
    if (hasJavaPlugin()) {
        final ContextTypeRegistry codeTemplateContextRegistry = JavaPlugin.getDefault().getCodeTemplateContextRegistry();
        final Iterator<?> ctIter = codeTemplateContextRegistry.contextTypes();
        while (ctIter.hasNext()) {
            final TemplateContextType contextType = (TemplateContextType) ctIter.next();
            contextType.addResolver(new GitTemplateVariableResolver(// $NON-NLS-1$
            "git_config", UIText.GitTemplateVariableResolver_GitConfigDescription));
        }
    }
}
Also used : ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) GitTemplateVariableResolver(org.eclipse.egit.ui.internal.variables.GitTemplateVariableResolver) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 17 with TemplateContextType

use of org.eclipse.jface.text.templates.TemplateContextType in project titan.EclipsePlug-ins by eclipse.

the class ContentAssistProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
    IDocument doc = viewer.getDocument();
    IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class);
    ASN1ReferenceParser refParser = new ASN1ReferenceParser();
    Reference ref = refParser.findReferenceForCompletion(file, offset, doc);
    IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.DISPLAYDEBUGINFORMATION, true, null)) {
        TITANDebugConsole.println("parsed the reference: " + ref);
    }
    if (ref == null || ref.getSubreferences().isEmpty()) {
        return new ICompletionProposal[] {};
    }
    Scope scope = null;
    ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
    Module tempModule = projectSourceParser.containedModule(file);
    if (tempModule != null) {
        scope = tempModule.getSmallestEnclosingScope(refParser.getReplacementOffset());
        ref.setMyScope(scope);
        ref.detectModid();
    }
    TemplateContextType contextType = new TemplateContextType(ASN1CodeSkeletons.CONTEXT_IDENTIFIER, ASN1CodeSkeletons.CONTEXT_NAME);
    ProposalCollector propCollector = new ProposalCollector(Identifier_type.ID_ASN, ASN1CodeSkeletons.CONTEXT_IDENTIFIER, contextType, doc, ref, refParser.getReplacementOffset());
    if (scope != null) {
        scope.addProposal(propCollector);
        propCollector.sortTillMarked();
        propCollector.markPosition();
    }
    if (ref.getSubreferences().size() != 1) {
        return propCollector.getCompletitions();
    }
    if (scope == null) {
        propCollector.addProposal(CodeScanner.TAGS, null, KEYWORD);
    } else {
        ASN1CodeSkeletons.addSkeletonProposals(doc, refParser.getReplacementOffset(), propCollector);
    }
    propCollector.sortTillMarked();
    propCollector.markPosition();
    propCollector.addProposal(CodeScanner.VERBS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.COMPARE_TYPES, null, KEYWORD);
    propCollector.addProposal(CodeScanner.STATUS_TYPE, null, KEYWORD);
    propCollector.addProposal(CodeScanner.KEYWORDS, null, KEYWORD);
    propCollector.addProposal(CodeScanner.STORAGE, null, KEYWORD);
    propCollector.addProposal(CodeScanner.MODIFIER, null, KEYWORD);
    propCollector.addProposal(CodeScanner.ACCESS_TYPE, null, KEYWORD);
    propCollector.sortTillMarked();
    String sortingpolicy = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CONTENTASSISTANT_PROPOSAL_SORTING);
    if (PreferenceConstantValues.SORT_ALPHABETICALLY.equals(sortingpolicy)) {
        propCollector.sortAll();
    }
    return propCollector.getCompletitions();
}
Also used : ProposalCollector(org.eclipse.titan.designer.editors.ProposalCollector) IFile(org.eclipse.core.resources.IFile) Scope(org.eclipse.titan.designer.AST.Scope) Reference(org.eclipse.titan.designer.AST.Reference) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Module(org.eclipse.titan.designer.AST.Module) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 18 with TemplateContextType

use of org.eclipse.jface.text.templates.TemplateContextType in project dsl-devkit by dsldevkit.

the class CheckCfgTemplateProposalProvider method createTemplates.

@Override
protected void createTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
    if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck")) {
        // $NON-NLS-1$
        addConfiguredCheckTemplates(templateContext, context, acceptor);
        return;
    } else if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.kw_catalog")) {
        // $NON-NLS-1$
        addCatalogConfigurations(templateContext, context, 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 19 with TemplateContextType

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

the class HTMLTemplateCompletionProcessor 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 20 with TemplateContextType

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

the class CSSTemplateCompletionProcessor 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)

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