Java Code Examples for org.eclipse.xtext.ui.editor.contentassist.ITemplateAcceptor#accept()

The following examples show how to use org.eclipse.xtext.ui.editor.contentassist.ITemplateAcceptor#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckCfgTemplateProposalProvider.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@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)));
    }
  }
}
 
Example 2
Source File: GamlTemplateProposalProvider.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void createTemplates(final TemplateContext templateContext, final ContentAssistContext context,
		final ITemplateAcceptor acceptor) {
	// Disabling for comments (see Issue 786)
	final EObject grammarElement = context.getCurrentNode().getGrammarElement();
	if (grammarElement == ga.getML_COMMENTRule()) { return; }
	if (grammarElement == ga.getSL_COMMENTRule()) { return; }
	// TemplateContextType contextType = templateContext.getContextType();
	final Template[] templates = store.getTemplates();
	for (final Template template : templates) {
		if (!acceptor.canAcceptMoreTemplates()) { return; }
		if (validate(template, templateContext)) {
			acceptor.accept(
					createProposal(template, templateContext, context, getImage(template), getRelevance(template)));
		}
	}

}
 
Example 3
Source File: DefaultTemplateProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@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)));
		}
	}
}
 
Example 4
Source File: CheckCfgTemplateProposalProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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"; //$NON-NLS-1$
  final String templateDescription = "configures all missing catalogs"; //$NON-NLS-1$

  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());
        builder.append("catalog ").append(catalogName).append(" {}").append(Strings.newLine()); //$NON-NLS-1$ //$NON-NLS-2$
      }

    }

    if (builder.length() > 0) {
      builder.append("${cursor}"); //$NON-NLS-1$
      Template t = new Template(templateName, templateDescription, contextTypeId, builder.toString(), true);
      TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCatalog(), getRelevance(t));
      acceptor.accept(tp);
    }
  }
}
 
Example 5
Source File: CheckCfgTemplateProposalProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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
      final StringJoiner paramsJoiner = new StringJoiner(", ", " (", ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      paramsJoiner.setEmptyValue(""); //$NON-NLS-1$
      for (final FormalParameter param : check.getFormalParameters()) {
        final String paramName = param.getName();
        final Object defaultValue = interpreter.evaluate(param.getRight()).getResult();

        final String valuePlaceholder = helper.createLiteralValuePattern(paramName, defaultValue);
        paramsJoiner.add(paramName + " = " + valuePlaceholder); //$NON-NLS-1$
      }

      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 + qualifiedNameValueConverter.toString(checkName) + paramsJoiner + "${cursor}"; //$NON-NLS-1$

      Template t = new Template(checkName, description, contextTypeId, pattern, true);
      TemplateProposal tp = createProposal(t, templateContext, context, images.forConfiguredCheck(check.getDefaultSeverity()), getRelevance(t));
      acceptor.accept(tp);
    }
  }
}
 
Example 6
Source File: SGenTemplateProposalProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private void createFeatureConfigurationTemplates(TemplateContext templateContext, ContentAssistContext context,
		ITemplateAcceptor acceptor) {
	GeneratorModel model = (GeneratorModel) EcoreUtil2.getRootContainer(context.getCurrentModel());

	Optional<IGeneratorDescriptor> generatorDescriptor = GeneratorExtensions
			.getGeneratorDescriptor(model.getGeneratorId());
	if (!generatorDescriptor.isPresent()) {
		return;
	}
	Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions
			.getLibraryDescriptors(generatorDescriptor.get().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(GenmodelActivator.getInstance()
									.getInjector(GenmodelActivator.ORG_YAKINDU_SCT_GENERATOR_GENMODEL_SGEN)),
							context.getCurrentModel()),
					false);
			TemplateProposal proposal = createProposal(template, templateContext, context, getImage(template),
					getRelevance(template));
			acceptor.accept(proposal);
		}
	}
}