Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / imports / ExecuteImportScriptMacro.groovy @ 499

History | View | Annotate | Download (1.1 kB)

1
package org.txm.macro.imports
2

    
3
import org.kohsuke.args4j.*
4
import groovy.transform.Field
5
import org.txm.rcp.swt.widget.parameters.*
6
import org.txm.rcp.commands.*
7

    
8
@Field @Option(name="scriptFile", usage="an example file", widget="File", required=true, def="xxxLoader.groovy")
9
File scriptFile
10

    
11
@Field @Option(name="paramFile", usage="an example file", widget="File", required=true, def="import.xml")
12
File paramFile
13

    
14
if (!ParametersDialog.open(this)) return;
15

    
16
File script = scriptFile // if not done, using scriptFile raise a Cast exception to 'groovy.lang.Reference'
17
File param = paramFile
18
if (!script.getName().endsWith(".groovy")) {
19
        println "Error: the selected file is not a Groovy script: $script"
20
        return
21
}
22
if (!param.getName().endsWith(".xml")) {
23
        println "Error: the selected file is not a XML import parameter file: $param"
24
        return
25
}
26

    
27
println "Runnin import with $scriptFile and $paramFile"
28

    
29
monitor.syncExec(new Runnable() {
30
        public void run() {
31
                try {
32
                        String path = script.getAbsolutePath()
33
                        ExecuteImportScript.executeScript(script.getAbsolutePath(), param);
34
                } catch (Exception e) {
35
                        e.printStackTrace();
36
                }
37
        }
38
});