The generation process is driven by Scenario Tree provided by Scenario.xml file. The Scenario Tree describes how to drive automatic generation processes.
Indeed, as explained in this page a scenario transforms an input (XML files, Pojos) into a GENERATED XML file which describes the body of a part (Editor, Query, Detail UI…).
For instance, The DetailScenario class builds XML file like FilmDIGENERATED.axml (see Scenario architecture).

An example of Scenario Tree can be see here.


However, only common cases can be dealt by the set of scenarios given by default.
In order to get around this limitation, you can create your own scenario tree file which describes specific features for the generation processes. You can specify:

  • New scenarios, generators, path elements, parameters can be specified or added to the Scenario Tree before launching or relaunching generation processes.
  • Pojo rewriter for injecting changes in Pojos (e.g. org.adichatz.scenario.generation.SuperPojoRewriter is a java class for rewrite Pojo in order to add a super class.
  • Specific features as new item value, validators or listeners can be added to the scenario tree.

These changes can be manually made by the developper inside the Scenario.xml file. A other way is to assemble changes inside a new Scenario tree stored in a specific xml file

For example, open file [eclipse_dir]/plugins/org.adichatz.template/template/connectors/pagilaMappingOverride.xml. Following XML elements:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<scenarioTree xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adichatz.org/xsd/v0.9.1/generator/scenarioTree.xsd">
    <pathElements>
        <pathElement type="PROJECT" location="myscenario"/>
    </pathElements>
	<params>
    	<param id="devl.default.integer.pattern" value="#####"/>
    </params>
    <generators>
        <generator treeClassName="org.adichatz.generator.wrapper.TableWrapper" generatorClassName="org.mycompany.myscenario.generator.MyTableGenerator"/>
        <generator treeClassName="#CONTROLGENERATOR()" generatorClassName="org.mycompany.myscenario.generator.MyControlGenerator"/>
    </generators>
    <generationScenario>
        <generationUnit scenarioClassName="org.mycompany.myscenario.scenario.MyDetailScenario" type="DETAIL"/>
		<modelPart>
    		<pojoRewriters>
	    		<pojoRewriter rewriterClassName="org.adichatz.scenario.generation.PgPojoIdRewriter"/>
	    		<pojoRewriter rewriterClassName="org.adichatz.scenario.generation.SuperPojoRewriter" propertyRegex="lastUpdate">
	    			<params>
	    				<param id="superClassURI" value="bundleclass://./..model.ASuperLastUpdateClass"/>
	    				<param id="sourceURI" value="platform:/plugin/org.adichatz.template/template/src/ASuperLastUpdateClass.java"/>
	    			</params>
	    		</pojoRewriter>
			</pojoRewriters>
    	</modelPart>
		<propertyField id="lastUpdate">
        	<controlField xsi:type="dateTextType" enabled="false" style="SWT.BORDER | SWT.TIME"/>
		</propertyField>
		<propertyField id="rating" pojoType="#ENUM(MpaaRatingEnum, {G, PG, PG-13, R, NC-17})">
        	<controlField xsi:type="cComboType">
				<labelProvider>
	               <textCode>return ((#MODELPACKAGE().MpaaRatingEnum) element).getValue();</textCode>
				</labelProvider>
				<initValues>return java.util.Arrays.asList(#MODELPACKAGE().MpaaRatingEnum.values());</initValues>
			</controlField>
		</propertyField>
		<propertyField id="fulltext" pojoType="tsvector"/>
		<pluginEntity entityURI="adi://././FilmMM">
			<messages>
        		<message key="invalid.year.value" value="Invalid year '{0}'! Value must be between 1900 and 2155"/>
        		<message key="invalid.year.value" value="'{0}' n'est pas une année valide! La valeur doit être entre 1900 et 2155" language="fr"/>
        	</messages>
            <params>
                <param id="FULLTEXT_RESOURCE_URI" type="QUERY_ITEM" value="adi://org.adichatz.jpa/query/FullTextInclude"/>
            </params>
            <propertyField id="releaseYear" pojoType="int">
		        <controlField xsi:type="formattedTextType" editPattern="####" format="Integer">
		        	<validators>
	           			<validator key="invalidYear" errorMessage="#MSG(film, invalid.year.value, #FV())">
	           				<errorWhen>return #FV() &lt; 1900 ||  #FV() &gt; 2155;</errorWhen>
	           			</validator>
		        	</validators>
		        </controlField>
            </propertyField>
            <propertyField id="specialFeatures" pojoType="String[]">
		        <controlField xsi:type="multiChoiceType" values="Trailers,Commentaries,Deleted Scenes,Behind the Scenes" multiChoiceType="Array" popupToolbar="true">
		        	<convertTargetToModel>return java.util.Arrays.copyOf((Object[]) value, ((Object[]) value).length, String[].class);</convertTargetToModel>
		        </controlField>
            </propertyField>
        </pluginEntity>
    </generationScenario>
</scenarioTree>

Remarks:

Line 4:A new project containing resources (classes) is added to the path for generation processes.
Lines 11-12:2 new Generators are used instead of standard generators.
Lines 17-23:2 new pojo rewriters are executed after Pojos are generated.
Lines 26-28:The controller for lastUpdate property will be a DateTextController for any entity of the project.
Lines 29-36:The rating property has a enum type (PostgresSQL database) and is displayed in a CComboController controller for any entity of the project.
Line 37:The fullText property must be considered as a tsvector (fulltext feature in PostgresSQL database): that means it is not mapped in the client side.
Lines 40-41:2 items are added to the message bundle file linked to the Film entity (filmGENERATED.properties file).
Line 44:a new parameter is passed when building navigator. This item provides a Fulltext feature will be associated to the Query form of the Film entity.
Lines 46-54:Assumes that the value of the releaseYear property must be between 1900 and 2155 (Client side).
Lines 55-59:The value of the specialFeatures property is an array of predetermined values (PostgresSQL database) and uses a MultiChoiceController controller.



This customized Scenario Tree will be merged to the standard Scenario Tree in order to inject the aboved described features in the project.
So, Developpers can build and share powerfull aspects to easily enrich the generation processes.