Search in sources :

Example 46 with Template

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

the class PortTypeBody method addGetreplyProposals.

/**
 * Adds the "getreply" related operations of port types, to the completion
 * list.
 *
 * @param propCollector the proposal collector
 * @param i index, not used
 */
public static void addGetreplyProposals(final ProposalCollector propCollector, final int i) {
    propCollector.addProposal("getreply", "getreply", ImageCache.getImage("port.gif"), "");
    propCollector.addTemplateProposal("getreply", new Template("getreply from myPartner", "from clause", propCollector.getContextIdentifier(), "getreply from ${myPartner};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
    propCollector.addTemplateProposal("getreply", new Template("getreply( templateInstance ) -> value myReturnValue param(parameters) sender mySenderVar", "value, parameters and sender clause", propCollector.getContextIdentifier(), "getreply( ${templateInstance} ) -> value ${myReturnValue} param( ${parameters} ) sender ${mySenderVar};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
}
Also used : Template(org.eclipse.jface.text.templates.Template) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)

Example 47 with Template

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

the class PortTypeBody method addCheckProposals.

/**
 * Adds the "check" related operations of port types, to the completion
 * list.
 *
 * @param propCollector the proposal collector
 * @param i index, not used
 */
public static void addCheckProposals(final ProposalCollector propCollector, final int i) {
    propCollector.addProposal("check", "check", ImageCache.getImage("port.gif"), "");
    propCollector.addTemplateProposal("check", new Template("check( portOperation )", "", propCollector.getContextIdentifier(), "check( ${portOperation} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
    propCollector.addTemplateProposal("check", new Template("check( from myPeer)", "form clause", propCollector.getContextIdentifier(), "check( from ${myPeer});", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
    propCollector.addTemplateProposal("check", new Template("check( from myPeer -> value myVar)", "form and value clause", propCollector.getContextIdentifier(), "check( from ${myPeer} -> value ${myVar});", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
    propCollector.addTemplateProposal("check", new Template("check( -> value myVar)", "value clause", propCollector.getContextIdentifier(), "check( -> value ${myVar} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
    propCollector.addTemplateProposal("check", new Template("check( -> value myVar sender myPeer)", "value and sender clause", propCollector.getContextIdentifier(), "check( -> value ${myVar} sender ${myPeer} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
}
Also used : Template(org.eclipse.jface.text.templates.Template) Def_Var_Template(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template)

Example 48 with Template

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

the class Testcase_Type method addProposal.

@Override
public /**
 * {@inheritDoc}
 */
void addProposal(final ProposalCollector propCollector, final int i) {
    final List<ISubReference> subrefs = propCollector.getReference().getSubreferences();
    if (subrefs.size() != i + 1 || Subreference_type.arraySubReference.equals(subrefs.get(i).getReferenceType())) {
        return;
    }
    propCollector.addTemplateProposal("apply", new Template("apply( parameters )", "", propCollector.getContextIdentifier(), "apply( ${parameters} )", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
}
Also used : ISubReference(org.eclipse.titan.designer.AST.ISubReference) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Template(org.eclipse.jface.text.templates.Template)

Example 49 with Template

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

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

the class CheckCfgTemplateProposalProvider method addCatalogConfigurations.

/**
 * Adds the populated check configuration.
 *
 * @param templateContext
 *          the template context
 * @param context
 *          the context
 * @param acceptor
 *          the acceptor
 */
@SuppressWarnings("all")
private void addCatalogConfigurations(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
    // $NON-NLS-1$
    final String templateName = "Add all registered catalogs";
    // $NON-NLS-1$
    final String templateDescription = "configures all missing catalogs";
    final String contextTypeId = templateContext.getContextType().getId();
    if (context.getRootModel() instanceof CheckConfiguration) {
        final CheckConfiguration conf = (CheckConfiguration) context.getRootModel();
        List<IEObjectDescription> allElements = Lists.newArrayList(scopeProvider.getScope(conf, CheckcfgPackage.Literals.CONFIGURED_CATALOG__CATALOG).getAllElements());
        StringBuilder builder = new StringBuilder();
        for (IEObjectDescription description : allElements) {
            if (description.getEObjectOrProxy() instanceof CheckCatalog) {
                CheckCatalog catalog = (CheckCatalog) description.getEObjectOrProxy();
                if (catalog.eIsProxy()) {
                    catalog = (CheckCatalog) EcoreUtil.resolve(catalog, conf);
                }
                if (isCatalogConfigured(conf, catalog)) {
                    continue;
                } else if (allElements.indexOf(description) > 0) {
                    builder.append(Strings.newLine());
                }
                final String catalogName = qualifiedNameValueConverter.toString(description.getQualifiedName().toString());
                // $NON-NLS-1$ //$NON-NLS-2$
                builder.append("catalog ").append(catalogName).append(" {}").append(Strings.newLine());
            }
        }
        if (builder.length() > 0) {
            // $NON-NLS-1$
            builder.append("${cursor}");
            Template t = new Template(templateName, templateDescription, contextTypeId, builder.toString(), true);
            TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCatalog(), getRelevance(t));
            acceptor.accept(tp);
        }
    }
}
Also used : TemplateProposal(org.eclipse.jface.text.templates.TemplateProposal) CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) CheckCatalog(com.avaloq.tools.ddk.check.check.CheckCatalog) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) 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