Project Wizard

Optionally, Xtext can generate a New Project Wizard for your DSL. Using this wizard a user can create a new project with only a few clicks that is configured with the right dependencies and natures. By default it contains a sample model file and workflow that serve as a scaffold for the user. Furthermore it has the Xtext nature and thereby the builder assigned. You enable the generation of the project wizard by adding the SimpleProjectWizardFragment fragment to the workflow:

import org.eclipse.xtext.ui.generator.* 

// project wizard fragment
fragment = projectWizard.SimpleProjectWizardFragment {
  generatorProjectName = "${projectName}.generator"
  modelFileExtension = file.extensions
}

Here

After running the Xtext generator, the DSL’s UI project will contain a new Xpand template MyDslNewProject.xpt in the src folder in the package .ui.wizard. Note: It may be necessary to manually merge the new entry in the _plugin.xml___gen_ into your plugin.xml of the UI project to enable the wizard contribution.

The generated Xpand template will be expanded by the project wizard when the user clicks the Finish button and it is responsible for initializing the project with some sample content. When finishing the wizard the template will be used to create a sample model file and a simple workflow to run the model through the generator project’s MyDslGenerator.mwe workflow. However, this is only a pragmatic default. As the Xpand template is in the src source folder you may of course modify it to generate whatever initial content you want for a new project. Just make sure to leave the top-level main definition in place, as that is the interface for the project wizard.

Note: To edit the generated Xpand template you should check that the JavaBeans meta model contributor is enabled under Preferences > Xtend/Xpand. Further you should also configure the UI project with the Xpand/Xtend nature using Configure > Add Xpand/Xtend Nature in the context menu.

Customizing the Project Wizard

To further customize the creation of the project you can implement your own project creator. The default project creator is represented by the generated class MyDslProjectCreator in the src-gen folder. It is highly extensible. Without any changes it will simply create a new plug-in project with the Xtext nature assigned. Afterwards it will execute the main definition of the Xpand template as described above.

To add more pages or input fields to the project wizard you should subclass the class MyDslNewProjectWizard as appropriate. Don’t forget to register the subclass in the UI project’s MyDslUiModule. You may also want to make additionally entered user data available to the Xpand template. In this case you should enhance the MyDslProjectInfo to allow that one to hold the information. This is the context object which gets passed to the template when it’s executed. Don’t forget that your specialized MyDslNewProjectWizard has to populate the data fields of your MyDslProjectInfo.