Search in sources :

Example 46 with TemplateContextType

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

the class ContributionContextTypeRegistry method addContextType.

/**
 * Tries to create a context type given an id. If there is already a context
 * type registered under the given id, nothing happens. Otherwise,
 * contributions to the <code>org.eclipse.ui.editors.templates</code>
 * extension point are searched for the given identifier and the specified
 * context type instantiated if it is found.
 *
 * @param id the id for the context type as specified in XML
 */
public void addContextType(String id) {
    Assert.isNotNull(id);
    if (getContextType(id) != null)
        return;
    TemplateContextType type = createContextType(id);
    if (type != null)
        addContextType(type);
}
Also used : TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 47 with TemplateContextType

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

the class ContributionContextTypeRegistry method createContextType.

/**
 * Tries to create a context type given an id. Contributions to the
 * <code>org.eclipse.ui.editors.templates</code> extension point are
 * searched for the given identifier and the specified context type
 * instantiated if it is found. Any contributed
 * {@link org.eclipse.jface.text.templates.TemplateVariableResolver}s
 * are also instantiated and added to the context type.
 *
 * @param id the id for the context type as specified in XML
 * @return the instantiated and configured context type, or
 *         <code>null</code> if it is not found or cannot be instantiated
 */
public static TemplateContextType createContextType(String id) {
    Assert.isNotNull(id);
    IConfigurationElement[] extensions = getTemplateExtensions();
    TemplateContextType type;
    try {
        type = createContextType(extensions, id);
        if (type != null) {
            TemplateVariableResolver[] resolvers = createResolvers(extensions, id);
            for (int i = 0; i < resolvers.length; i++) type.addResolver(resolvers[i]);
        }
    } catch (CoreException e) {
        // EditorsPlugin.log(e);
        type = null;
    }
    return type;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) TemplateVariableResolver(org.eclipse.jface.text.templates.TemplateVariableResolver)

Example 48 with TemplateContextType

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

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

the class XtextTemplateContextTest method setUp.

@Before
public void setUp() throws Exception {
    document = new Document();
    position = new Position(0);
    testMe = new XtextTemplateContext(new TemplateContextType(), document, position, null, null);
}
Also used : Position(org.eclipse.jface.text.Position) XtextTemplateContext(org.eclipse.xtext.ui.editor.templates.XtextTemplateContext) Document(org.eclipse.jface.text.Document) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) Before(org.junit.Before)

Example 50 with TemplateContextType

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

TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)55 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 StyledString (org.eclipse.jface.viewers.StyledString)3 Reference (org.eclipse.titan.designer.AST.Reference)3