Commit 7e8f3596 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ refinements to TDLtx file template wizard

parent 901710bf
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ public class Messages extends NLS {
	public static String TDLtxFileExtras_Description;
	public static String TDLtxProjectWithOpenAPI_Label;
	public static String TDLtxProjectWithOpenAPI_Description;
	public static String TDLtxFileFromOpenAPI_Label;
	public static String TDLtxFileFromOpenAPI_Description;
	
	static {
	// initialize resource bundle
+34 −28
Original line number Diff line number Diff line
@@ -8,7 +8,8 @@ import org.eclipse.xtext.ui.wizard.template.FileTemplate
import org.eclipse.xtext.ui.wizard.template.IFileGenerator
import org.eclipse.xtext.ui.wizard.template.IFileTemplateProvider
import org.etsi.mts.tdl.openapi2tdl.next.ConverterNext
import com.google.inject.Inject
import org.eclipse.core.runtime.preferences.InstanceScope
import org.eclipse.ui.preferences.ScopedPreferenceStore

/**
 * Create a list with all file templates to be shown in the template new file wizard.
@@ -16,20 +17,14 @@ import com.google.inject.Inject
 * Each template is able to generate one or more files.
 */
class TDLtxFileTemplateProvider implements IFileTemplateProvider {
    @Inject
    TDLtxFile txFile

    @Inject
    TDLtxFileExtras txFileExtra
    
	override getFileTemplates() {
//		#[new TDLtxFile, new TDLtxFileExtras]
        #[txFile, txFileExtra]
		#[new TDLtxFile, new TDLtxFileFromOpenAPI]
	}
}

@FileTemplate(label="TDLtx", icon="file_template.png", description="Create a new package for TDLtx.")
final class TDLtxFile {
	//TODO: make it more sensible
	val packageName = combo("Package Name:", #["Example", "Sample", "Tutorial", "Pack"], "The name of the package")

    //TODO: reuse?
@@ -42,28 +37,39 @@ final class TDLtxFile {
			    
			}
		''')
//        generator.generate('''«folder»/«packageName».tdltx''', TemplateContent.Example)
	}
}

//TODO: this seems to be inactive...
@FileTemplate(label="TDLtx extra", icon="file_template.png", description="Create a new package for TDLtx with extras.")
final class TDLtxFileExtras {
//    val packageName = combo("Package Name:", #["Example", "Sample", "Tutorial", "Pack"], "The name of the package")
    val testFile = "/Users/philip-iii/Dev/git/etsi-labs/eg-203647-restful-api-guide/OpenAPI/ExampleAPI.yaml"
    val dataDefinitionsPath = text("Data DefinitionsPath:", testFile, "The data definitions path to import from")
@FileTemplate(label="Data definitions import from OpenAPI", icon="file_template.png", description="Create a new package for TDLtx from OpenAPI data definitions.")
final class TDLtxFileFromOpenAPI {
    //TODO: more modern way?
	val s = new ScopedPreferenceStore(new InstanceScope(), "org.etsi.mts.tdl.tx.ui.template.data.openapi")
    val lastUsed = "LAST_USED"
    //TODO: file prompt?
    val dataDefinitionsPath = text("Data Definitions Path:", s.getString(lastUsed), "The data definitions path to import from")
    val sourceMapping = text("Source mapping tag:", "SOURCE_MAPPING", "The source mapping tag to be used for the data mappings")
    val targetMapping = text("Target mapping tag:", "TARGET_MAPPING", "The target mapping tag to be used for the data mappings")
	    
	var validated = false
	
	override protected updateVariables() {
		validated = true
		s.setValue(lastUsed, dataDefinitionsPath.value)
		s.save()
		super.updateVariables()
	}
	
    //TODO: reuse?
    override generateFiles(IFileGenerator generator) {
//        generator.generate('''«folder»/«name».tdltx''', '''
//            /*
//             * This is an example model
//             */
//            Package «name» {
//                
//            }
//        ''')
//        generator.generate('''«folder»/«packageName».tdltx''', TemplateContent.Example)
        //TODO: this gets loaded twice? already when the template is selected? and the file is not opened automatically
        ConverterNext.process(dataDefinitionsPath.value, "/Users/philip-iii/Dev/workspaces/runtime/2021-06-M3-clean/"+folder+"/"+name+".tdltx")
		//NOTE: this is triggered on every key stroke.. -> lock until second screen
		if (validated) {
			generator.generate('''«folder»/«name».tdltx''', 
				ConverterNext.processToString(dataDefinitionsPath.value, 
					folder+"/"+name+".tdltx", 
					sourceMapping.value, 
					targetMapping.value
			))
		}
    }
	
}
+4 −2
Original line number Diff line number Diff line
@@ -2,7 +2,9 @@ TDLtxProject_Label=TDLtx
TDLtxProject_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>
TDLtxFile_Label=TDLtx
TDLtxFile_Description=Create a new package for TDLtx.
TDLtxFileExtras_Label=TDLtx extra
TDLtxFileExtras_Description=Create a new package for TDLtx with extras.
TDLtxFileExtras_Label=Data definitions import from OpenAPI
TDLtxFileExtras_Description=Create a new package for TDLtx from OpenAPI data definitions.
TDLtxProjectWithOpenAPI_Label=TDLtx with OpenAPI
TDLtxProjectWithOpenAPI_Description=<p><b>TDLtx with OpenAPI</b></p> <p>This is a parameterized project for TDLtx with the option to import data definitions from OpenAPI.  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>
TDLtxFileFromOpenAPI_Label=Data definitions import from OpenAPI
TDLtxFileFromOpenAPI_Description=Create a new package for TDLtx from OpenAPI data definitions.