<< January 26, 2017 | Home | January 28, 2017 >>

xText - use custom properties in CustomOutputConfigurationProvider

Ok, that is a very special topic and I guess not many will need this.
My problem was that I created a properties-page and wanted to use the folders selected there or to use IProject-related paths or such. I had to hack a little bit to get it to work, but I did it. In the end I could have context-based CustomOutputConfigurations.

Ok, I got it to work but it feels a bit hacky. Here is what I did.

  1. Write OutputConfigurationProvider that implements IContextualOutputProvider2 and place it somewhere in your MyDSL-Modules main-module
public class CustomOutputConfigurationProvider  implements IContextualOutputConfigurationProvider2 {

	override getOutputConfigurations(ResourceSet context) {
		if (context.resources.size()>0){
			// we are now context-aware. With the resource we can access the project
			val Resource res = context.resources.get(0);
			val path = res.URI.toPlatformString(true);
			val file = ResourcesPlugin.workspace.root.findMember(path) as IFile;
			val IProject project = file.project		
			// do what you want! e.g. read properties (as I intend to do)
			val OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT);
			defaultOutput.setDescription("Default Output - Overwrite");
			defaultOutput.useOutputPerSourceFolder = true;
			return newHashSet(defaultOutput);
		return newHashSet();
  1. Bind it in your MyDSLRuntimeModule:
	def Class<? extends IContextualOutputConfigurationProvider2> bindIContextualOutputConfigurationProvider2() {

3)In the UI-Module create a CustomBuilderParticipant that derives from BuilderPartiticpant:

public class CustomBuilderParticipant extends BuilderParticipant {

	private IContextualOutputConfigurationProvider2 outputConfigurationProvider;
	protected Map<String, OutputConfiguration> getOutputConfigurations(IBuildContext context) {
		Set<OutputConfiguration> configurations = outputConfigurationProvider.getOutputConfigurations(context
		return uniqueIndex(configurations, new Function<OutputConfiguration, String>() {
			public String apply(OutputConfiguration from) {
				return from.getName();
  1. Bind this in your UI-Modules MsDSLUIModule.xtend:
	override Class<? extends IXtextBuilderParticipant> bindIXtextBuilderParticipant() {
		return CustomBuilderParticipant;

That's it. Seems to work. Also have a look at a corresponding forum-thread .

Tags : , ,

Export this post as PDF document  Export this post to PDF document

Social Bookmarks :  Add this post to Slashdot    Add this post to Digg    Add this post to Reddit    Add this post to Delicious    Add this post to Stumble it    Add this post to Google    Add this post to Technorati    Add this post to Bloglines    Add this post to Facebook    Add this post to Furl    Add this post to Windows Live    Add this post to Yahoo!

<< January 26, 2017 | Home | January 28, 2017 >>