Search in sources :

Example 11 with TemplateContextType

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

the class TemplatePreferencePage method add.

private void add() {
    Iterator<TemplateContextType> it = fContextTypeRegistry.contextTypes();
    if (it.hasNext()) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Template template = new Template("", "", it.next().getId(), "", true);
        Template newTemplate = editTemplate(template, false, true);
        if (newTemplate != null) {
            TemplatePersistenceData data = new TemplatePersistenceData(newTemplate, true);
            fTemplateStore.add(data);
            fTableViewer.refresh();
            fTableViewer.setChecked(data, true);
            fTableViewer.setSelection(new StructuredSelection(data));
        }
    }
}
Also used : TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) Template(org.eclipse.jface.text.templates.Template)

Example 12 with TemplateContextType

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

the class ErlTemplateCompletionProcessor method getTemplates.

@Override
protected Template[] getTemplates(final String contextTypeId) {
    final Template[] templates = ErlideUIPlugin.getDefault().getTemplateStore().getTemplates();
    final TemplateContextType type = ErlideUIPlugin.getDefault().getContextTypeRegistry().getContextType(contextTypeId);
    if (type instanceof ErlangTemplateContextType) {
        final List<Template> result = new ArrayList<>(templates.length);
        final ErlangTemplateContext etc = new ErlangTemplateContext(type, fDocument, offset, length);
        for (final Template template : templates) {
            if (etc.canEvaluate(template)) {
                result.add(template);
            }
        }
        return result.toArray(new Template[result.size()]);
    }
    return templates;
}
Also used : ArrayList(java.util.ArrayList) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) Template(org.eclipse.jface.text.templates.Template)

Example 13 with TemplateContextType

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

the class NewLayoutTplWizard method getDefaultProvider.

@Override
protected IDataModelProvider getDefaultProvider() {
    LayoutTplUI defaultUI = LayoutTplUI.getDefault();
    TemplateStore templateStore = defaultUI.getTemplateStore();
    ContextTypeRegistry contextTypeRegistry = defaultUI.getTemplateContextRegistry();
    TemplateContextType contextType = contextTypeRegistry.getContextType(LayoutTplTemplateContextTypeIds.NEW);
    return new NewLayoutTplDataModelProvider() {

        @Override
        public IDataModelOperation getDefaultOperation() {
            return new AddLayoutTplOperation(getDataModel(), templateStore, contextType);
        }
    };
}
Also used : NewLayoutTplDataModelProvider(com.liferay.ide.layouttpl.core.operation.NewLayoutTplDataModelProvider) LayoutTplUI(com.liferay.ide.layouttpl.ui.LayoutTplUI) ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) TemplateStore(org.eclipse.jface.text.templates.persistence.TemplateStore) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 14 with TemplateContextType

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

the class LiferayUIPlugin method _registerResolvers.

private void _registerResolvers() {
    ContextTypeRegistry templateContextRegistry = JavaPlugin.getDefault().getTemplateContextRegistry();
    Iterator<?> ctIter = templateContextRegistry.contextTypes();
    while (ctIter.hasNext()) {
        Object next = ctIter.next();
        if (next instanceof TemplateContextType) {
            TemplateContextType contextType = (TemplateContextType) next;
            if (contextType.getId().equals("java")) {
                contextType.addResolver(new ServiceClassNameResolver());
            }
        }
    }
}
Also used : ServiceClassNameResolver(com.liferay.ide.ui.templates.ServiceClassNameResolver) ContextTypeRegistry(org.eclipse.jface.text.templates.ContextTypeRegistry) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType)

Example 15 with TemplateContextType

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

the class ServiceXmlTemplateCompletinoProcessor method getContextType.

@Override
protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) {
    TemplateContextType type = null;
    ContextTypeRegistry registry = getTemplateContextRegistry();
    if (registry != null) {
        type = registry.getContextType(ServiceXmlContextType.ID_SERVICE_XML_TAG);
    }
    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