Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* generated by Xtext 2.27.0
*/
package org.etsi.mts.tdl.ui.wizard
import org.eclipse.core.runtime.Status
import org.eclipse.jdt.core.JavaCore
import org.eclipse.xtext.ui.XtextProjectHelper
import org.eclipse.xtext.ui.util.PluginProjectFactory
import org.eclipse.xtext.ui.wizard.template.IProjectGenerator
import org.eclipse.xtext.ui.wizard.template.IProjectTemplateProvider
import org.eclipse.xtext.ui.wizard.template.ProjectTemplate
import static org.eclipse.core.runtime.IStatus.*
import org.eclipse.xtext.ui.PluginImageHelper
import com.google.inject.Inject
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
/**
* Create a list with all project templates to be shown in the template new project wizard.
*
* Each template is able to generate one or more projects. Each project can be configured such that any number of files are included.
*/
class TDLtxProjectTemplateProvider implements IProjectTemplateProvider {
@Inject
TDLtxProject project
@Inject
TDLtxProjectWithOpenAPI projectWithOpenAPI
override getProjectTemplates() {
//#[new TDLtxProject]
#[project, projectWithOpenAPI]
}
}
//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 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)
@Inject
PluginImageHelper pluginImageHelper
override protected updateVariables() {
name.enabled = advanced.value
path.enabled = advanced.value
if (!advanced.value) {
name.value = "Example"
path.value = "tdltx.example"
}
}
override protected validate() {
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»/Wizardry.tdltx''', TemplateContent.Example)
addFile('''src/«path»/Model.tdltx''', '''
/*
* This is an example package
*/
Package «name» {
Import all from Wizardry
Type float
}
''')
])
}
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>
<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>")
final class TDLtxProjectWithOpenAPI {
//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 dataDefinitionsPath = text("Data DefinitionsPath:", testFile, "The data definitions path to import from", advancedGroup)
@Inject
PluginImageHelper pluginImageHelper
override protected updateVariables() {
name.enabled = advanced.value
path.enabled = advanced.value
dataDefinitionsPath.enabled = advanced.value
if (!advanced.value) {
name.value = "Example"
path.value = "tdltx.example"
dataDefinitionsPath.value = testFile
}
}
override protected validate() {
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»/Wizardry.tdltx''', TemplateContent.Example)
addFile('''src/«path»/Model.tdltx''', '''
/*
* This is an example package
*/
Package «name» {
Import all from generated_from_ExampleAPI_yaml
Import all from Wizardry
}
''')
//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")
])
}
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»''')
}
}