Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Preference page for separate generator(Show compiler preference page for a separate generator)
Preference page for separate generator [message #1386716] Thu, 19 June 2014 18:51 Go to next message
David Paz is currently offline David PazFriend
Messages: 9
Registered: November 2013
Junior Member
Hello,

I have two generator for the same language. Generators works well, they generate code to the correct outlet, configured with custom OutputConfigurationProvider. The problem is that the second generator uses properly the bound OutputConfigurationProvider but I would like to make the OutputConfiguration options available in the eclipse preferences just as with the original dsl run-time project.

Just note please that I used the runtime and ui plugin from generated dsl project as seed for the second generator. Removed most of the code and the grammar artifacts.

Thanks in advance for any help or advice on where to look at.
Regards,
David

Re: Preference page for separate generator (Workaround) [message #1386840 is a reply to message #1386716] Sat, 21 June 2014 11:57 Go to previous messageGo to next message
David Paz is currently offline David PazFriend
Messages: 9
Registered: November 2013
Junior Member
So answering my self now. So far I did come with a workaround so, in case anyone find a good solution for this please share it.

Since each plug-in (external generator) interested in hook into the generation process should use the extension point: org.eclipse.xtext.builder.participant

Having this ConfigurationProvider declared on main DSL UI plug-in and bound in each generator UI plug-in:
class EntityOutputConfigurationProvider extends OutputConfigurationProvider {

	/**
	 * Configure outlets for generators.
	 * 
	 * Each external generator interested on having an output configuration section must 
	 * implement {@link IEntityParticipantGenerator} so this provider can grab it.
	 * 
	 */
	def override Set<OutputConfiguration> getOutputConfigurations() {
		val Set<OutputConfiguration> options = super.outputConfigurations

		val IConfigurationElement[] configs = Platform.getExtensionRegistry().
			getConfigurationElementsFor("org.eclipse.xtext.builder.participant");
		for (IConfigurationElement config : configs) {
			try {
				val participant = config.createExecutableExtension("class") as BuilderParticipant
				if(participant.generator.class.interfaces.exists[I | I == IEntityParticipantGenerator])
					options.addAll( 
                                            (participant.generator as IEntityParticipantGenerator).outputConfigurations )
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return options
	}
}


The IEntityParticipantGenerator is just this:
/**
 * Each generator should provides its own output configurations
 */
interface IEntityParticipantGenerator {
	def Set<OutputConfiguration> getOutputConfigurations()
}


Then in each external generator it is implemented the "getOutputConfigurations" method and on the main DSL compiler preference page we get the output configuration for each generator.

Then also looking at xtextcasts.org it is shown how to have a preference page for custom options.

Drawbacks?
* The configuration split in several preference pages for each generator doesn't look good.
* The sections in the main output configuration can became confusing if several generators are added like this.

That's why I was looking into a way to have each generator output preferences in its own page and get it used by IFileSystemAccess when generating. Maybe I'm just looking into the wrong direction.

Best regards.
David
Re: Preference page for separate generator (Workaround) [message #1387077 is a reply to message #1386840] Mon, 23 June 2014 23:22 Go to previous messageGo to next message
David Paz is currently offline David PazFriend
Messages: 9
Registered: November 2013
Junior Member
Another update. This solution seem to be far more better. It is just about configuring extension points in pulgin.xml file of the UI project.


  • 1 Create org.eclipse.ui.keywords extension. With this we declare a unique id for make reference to it later on.
  • 2 Create org.eclipse.ui.preferencePages extension. With this we create necessary code base to have our Preference page. Change the id field to use the id we declared before in org.eclipse.ui.keywords and give a meaningful name to the page Smile. Leave the category field empty so the plug-in has its own page in the top most level in the hierarchy of pages when displaying.
  • 3 When the preference page is created, the org.eclipse.core.runtime.preferences also gets created. Both the PreferencePage as well as the PreferenceInitializer can be configured to meet your needs.
  • 4 Create another page for the Compiler output. Set up the category field to be the the class you are using for the PreferencePage. The class field must be configured using the ExecutableExtensionFactory class from the UI plug-in and providing to it the: org.eclipse.xtext.builder.preferences.BuilderPreferencePage. It should be like: my.package.ui.ExecutableExtensionFactory:org.eclipse.xtext.builder.preferences.BuilderPreferencePage


With this we get the page needed, it is still missing the project scope specific preferences, only workspace scoped preferences. Get the clue on xtextcasts.org chapter 21.. Can not put full url on thread.

Hope this help.
Regards,
David
Re: Preference page for separate generator (Workaround) [message #1387098 is a reply to message #1387077] Tue, 24 June 2014 06:15 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hi David,

Here is an example how to restrict the scope, perhaps it works for your situation as well.

reducing cross reference to current DSL file [message #1229358] at
https://www.eclipse.org/forums/index.php/t/635607/
Previous Topic:Subclassing code generators (example: Swing UI)
Next Topic:How to start
Goto Forum:
  


Current Time: Fri Mar 29 13:04:44 GMT 2024

Powered by FUDForum. Page generated in 0.04186 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top