Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to validate file names in generated file FileTemplateProvider(Checking whether a file name matches a regular expression, but validate method seems to be ignored)
How to validate file names in generated file FileTemplateProvider [message #1802332] Wed, 06 February 2019 15:08 Go to next message
Martin Moser is currently offline Martin MoserFriend
Messages: 7
Registered: January 2019
Junior Member
Hi all,

I have created a File Wizard using xText 2.14.
In my mwe2 file I have set:
fileWizard = {
generate = true
}

Using that generated file template I can generate demo files using the generateFiles method.
Now I want to check whether the given file name in the wizard matches a regular expression.

I thought I could override the validate() method, buit seems, that this method isn't called at all.

My FileTemplateProvider looks like this:

@FileTemplate(label="My DSL file", icon="file_template.png", description="desc....")
....
final class MyDslFile {

//generation is called and it works
override generateFiles(IFileGenerator generator) {
generator.generate('''«folder»/«name».mydsl''', '''
//dummyfile
''')
}

override validate() { //never called??
println("validate");
return new Status(IStatus.ERROR, "", 1, "KO", null);
}

override updateVariables() { //also never called??
println("updateVariables");
}
}


So, what am I doing wrong?


Thanks in advance!

Best regards,
Martin
Re: How to validate file names in generated file FileTemplateProvider [message #1802370 is a reply to message #1802332] Thu, 07 February 2019 13:03 Go to previous messageGo to next message
Arne Deutsch is currently offline Arne DeutschFriend
Messages: 12
Registered: July 2009
Junior Member
Hi Martin,

folder and file name are somewhat special in that they are not variables and hence the validation method are not called for them (only for other variables). There was a discussion in the comments about the (related) new project wizard regarding name and folder. Please have a look in the comments at https://blogs.itemis.com/en/new-file-wizard-easy-to-generate-with-xtext-2.14 . I think if you need to adapt the validaiton logic for these fields you probably have to implement your own NewFileWizardPrimaryPage (https://github.com/eclipse/xtext-eclipse/blob/24ff1fcfb7821f496346864ca6e32a99f931273b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/wizard/template/NewFileWizardPrimaryPage.java).

Hope this will pelp you.

Kind regards,
Arne
Re: How to validate file names in generated file FileTemplateProvider [message #1802388 is a reply to message #1802370] Thu, 07 February 2019 21:39 Go to previous message
Martin Moser is currently offline Martin MoserFriend
Messages: 7
Registered: January 2019
Junior Member
Hi Arne,

thanks for your quick reply.
I will take a look into that NewFileWizardPrimaryPage.

Best regards,
Martin
Previous Topic:Xtext & Xtend 2.17.0.M2 + MWE 2.10.M2
Next Topic:Loading classes in Xbase-based DSL with interpreter
Goto Forum:
  


Current Time: Sat Aug 24 00:01:51 GMT 2019

Powered by FUDForum. Page generated in 0.02277 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top