...@@ -8,7 +8,8 @@ import org.eclipse.xtext.ui.wizard.template.FileTemplate ...@@ -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.IFileGenerator
import org.eclipse.xtext.ui.wizard.template.IFileTemplateProvider import org.eclipse.xtext.ui.wizard.template.IFileTemplateProvider
import org.etsi.mts.tdl.openapi2tdl.next.ConverterNext 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. * 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 ...@@ -16,20 +17,14 @@ import com.google.inject.Inject
* Each template is able to generate one or more files. * Each template is able to generate one or more files.
*/ */
class TDLtxFileTemplateProvider implements IFileTemplateProvider { class TDLtxFileTemplateProvider implements IFileTemplateProvider {
@Inject
TDLtxFile txFile
@Inject
TDLtxFileExtras txFileExtra
override getFileTemplates() { override getFileTemplates() {
// #[new TDLtxFile, new TDLtxFileExtras] #[new TDLtxFile, new TDLtxFileFromOpenAPI]
#[txFile, txFileExtra]
} }
} }
@FileTemplate(label="TDLtx", icon="file_template.png", description="Create a new package for TDLtx.") @FileTemplate(label="TDLtx", icon="file_template.png", description="Create a new package for TDLtx.")
final class TDLtxFile { final class TDLtxFile {
//TODO: make it more sensible
val packageName = combo("Package Name:", #["Example", "Sample", "Tutorial", "Pack"], "The name of the package") val packageName = combo("Package Name:", #["Example", "Sample", "Tutorial", "Pack"], "The name of the package")
//TODO: reuse? //TODO: reuse?
...@@ -42,28 +37,39 @@ final class TDLtxFile { ...@@ -42,28 +37,39 @@ final class TDLtxFile {
} }
''') ''')
// generator.generate('''«folder»/«packageName».tdltx''', TemplateContent.Example)
} }
} }
//TODO: this seems to be inactive... @FileTemplate(label="Data definitions import from OpenAPI", icon="file_template.png", description="Create a new package for TDLtx from OpenAPI data definitions.")
@FileTemplate(label="TDLtx extra", icon="file_template.png", description="Create a new package for TDLtx with extras.") final class TDLtxFileFromOpenAPI {
final class TDLtxFileExtras { //TODO: more modern way?
// val packageName = combo("Package Name:", #["Example", "Sample", "Tutorial", "Pack"], "The name of the package") val s = new ScopedPreferenceStore(new InstanceScope(), "org.etsi.mts.tdl.tx.ui.template.data.openapi")
val testFile = "/Users/philip-iii/Dev/git/etsi-labs/eg-203647-restful-api-guide/OpenAPI/ExampleAPI.yaml" val lastUsed = "LAST_USED"
val dataDefinitionsPath = text("Data DefinitionsPath:", testFile, "The data definitions path to import from") //TODO: file prompt?
val dataDefinitionsPath = text("Data Definitions Path:", s.getString(lastUsed), "The data definitions path to import from")
//TODO: reuse? 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()
}
override generateFiles(IFileGenerator generator) { override generateFiles(IFileGenerator generator) {
// generator.generate('''«folder»/«name».tdltx''', ''' //NOTE: this is triggered on every key stroke.. -> lock until second screen
// /* if (validated) {
// * This is an example model generator.generate('''«folder»/«name».tdltx''',
// */ ConverterNext.processToString(dataDefinitionsPath.value,
// Package «name» { folder+"/"+name+".tdltx",
// sourceMapping.value,
// } targetMapping.value
// ''') ))
// 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")
} }
} }
...@@ -2,7 +2,9 @@ TDLtxProject_Label=TDLtx ...@@ -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> 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_Label=TDLtx
TDLtxFile_Description=Create a new package for TDLtx. TDLtxFile_Description=Create a new package for TDLtx.
TDLtxFileExtras_Label=TDLtx extra TDLtxFileExtras_Label=Data definitions import from OpenAPI
TDLtxFileExtras_Description=Create a new package for TDLtx with extras. TDLtxFileExtras_Description=Create a new package for TDLtx from OpenAPI data definitions.
TDLtxProjectWithOpenAPI_Label=TDLtx with OpenAPI 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> 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.
...@@ -45,11 +45,11 @@ Component ${componentType} { ...@@ -45,11 +45,11 @@ Component ${componentType} {
Expected behaviour Expected behaviour
ensure that { ensure that {
when { when {
tester::interface sends "hello" to sut::interface tester::interface sends "hello" {string} to sut::interface
${source:CrossReference('Message.sourceGate')} sends "ey" to sut::interface ${source:CrossReference('Message.sourceGate')} sends "hey" {string} to sut::interface
} }
then { then {
tester::interface receives "hello back" from sut::interface tester::interface receives "hello back" {string} from sut::interface
} }
} }
} }
......
...@@ -3,9 +3,14 @@ ...@@ -3,9 +3,14 @@
*/ */
package org.etsi.mts.tdl; package org.etsi.mts.tdl;
import org.eclipse.xtext.conversion.IValueConverterService;
/** /**
* Use this class to register components to be used at runtime / without the Equinox extension registry. * Use this class to register components to be used at runtime / without the Equinox extension registry.
*/ */
public class TDLtxRuntimeModule extends AbstractTDLtxRuntimeModule { public class TDLtxRuntimeModule extends AbstractTDLtxRuntimeModule {
@Override
public Class<? extends IValueConverterService> bindIValueConverterService() {
return EString2XtextConverter.class;
}
} }
...@@ -63,7 +63,7 @@ public class TDLtxValidator extends AbstractTDLtxValidator { ...@@ -63,7 +63,7 @@ public class TDLtxValidator extends AbstractTDLtxValidator {
//TODO: goes a bit in circles //TODO: goes a bit in circles
//TODO: extract into an activator or something? also as command //TODO: extract into an activator or something? also as command
//TODO: works in principle, occasionally causes hangs and strange errors though... //TODO: works in principle, occasionally causes hangs and strange errors though...
System.out.println("init EVL validator"); System.out.println("Init EVL validator..");
// Assuming you have generated the metamodel code // Assuming you have generated the metamodel code
EPackage ePackage = tdlPackage.eINSTANCE; EPackage ePackage = tdlPackage.eINSTANCE;
...@@ -88,19 +88,20 @@ public class TDLtxValidator extends AbstractTDLtxValidator { ...@@ -88,19 +88,20 @@ public class TDLtxValidator extends AbstractTDLtxValidator {
newValidator.getDelegates().add(existingValidator); newValidator.getDelegates().add(existingValidator);
newValidator.getDelegates().add(evlValidator); newValidator.getDelegates().add(evlValidator);
EValidator.Registry.INSTANCE.put(ePackage, newValidator); EValidator.Registry.INSTANCE.put(ePackage, newValidator);
} }
initialised = true;
} }
@Check // @Check
public void checkConfigurationsStartWithCapital(TestConfiguration c) { // public void checkConfigurationsStartWithCapital(TestConfiguration c) {
if (!Character.isUpperCase(c.getName().charAt(0))) { // if (!Character.isUpperCase(c.getName().charAt(0))) {
warning("Name should start with a capital", // warning("Name should start with a capital",
tdlPackage.Literals.ELEMENT__NAME, // tdlPackage.Literals.ELEMENT__NAME,
INVALID_NAME); // INVALID_NAME);
} // }
} //}
} }