Commits (2)
......@@ -22,6 +22,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.epsilon.profiling,
org.eclipse.epsilon.eol.tools,
com.google.inject,
org.eclipse.xtext.ui
org.eclipse.xtext.ui,
org.etsi.mts.tdl.model
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11
......@@ -13,6 +13,11 @@
id="org.etsi.mts.tdl.constraints.ui.commands.validateCommand"
name="Validate TDL model">
</command>
<command
categoryId="org.etsi.mts.tdl.constraints.ui.commands.category"
id="org.etsi.mts.tdl.constraints.ui.commands.toggleValidationCommand"
name="Automatically Validate TDL model">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
......@@ -21,6 +26,13 @@
class="org.etsi.mts.tdl.constraints.ui.handlers.ValidationHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
commandId="org.etsi.mts.tdl.constraints.ui.commands.toggleValidationCommand"
class="org.etsi.mts.tdl.constraints.ui.handlers.ToggleValidationHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
......@@ -58,6 +70,36 @@
</command>
</toolbar>
</menuContribution>
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="TDL"
mnemonic="T"
id="org.etsi.mts.tdl.tools.menus.TDLMenu">
<command
commandId="org.etsi.mts.tdl.constraints.ui.commands.toggleValidationCommand"
icon="icons/ValidateIcon.png"
id="org.etsi.mts.tdl.constraints.ui.menus.toggleValidation"
mnemonic="V"
style="toggle">
</command>
</menu>
</menuContribution>
<menuContribution
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
<toolbar
id="org.etsi.mts.tdl.constraints.ui.toolbars.toggleValidation">
<command
commandId="org.etsi.mts.tdl.constraints.ui.commands.toggleValidationCommand"
icon="icons/ValidateIcon.png"
id="org.etsi.mts.tdl.constraints.ui.toolbars.toggleValidation"
style="toggle"
tooltip="Automatically Validate TDL model">
</command>
</toolbar>
</menuContribution>
</extension>
</plugin>
package org.etsi.mts.tdl.constraints.ui.handlers;
import java.net.URI;
import java.util.Collection;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.util.EObjectValidator;
import org.eclipse.epsilon.evl.emf.validation.CompositeEValidator;
import org.eclipse.epsilon.evl.emf.validation.EvlValidator;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.etsi.mts.tdl.tdlPackage;
public class ToggleValidationHandler extends AbstractHandler {
private static boolean initialised;
private static EvlValidator evlValidator;
//TODO: for some reason seems to hang now..
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ScopedPreferenceStore s = new ScopedPreferenceStore(new InstanceScope(), "org.etsi.mts.tdl.constraints.ui.autoValidation");
boolean enabled = s.getBoolean("enabled");
//TODO: some constraints seems to be providing strange errors
//TODO: maintain state across menu toolbar and others
//TODO: maintain state across launches
if (!enabled) {
try {
init();
registerValidator(tdlPackage.eINSTANCE);
enabled = true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
stop();
enabled = false;
}
s.setValue("enabled", enabled);
return null;
}
public static void stop() {
EPackage ePackage = tdlPackage.eINSTANCE;
EValidator existingValidator = EValidator.Registry.INSTANCE.getEValidator(ePackage);
if (existingValidator instanceof CompositeEValidator) {
//TODO: check for evl validators?
((CompositeEValidator) existingValidator).getDelegates().remove(evlValidator);
Collection<EValidator> delegates = ((CompositeEValidator) existingValidator).getDelegates();
//TODO: make more robust
delegates.removeIf(d -> d instanceof EvlValidator);
} else {
if (existingValidator == null) {
existingValidator = EObjectValidator.INSTANCE;
}
CompositeEValidator newValidator = new CompositeEValidator();
newValidator.getDelegates().add(existingValidator);
newValidator.getDelegates().add(evlValidator);
EValidator.Registry.INSTANCE.put(ePackage, newValidator);
}
}
public static void init() throws Exception {
if (initialised) {
return;
}
//TODO: goes a bit in circles
//TODO: extract into an activator or something? also as command
//TODO: works in principle, occasionally causes hangs and strange errors though...
System.out.println("Init EVL validator..");
// Assuming you have generated the metamodel code
EPackage ePackage = tdlPackage.eINSTANCE;
// Pass a model name if your script uses it
// Pass a valid bundle ID as it used for reporting (if not in a plugin use your project name or similar)
String modelName = "TDL"; //This seems to be important! Otherwise strange hangs occur -> TDL?
String bundleId = "org.etsi.mts.tdl.constraints";
URI evlScriptURI = new URI("platform:/plugin/"+bundleId+"/constraints/tdl-generated-ETSI-ES-203-119-1-V1.5.1-fixed.evl");
//TODO: try out extension point integration
//TODO: try out fixes -> can they be in a separate module?
//TODO: add other constraints for TO/TC
evlValidator = new EvlValidator(
evlScriptURI, modelName , ePackage.getNsURI(), bundleId);
evlValidator.setShowErrorDialog(false);
//TODO: extract to optional on demand / auto validation
//TODO: this brings all the epsilon dependencies here as well
//-> effectively requires constraints to be installed.. shall be plugged in ideally..
//-> check again extension point integration..
// registerValidator(ePackage);
initialised = true;
}
//TODO: reorganise and reuse (from TDLtxValidator, shall migrate local Validator as well)
private static void registerValidator(EPackage ePackage) {
EValidator existingValidator = EValidator.Registry.INSTANCE.getEValidator(ePackage);
if (existingValidator instanceof CompositeEValidator) {
((CompositeEValidator) existingValidator).getDelegates().add(evlValidator);
} else {
if (existingValidator == null) {
existingValidator = EObjectValidator.INSTANCE;
}
CompositeEValidator newValidator = new CompositeEValidator();
newValidator.getDelegates().add(existingValidator);
newValidator.getDelegates().add(evlValidator);
EValidator.Registry.INSTANCE.put(ePackage, newValidator);
}
}
}
......@@ -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
......
......@@ -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>
......
......@@ -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>