### Creating a Template Package

1. Create a new plug-in project

2. Add dependencies for `com.ssaglobal.generator` and `com.ssaglobal.generator.ui`, and for the plugin(s) that define the EMF model(s) you want to use to drive your templates. In this example, `com.ssaglobal.istudio.core` defines the EMF model that the templates use.

3. On the Extensions page, add a new `com.ssaglobal.generator.templatepackage` extension.

4. Create a new Base element under the extension point (right-click on the extension point and select New->Base)

   templateRoot
     Path (relative to your plug-in project) that will contain your template files.
   outputRoot
     File system path to the folder that will receive the file(s) generated by your template(s). The path is relative to the path defined in the Business Studio Project Properties
   helppluginid
     Plugin ID of the plugin which contains the help. If the help is in the current plugin, then leave this field empty
   helpid
     Helpid as it is defined in the Context.xml of the help plugin. It should refer to the general help of the template

5. Create a new Template element ((right-click on the extension point and select New->Template) under the extension point for each template in your package.

   template
     The name of the template file.
   nameTemplate
     The name of the template file that will provide the file name for the file that will receive the text generated by `template`.
   appliesToClass
     Fully-qualified name of the Java class (EMF model object) that the template should process. When the generator runs it will invoke the template once for each instance of the class that it finds in the EMF model passed to the generator. Note that the class you select must implement `org.eclipse.emf.ecore.EObject`.
   engine
     Select the template engine to be used to process your template. Note that `FreeMarker` is the only choice that's fully integrated in this version.
   writer
     Select the post processor (if any) to be used to process the template output. The only post processor currently supported is the PDF writer.
   appliesToSubclasses
     Select `true` if the template should process subclasses of `appliesToClass`, or select `false` if it should only process instances of `appliesToClass`. In the example above I selected `com.ssaglobal.istudio.core.model.bid.impl.ComponentImpl` for `appliesToClass`. `BusinessInterfaceDefinitionImpl` is a subclass of `ComponentImpl`, so selecting `true` means that the template will also be used for instances of `BusinessInterfaceDefinitionImpl`.

   Note that the plug-in editor’s class browser will only let you select concrete classes – not interfaces – which is why `com.ssaglobal.istudio.core.model.bid.impl.ComponentImpl` is selected instead of `com.ssaglobal.istudio.core.model.bid.Component` in the example above. The generator will work correctly if you enter an interface instead of a concrete class – you just won’t be able to select an interface using the plug-in editor's `Browse…` button.

6. Create a new `Helper` element under the extension point (right-click on the extension point and select New->Helper) for each helper class used by your package.

   name
     the logical name that you’ll use to access the helper in your templates. In this example, you’d reference the helper in a `FreeMarker` template with ${properties.propertyName}.
   helperClass
     the fully-qualified class name of the helper class, e.g., `com.ssaglobal.generator.helper.PropertiesHelper`.
   appliesToClass
     Fully-qualified name of the Java class (EMF model object) that the helper should process. An instance of the helper class will be created for each template that processes an instance if this class.
   appliesToSubclasses
     Select `true` if the helper should process subclasses of `appliesToClass`, or select `false` if it should only process instances of `appliesToClass`. In this case, `true` is selected and `appliesToClass` is `org.eclipse.emf.ecore.impl.EObjectImpl`, so the `PropertiesHelper` will be instantiated for every template (since all EMF model objects are subclasses of EObjectImpl).

7. Create a new `Property` element under the extension point (right-click on the extension point and select New->Property) for each property used by your package.

   name
     the logical name that you’ll use to access the property in your templates. In this example, you’d reference the helper in a `FreeMarker` template with ${properties.javaPackage} (`properties` is the name assigned to the `PropertiesHelper` in the `Helper` example, and `javaPackage` is the name assigned to the property in this example).
   description
     Enter the description as it should be shown of preference and project property pages.
   value
     Enter the default value for the property. Users of your template package will be able to override the value in the preferences and/or project settings.
   helpid
     Helpid as it is defined in the Context.xml of the help plugin. It should refer to the property specific help of the property. It looks for help in the plugin defined in Base. If no plugin id is defined, then help should be in the current plugin

8. Optionally, create a new `BuildScript` element under the extension point (right-click on the extension point and select New->BuildScript). You need the `BuildScript` element only if you want to run an Ant build script automatically after generating.

   name
     The path to the Ant build script. If you select `true` for the `generated` attribute, this is the path relative to `outputRoot`. If you select `false` for the `generated` attribute, this is the path relative to your plug-in.
   generated
     Select `true` if the build script is generated by your template package. Select `false` if the build script is a static file included as a resource in your template package.

9. Add a new `org.eclipse.ui.popupMenus` extension.

10. Change the menu ID from `<your plugin ID>.menu1` to `com.ssaglobal.generator.ui.menu1` so that your plug-in’s generate action will appear in the Infor Generator menu.

11. Add a new `org.eclipse.ui.preferencePages` extension.

12. On the build page, make sure your Ant script and templates are included in the binary build.

13. Modify the action class that was created for your popup menu extension to invoke the generator. The code should look something like this:

    > `

    >     package com.ssaglobal.generator.testpackage;

    >     import org.eclipse.ui.plugin.AbstractUIPlugin;

    >     public class GenerateAction extends com.ssaglobal.generator.ui.GenerateAction {

    >     	public AbstractUIPlugin getExtensionPlugin() {
    >     		return TestpackagePlugin.getDefault();
    >     	}

    >     }

    > `

    The only change you should need to make to the above example is replacing `TestpackagePlugin` with the name of your plug-in class.

14. Modify the preference initializer class that was created by the preference page wizard. The code should look something like this:

    > `

    >     package com.ssaglobal.generator.testpackage;

    >     import org.eclipse.ui.plugin.AbstractUIPlugin;

    >     import com.ssaglobal.generator.ui.GeneratorPreferenceInitializer;

    >     /**
    >      * Class used to initialize default preference values.
    >      */
    >     public class PreferenceInitializer extends GeneratorPreferenceInitializer {

    >     	public AbstractUIPlugin getExtensionPlugin() {
    >     		return TestpackagePlugin.getDefault();
    >     	}
    >     }

    > `

    The only change you should need to make to the above example is replacing `TestpackagePlugin` with the name of your plug-in class.

15. Modify the preference page class that was created by the preference page wizard. The code should look something like this:

    > `

    >     package com.ssaglobal.generator.testpackage;

    >     import org.eclipse.ui.plugin.AbstractUIPlugin;

    >     import com.ssaglobal.generator.testpackage.TestpackagePlugin;
    >     import com.ssaglobal.generator.ui.GeneratorPreferencePage;

    >     public class TestpackagePreferencePage extends GeneratorPreferencePage {

    >     	public AbstractUIPlugin getExtensionPlugin() {
    >     		return TestpackagePlugin.getDefault();
    >     	}
    >     }

    > `

    The only change you should need to make to the above example is replacing `TestpackagePlugin` with the name of your plug-in class.

16. Create your templates in the folder identified by the `templateRoot` attribute in step 4 above.