Search in sources :

Example 11 with ContextTypeRegistry

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

the class XPathTemplateCompletionProcessor 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 12 with ContextTypeRegistry

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

the class XMLTemplateCompletionProcessor 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 13 with ContextTypeRegistry

use of org.eclipse.jface.text.templates.ContextTypeRegistry in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonContentAssistProcessor method getContextType.

@Override
protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) {
    Model model = null;
    if (viewer.getDocument() instanceof JsonDocument) {
        model = ((JsonDocument) viewer.getDocument()).getModel();
    }
    String contextType = getContextTypeId(model, currentPath.toString());
    ContextTypeRegistry registry = getContextTypeRegistry();
    if (registry != null) {
        return registry.getContextType(contextType);
    } else {
        return null;
    }
}
Also used : Model(com.reprezen.swagedit.core.model.Model) ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) StyledString(org.eclipse.jface.viewers.StyledString) JsonDocument(com.reprezen.swagedit.core.editor.JsonDocument)

Example 14 with ContextTypeRegistry

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

the class CodetemplatesProposalProvider method completeVariable_Type.

@Override
public void completeVariable_Type(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if ((mode & NORMAL) != 0) {
        super.completeVariable_Name(model, assignment, context, acceptor);
        TemplateData data = new TemplateData(model);
        if (data.doCreateProposals()) {
            ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(data.language);
            if (helper != null) {
                String contextTypeId = helper.getId(data.rule);
                ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(data.language);
                TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
                if (contextType != null) {
                    Iterator<TemplateVariableResolver> resolvers = Iterators.filter(contextType.resolvers(), TemplateVariableResolver.class);
                    while (resolvers.hasNext()) {
                        TemplateVariableResolver resolver = resolvers.next();
                        String type = resolver.getType();
                        StyledString displayString = new StyledString(type).append(" - " + resolver.getDescription(), StyledString.QUALIFIER_STYLER);
                        acceptor.accept(createCompletionProposal(type, displayString, null, context));
                    }
                }
            }
        }
    }
}
Also used : ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) ContextTypeIdHelper(org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper) IInspectableTemplateVariableResolver(org.eclipse.xtext.ui.codetemplates.ui.resolvers.IInspectableTemplateVariableResolver) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver)

Example 15 with ContextTypeRegistry

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

the class CodetemplatesProposalProvider method completeNestedCrossReference.

public void completeNestedCrossReference(CrossReference crossReference, ContentAssistContext context, ICompletionProposalAcceptor acceptor, TemplateData data) {
    if (data.doCreateProposals()) {
        ContextTypeIdHelper helper = languageRegistry.getContextTypeIdHelper(data.language);
        if (helper != null) {
            String contextTypeId = helper.getId(data.rule);
            ContextTypeRegistry contextTypeRegistry = languageRegistry.getContextTypeRegistry(data.language);
            TemplateContextType contextType = contextTypeRegistry.getContextType(contextTypeId);
            TemplateVariableResolver crossRefResolver = getResolver(contextType, "CrossReference");
            if (crossRefResolver != null) {
                Assignment assignment = (Assignment) crossReference.eContainer();
                EReference reference = GrammarUtil.getReference(crossReference);
                if (reference != null) {
                    String proposalText = "${" + assignment.getFeature() + ":CrossReference(" + reference.getEContainingClass().getName() + "." + reference.getName() + ")}";
                    StyledString displayText = new StyledString("${", StyledString.DECORATIONS_STYLER).append(assignment.getFeature()).append(":CrossReference(", StyledString.DECORATIONS_STYLER).append(reference.getEContainingClass().getName() + "." + reference.getName(), StyledString.COUNTER_STYLER).append(")}", StyledString.DECORATIONS_STYLER).append(" - Create a new template variable", StyledString.QUALIFIER_STYLER);
                    ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
                    if (proposal instanceof ConfigurableCompletionProposal) {
                        ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
                        configurable.setSelectionStart(configurable.getReplacementOffset() + 2);
                        configurable.setSelectionLength(assignment.getFeature().length());
                        configurable.setAutoInsertable(false);
                        configurable.setSimpleLinkedMode(context.getViewer(), '\t');
                        configurable.setPriority(configurable.getPriority() * 2);
                    }
                    acceptor.accept(proposal);
                }
            }
        }
    }
}
Also used : Assignment(org.eclipse.xtext.Assignment) ConfigurableCompletionProposal(org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) ContextTypeIdHelper(org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper) EReference(org.eclipse.emf.ecore.EReference) IInspectableTemplateVariableResolver(org.eclipse.xtext.ui.codetemplates.ui.resolvers.IInspectableTemplateVariableResolver) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver)

Aggregations

ContextTypeRegistry (org.eclipse.jface.text.templates.ContextTypeRegistry)19 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)17 TemplateVariableResolver (org.eclipse.jface.text.templates.TemplateVariableResolver)5 ContextTypeIdHelper (org.eclipse.xtext.ui.editor.templates.ContextTypeIdHelper)5 StyledString (org.eclipse.jface.viewers.StyledString)4 IInspectableTemplateVariableResolver (org.eclipse.xtext.ui.codetemplates.ui.resolvers.IInspectableTemplateVariableResolver)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 TemplateStore (org.eclipse.jface.text.templates.persistence.TemplateStore)2 Grammar (org.eclipse.xtext.Grammar)2 Codetemplate (org.eclipse.xtext.ui.codetemplates.templates.Codetemplate)2 Codetemplates (org.eclipse.xtext.ui.codetemplates.templates.Codetemplates)2 Variable (org.eclipse.xtext.ui.codetemplates.templates.Variable)2 ConfigurableCompletionProposal (org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal)2 NewLayoutTplDataModelProvider (com.liferay.ide.layouttpl.core.operation.NewLayoutTplDataModelProvider)1 LayoutTplUI (com.liferay.ide.layouttpl.ui.LayoutTplUI)1 NewVaadinPortletClassDataModelProvider (com.liferay.ide.portlet.vaadin.core.operation.NewVaadinPortletClassDataModelProvider)1 ServiceClassNameResolver (com.liferay.ide.ui.templates.ServiceClassNameResolver)1 JsonDocument (com.reprezen.swagedit.core.editor.JsonDocument)1 Model (com.reprezen.swagedit.core.model.Model)1 GitTemplateVariableResolver (org.eclipse.egit.ui.internal.variables.GitTemplateVariableResolver)1