Commit 58f89eaf authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ refined project templates

parent acfa9489
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ public class Messages extends NLS {
	public static String TDLtxFileFromOpenAPI_Description;
	public static String TDLtxLibrary_Label;
	public static String TDLtxLibrary_Description;
	public static String TDLtxProjectBase_Label;
	public static String TDLtxProjectBase_Description;
	
	static {
	// initialize resource bundle
+85 −9
Original line number Diff line number Diff line
@@ -30,28 +30,36 @@ import org.etsi.mts.tdl.ui.wizard.TemplateHelper.Libraries
 */
class TDLtxProjectTemplateProvider implements IProjectTemplateProvider {
    @Inject
    TDLtxProject project
    TDLtxProject iTDLtxProject

    @Inject
    TDLtxProjectWithOpenAPI projectWithOpenAPI
    TDLtxProjectBase iTDLtxProjectBase

    @Inject
    TDLtxProjectWithOpenAPI iTDLtxProjectWithOpenAPI
    
	override getProjectTemplates() {
		//#[new TDLtxProject]
		#[project, projectWithOpenAPI]
		#[
//			new TDLtxProject, 
//			new TDLtxProjectBase, 
//			new TDLtxProjectWithOpenAPI
			iTDLtxProject, 
			iTDLtxProjectBase, 
			iTDLtxProjectWithOpenAPI
		]
	}
}

//TODO: customise
@ProjectTemplate(label="TDLtx", icon="project_template.png", description="<p><b>TDLtx</b></p>
@ProjectTemplate(label="TDLtx Base", icon="project_template.png", description="<p><b>TDLtx</b></p>
<p>This is a parameterized project for TDLtx. You can set a parameter to modify the content in the generated file
and a parameter to set the path the file is created in.</p><p><img href=\"project_template.png\"/></p>")
final class TDLtxProject {
final class TDLtxProjectBase {
    //TODO: remove after testing
    val testFile = "/Users/philip-iii/Dev/git/etsi-labs/eg-203647-restful-api-guide/OpenAPI/ExampleAPI.yaml"
	val advanced = check("Advanced:", false)
	val advancedGroup = group("Properties")
	val name = combo("Package Name:", #["Example", "Sample", "Tutorial", "Pack"], "The name of the package", advancedGroup)
	val path = text("Path:", "tdltx_example", "The package path to place the files in", advancedGroup)
	val path = text("Path:", "tdl", "The package path to place the files in", advancedGroup)

    @Inject
    PluginImageHelper pluginImageHelper
@@ -61,7 +69,7 @@ final class TDLtxProject {
		path.enabled = advanced.value
		if (!advanced.value) {
			name.value = "Example"
			path.value = "tdltx.example"
			path.value = "tdl"
		}
	}

@@ -106,6 +114,74 @@ final class TDLtxProject {
	
}

//TODO: customise
@ProjectTemplate(label="TDLtx", icon="project_template.png", description="<p><b>TDLtx</b></p>
<p>This is a parameterized project for TDLtx. You can set a parameter to modify the content in the generated file
and a parameter to set the path the file is created in.</p><p><img href=\"project_template.png\"/></p>")
final class TDLtxProject {
    //TODO: remove after testing
	val advanced = check("Advanced:", false)
	val advancedGroup = group("Properties")
//	val name = combo("Package Name:", #["Example", "Sample", "Tutorial", "Pack"], "The name of the package", advancedGroup)
    val name = text("Main Package Name:", "Main", "The name of the main package")
	val path = text("Path:", "tdl", "The package path to place the files in", advancedGroup)
	//TODO: add other options

    @Inject
    PluginImageHelper pluginImageHelper

	override protected updateVariables() {
		name.enabled = advanced.value
		path.enabled = advanced.value
		if (!advanced.value) {
			name.value = "Main"
			path.value = "tdl"
		}
	}

	override protected validate() {
		//TODO: validate name as well
		if (path.value.matches('[a-z][a-z0-9_.]*(/[a-z][a-z0-9_.]*)*'))
			null
		else
			new Status(ERROR, "Wizard", "'" + path + "' is not a valid package name")
			//TODO: validate data definitions as well
	}

	override generateProjects(IProjectGenerator generator) {
		generator.generate(new PluginProjectFactory => [
			projectName = projectInfo.projectName
			location = projectInfo.locationPath
			//projectNatures += #[JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature", XtextProjectHelper.NATURE_ID]
			//builderIds += #[JavaCore.BUILDER_ID, XtextProjectHelper.BUILDER_ID]
			projectNatures += #[XtextProjectHelper.NATURE_ID]
			builderIds += #[XtextProjectHelper.BUILDER_ID]
			folders += "src"
			//TODO: remove hardcoded import
            addFile('''src/«path»/Standard.tdltx''', TemplateHelper.getLibrary("Standard"))
			addFile('''src/«path»/«name».tdltx''', '''
				/*
				 * This is an example package
				 */
				Package «name» {
				    Import all from Standard
				    Type float
				    //define elements here
				}
			''')
		])
		
	}
	
    protected override List<Pair<String, Image>> getImages() {
        #["project_template.png".image]
    }
    private def image(String id) {
        id -> pluginImageHelper.getImage('''platform:/plugin/«TxActivator.PLUGIN_ID»/«id»''')
    }
	
}


//TODO: customise further, reuse?
@ProjectTemplate(label="TDLtx with OpenAPI", icon="project_template.png", description="<p><b>TDLtx with OpenAPI</b></p>
+2 −0
Original line number Diff line number Diff line
@@ -10,3 +10,5 @@ TDLtxFileFromOpenAPI_Label=Data definitions import from OpenAPI
TDLtxFileFromOpenAPI_Description=Create a new package for TDLtx from OpenAPI data definitions.
TDLtxLibrary_Label=TDLtx Library
TDLtxLibrary_Description=Add library for TDL.
TDLtxProjectBase_Label=TDLtx Base
TDLtxProjectBase_Description=<p><b>TDLtx</b></p> <p>This is a parameterized project for TDLtx. You can set a parameter to modify the content in the generated file and a parameter to set the path the file is created in.</p><p><img href="project_template.png"/></p>