Java 类org.eclipse.xtext.ui.editor.contentassist.ITemplateAcceptor 实例源码

项目:dsl-devkit    文件:CheckCfgTemplateProposalProvider.java   
@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)));
    }
  }
}
项目:bts    文件:DefaultTemplateProposalProvider.java   
@Override
protected void createTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor 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)));
        }
    }
}
项目:bts    文件:AbstractTemplateProposalProvider.java   
public void createTemplates(ContentAssistContext context, ITemplateAcceptor acceptor) {
    if (!acceptor.canAcceptMoreTemplates())
        return;
    TemplateContext[] templateContexts = createTemplateContexts(context);
    if (templateContexts == null || templateContexts.length == 0)
        return;

    ITemplateAcceptor nullSafe = new NullSafeTemplateAcceptor(acceptor);
    for(TemplateContext templateContext: templateContexts) {
        if (!nullSafe.canAcceptMoreTemplates())
            return;
        templateContext.setVariable("selection", context.getSelectedText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$
        createTemplates(templateContext, context, nullSafe);
    }
}
项目:statecharts    文件:SGenTemplateProposalProvider.java   
@Override
protected void createTemplates(TemplateContext templateContext, ContentAssistContext context,
        ITemplateAcceptor acceptor) {
    super.createTemplates(templateContext, context, acceptor);

    String id = helper.getId(gaccess.getFeatureConfigurationRule());
    if (templateContext.getContextType().getId().equals(id)) {
        createFeatureConfigurationTemplates(templateContext, context, acceptor);
    }
}
项目:statecharts    文件:SGenTemplateProposalProvider.java   
private void createFeatureConfigurationTemplates(TemplateContext templateContext, ContentAssistContext context,
        ITemplateAcceptor acceptor) {
    GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(context.getCurrentModel());

    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(model.getGeneratorId());

    Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions
            .getLibraryDescriptors(generatorDescriptor.getLibraryIDs());

    for (ILibraryDescriptor desc : libraryDescriptor) {
        ResourceSet set = new ResourceSetImpl();
        Resource resource = set.getResource(desc.getURI(), true);
        FeatureTypeLibrary lib = (FeatureTypeLibrary) resource.getContents().get(0);
        EList<FeatureType> types = lib.getTypes();

        for (FeatureType featureType : types) {
            Template template = new Template(featureType.getName() + " feature",
                    "Creates feature " + featureType.getName(), featureType.getName(),
                    creator.createProposal(featureType,
                            desc.createFeatureValueProvider(SGenActivator.getInstance()
                                    .getInjector(SGenActivator.ORG_YAKINDU_SCT_GENERATOR_GENMODEL_SGEN)),
                            context.getCurrentModel()),
                    false);
            TemplateProposal proposal = createProposal(template, templateContext, context, getImage(template),
                    getRelevance(template));
            acceptor.accept(proposal);
        }
    }
}
项目:dsl-devkit    文件:CheckCfgTemplateProposalProvider.java   
/**
 * 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) {
  final String templateName = "Add all registered catalogs";
  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());
        }

        builder.append("catalog ").append(description.getQualifiedName()).append(" {").append(Strings.newLine());
        for (Check check : catalog.getAllChecks()) {
          builder.append("  default ").append(check.getName()).append(Strings.newLine());
        }
        // CHECKSTYLE:OFF
        builder.append("}");
        builder.append(Strings.newLine());
        // CHECKSTYLE:ON
      }

    }

    if (builder.length() > 0) {
      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);
    }
  }
}
项目:dsl-devkit    文件:CheckCfgTemplateProposalProvider.java   
/**
 * Adds template proposals for all checks which may be referenced in current catalog configuration. Only proposals for checks
 * which have not yet been configured are provided.
 *
 * @param templateContext
 *          the template context
 * @param context
 *          the context
 * @param acceptor
 *          the acceptor
 */
private void addConfiguredCheckTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) { // NOPMD
  ConfiguredCatalog configuredCatalog = EcoreUtil2.getContainerOfType(context.getCurrentModel(), ConfiguredCatalog.class);
  Iterable<String> alreadyConfiguredCheckNames = Iterables.filter(Iterables.transform(configuredCatalog.getCheckConfigurations(), new Function<ConfiguredCheck, String>() {
    @Override
    public String apply(final ConfiguredCheck from) {
      if (from.getCheck() != null) {
        return from.getCheck().getName();
      }
      return null;
    }
  }), Predicates.notNull());
  final CheckCatalog catalog = configuredCatalog.getCatalog();
  for (final Check check : catalog.getAllChecks()) {
    // create a template on the fly
    final String checkName = check.getName();
    if (!Iterables.contains(alreadyConfiguredCheckNames, checkName)) {

      // check if referenced check has configurable parameters
      String paramString = ""; //$NON-NLS-1$
      if (!check.getFormalParameters().isEmpty()) {
        StringBuilder params = new StringBuilder("("); //$NON-NLS-1$
        for (final FormalParameter p : check.getFormalParameters()) {
          final String paramName = p.getName();
          final String defaultValue = String.valueOf(interpreter.evaluate(p.getRight()).getResult());
          params.append(paramName).append(" = ").append("${").append(defaultValue).append('}'); //$NON-NLS-1$ //$NON-NLS-2$
          params.append(", "); //$NON-NLS-1$
        }
        if (params.length() > 2) {
          paramString = params.substring(0, params.length() - 2) + ')';
        }
      }

      final String severity = (catalog.isFinal() || check.isFinal()) ? "default " : "${default:Enum('SeverityKind')} "; //$NON-NLS-1$ //$NON-NLS-2$
      final String description = "Configures the check \"" + check.getLabel() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
      final String contextTypeId = "com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck." + checkName; //$NON-NLS-1$
      final String pattern = severity + checkName + (paramString.length() == 0 ? "${cursor}" : " " + paramString + "${cursor}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

      Template t = new Template(checkName, description, contextTypeId, pattern, true);
      TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCheck(check.getDefaultSeverity()), getRelevance(t));
      acceptor.accept(tp);
    }
  }
}
项目:bts    文件:AbstractTemplateProposalProvider.java   
public NullSafeTemplateAcceptor(ITemplateAcceptor delegate) {
    super();
    setDelegate(delegate);
}
项目:bts    文件:AbstractTemplateProposalProvider.java   
protected abstract void createTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor acceptor);