88import com .intellij .util .messages .MessageBus ;
99import de .fraunhofer .iem .swan .assist .comm .SwanNotifier ;
1010import de .fraunhofer .iem .swan .assist .data .JSONFileLoader ;
11+ import de .fraunhofer .iem .swan .assist .data .JSONFileParser ;
1112import de .fraunhofer .iem .swan .assist .data .JSONWriter ;
13+ import de .fraunhofer .iem .swan .assist .data .MethodWrapper ;
1214import de .fraunhofer .iem .swan .assist .ui .dialog .SwanLauncherDialog ;
15+ import de .fraunhofer .iem .swan .assist .util .Constants ;
1316
17+ import java .io .File ;
18+ import java .io .FileInputStream ;
1419import java .io .IOException ;
20+ import java .io .InputStream ;
21+ import java .util .ArrayList ;
22+ import java .util .HashMap ;
23+ import java .util .Objects ;
24+ import java .util .Properties ;
1525
1626/**
1727 * Action to start load dialog for configuring SWAN before running.
@@ -28,20 +38,53 @@ public void actionPerformed(AnActionEvent anActionEvent) {
2838 final Project project = anActionEvent .getRequiredData (CommonDataKeys .PROJECT );
2939 MessageBus messageBus = project .getMessageBus ();
3040
31- //Export changes to configuration files
32- JSONWriter exportFile = new JSONWriter () ;
41+ Properties config = new Properties ();
42+ InputStream input = null ;
3343
3444 try {
35- exportFile .writeToJsonFile (JSONFileLoader .getMethods (), JSONFileLoader .getConfigurationFile (true ));
45+ input = new FileInputStream (getClass ().getClassLoader ().getResource ("" ).getPath ()+"config.properties" );
46+ config .load (input );
3647 } catch (IOException e ) {
3748 e .printStackTrace ();
49+ } finally {
50+ if (input != null ) {
51+ try {
52+ input .close ();
53+ } catch (IOException e ) {
54+ e .printStackTrace ();
55+ }
56+ }
3857 }
3958
4059 //Launch Dialog
4160 SwanLauncherDialog dialog = new SwanLauncherDialog (project , true );
4261 dialog .show ();
4362
44- if (dialog .getExitCode ()==DialogWrapper .OK_EXIT_CODE ) {
63+ if (dialog .getExitCode () == DialogWrapper .OK_EXIT_CODE ) {
64+
65+ HashMap <String , String > swanParameters = dialog .getParameters ();
66+
67+ //Merge current list with training methods
68+ HashMap <String , MethodWrapper > methods = JSONFileLoader .getAllMethods ();
69+
70+ //Load training methods
71+ String trainingFile = Objects .requireNonNull (getClass ().getClassLoader ().getResource ("" )).getPath () + config .getProperty ("train_config_file" );
72+ JSONFileParser fileParser = new JSONFileParser (trainingFile );
73+ HashMap <String , MethodWrapper > trainingMethods = fileParser .parseJSONFileMap ();
74+
75+ HashMap <String , MethodWrapper > mergedMethods = new HashMap <>(methods );
76+ mergedMethods .putAll (trainingMethods );
77+
78+ //Export changes to configuration files
79+ JSONWriter exportFile = new JSONWriter ();
80+ String newConfigFile = swanParameters .get (Constants .SWAN_OUTPUT_DIR ) + File .separator + config .getProperty ("input_json_suffix" );
81+ try {
82+ exportFile .writeToJsonFile (new ArrayList <>(mergedMethods .values ()), newConfigFile );
83+ } catch (IOException e ) {
84+ e .printStackTrace ();
85+ }
86+
87+ swanParameters .put (Constants .SWAN_CONFIG_FILE , newConfigFile );
4588
4689 SwanProcessBuilder processBuilder = new SwanProcessBuilder (project , dialog .getParameters ());
4790 processBuilder .start ();
0 commit comments