Commit ba1f07d7 authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ updated file and project template providers

parent c8caea35
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ public class Messages extends NLS {
	public static String TDLtxProjectWithOpenAPI_Description;
	public static String TDLtxFileFromOpenAPI_Label;
	public static String TDLtxFileFromOpenAPI_Description;
	public static String TDLtxLibrary_Label;
	public static String TDLtxLibrary_Description;
	
	static {
	// initialize resource bundle
+30 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import org.eclipse.xtext.ui.wizard.template.IFileTemplateProvider
import org.etsi.mts.tdl.openapi2tdl.next.ConverterNext
import org.eclipse.core.runtime.preferences.InstanceScope
import org.eclipse.ui.preferences.ScopedPreferenceStore
import org.etsi.mts.tdl.ui.wizard.TemplateHelper.Libraries

/**
 * Create a list with all file templates to be shown in the template new file wizard.
@@ -18,14 +19,18 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore
 */
class TDLtxFileTemplateProvider implements IFileTemplateProvider {
	override getFileTemplates() {
		#[new TDLtxFile, new TDLtxFileFromOpenAPI]
		#[
			new TDLtxFile, 
			new TDLtxFileFromOpenAPI,
			new TDLtxLibrary
		]
	}
}

@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")
	val packageName = text("Package Name:", "EmptyPackage", "The name of the package")

    //TODO: reuse?
	override generateFiles(IFileGenerator generator) {
@@ -41,6 +46,29 @@ final class TDLtxFile {
	}
}

@FileTemplate(label="TDLtx Library", icon="file_template.png", description="Add library for TDL.")
final class TDLtxLibrary {
	//TODO: make it more sensible
	//TODO: name should not be asked for...
	val name = text("Name:", "Standard")
	val packageName = combo("Library:", #["Standard", "HTTP"], "The library to be added.")
	var validated = false

	override protected updateVariables() {
		validated = true
		super.updateVariables()
	}

    //TODO: reuse?
	override generateFiles(IFileGenerator generator) {
		//TODO: use enum values?
		if (validated) {
			generator.generate('''«folder»/«name».tdltx''', TemplateHelper.getLibrary(packageName.value))
		}		
	}
}


@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?
+38 −14
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ import java.util.List
import org.eclipse.swt.graphics.Image
import org.etsi.mts.tdl.tx.ui.internal.TxActivator
import org.etsi.mts.tdl.openapi2tdl.next.ConverterNext
import org.eclipse.ui.preferences.ScopedPreferenceStore
import org.eclipse.core.runtime.preferences.InstanceScope
import org.etsi.mts.tdl.ui.wizard.TemplateHelper.Libraries

/**
 * Create a list with all project templates to be shown in the template new project wizard.
@@ -110,13 +113,20 @@ final class TDLtxProject {
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 TDLtxProjectWithOpenAPI {
    //TODO: more modern way?
    //TODO: differentiate for project vs file wizard
	val s = new ScopedPreferenceStore(new InstanceScope(), "org.etsi.mts.tdl.tx.ui.template.data.openapi")
    val lastUsed = "LAST_USED"
    //TODO: file prompt?
    //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 advanced = check("Advanced:", true)
    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 dataDefinitionsPath = text("Data DefinitionsPath:", testFile, "The data definitions path to import from", advancedGroup)
    val name = text("Main Package Name:", "Main", "The name of the main package")
//    val name = combo("Package Name:", #["Example", "Sample", "Tutorial", "Pack"], "The name of the package", advancedGroup)
    val path = text("Path:", "tdl", "The package path to place the files in", advancedGroup)
    val dataDefinitionsPath = text("Data DefinitionsPath:", s.getString(lastUsed), "The data definitions path to import from", advancedGroup)
    val sourceMapping = text("Source mapping tag:", "SOURCE_MAPPING", "The source mapping tag to be used for the data mappings", advancedGroup)
    val targetMapping = text("Target mapping tag:", "TARGET_MAPPING", "The target mapping tag to be used for the data mappings", advancedGroup)

    @Inject
    PluginImageHelper pluginImageHelper
@@ -125,10 +135,15 @@ final class TDLtxProjectWithOpenAPI {
        name.enabled = advanced.value
        path.enabled = advanced.value
        dataDefinitionsPath.enabled = advanced.value
        sourceMapping.enabled = advanced.value
        targetMapping.enabled = advanced.value
        
        if (!advanced.value) {
            name.value = "Example"
            path.value = "tdltx.example"
            dataDefinitionsPath.value = testFile
            name.value = "Main"
            path.value = "tdl"
            dataDefinitionsPath.value = s.getString(lastUsed)
	        sourceMapping.value = "SOURCE_MAPPING"
	        targetMapping.value = "TARGET_MAPPING"
        }
    }

@@ -149,21 +164,30 @@ final class TDLtxProjectWithOpenAPI {
            projectNatures += #[XtextProjectHelper.NATURE_ID]
            builderIds += #[XtextProjectHelper.BUILDER_ID]
            folders += "src"
            addRequiredBundles(List.of("org.etsi.mts.tdl.tx.ui"))
            
//            addFile('''src/«path»/Standard.tdltx''', TemplateContent.Standard)
            //TODO: move libraries to a separate bundle
            addFile('''src/«path»/Standard.tdltx''', TemplateHelper.getLibrary("Standard"))
            //TODO: remove hardcoded import
            addFile('''src/«path»/Wizardry.tdltx''', TemplateContent.Example)
            //TODO: make target package name configurable? i.e. based on name
            addFile('''src/«path»/imported.tdltx''', 
            	ConverterNext.processToString(dataDefinitionsPath.value, 
					"src/"+path.value+"/imported.tdltx", 
					sourceMapping.value, 
					targetMapping.value
			))
            addFile('''src/«path»/Model.tdltx''', '''
                /*
                 * This is an example package
                 */
                Package «name» {
                    Import all from Standard
                    Import all from generated_from_ExampleAPI_yaml
                    Import all from Wizardry
                    
                    Type simple
                }
            ''')
             //TODO: add generated and import
             //TODO: deal with missing workspace info
             ConverterNext.process(dataDefinitionsPath.value, "/Users/philip-iii/Dev/workspaces/runtime/2021-06-M3-clean/"+projectInfo.projectName+"/src/imported.tdltx")
             
        ])
        
    }
+10 −5
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2019 itemis AG (http://www.itemis.eu) and others.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
@@ -8,9 +7,14 @@
 *******************************************************************************/
package org.etsi.mts.tdl.ui.wizard

/**
 * @author miklossy - Initial contribution and API
 */
import java.nio.file.Files
import java.nio.file.Path
import org.eclipse.core.runtime.Platform
import org.osgi.framework.Bundle
import java.net.URL
import java.io.File
import java.net.URI

class TemplateContent {
	//TODO: can we access the shared templates instead?
	public static val Example = '''
@@ -41,4 +45,5 @@ class TemplateContent {
        }
    }
    '''

}
+2 −0
Original line number Diff line number Diff line
@@ -8,3 +8,5 @@ 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.
TDLtxLibrary_Label=TDLtx Library
TDLtxLibrary_Description=Add library for TDL.