77
88package de .fraunhofer .iem .swan .assist .actions ;
99
10+ import com .intellij .ide .util .PropertiesComponent ;
1011import com .intellij .openapi .actionSystem .AnAction ;
1112import com .intellij .openapi .actionSystem .AnActionEvent ;
1213import com .intellij .openapi .actionSystem .CommonDataKeys ;
14+ import com .intellij .openapi .progress .PerformInBackgroundOption ;
15+ import com .intellij .openapi .progress .ProgressManager ;
1316import com .intellij .openapi .project .Project ;
14- import com .intellij .openapi .ui .DialogWrapper ;
15- import com .intellij .util .messages .MessageBus ;
17+ import de .fraunhofer .iem .swan .assist .analysis .SwanBackgroundTask ;
1618import de .fraunhofer .iem .swan .assist .comm .SwanNotifier ;
1719import de .fraunhofer .iem .swan .assist .data .JSONFileLoader ;
18- import de .fraunhofer .iem .swan .assist .data .TrainingFileManager ;
19- import de .fraunhofer .iem .swan .assist .ui .dialog .RunAnalysisDialog ;
2020import de .fraunhofer .iem .swan .assist .util .Constants ;
2121import de .fraunhofer .iem .swan .data .Method ;
2222
2323import java .io .File ;
2424import java .io .IOException ;
2525import java .io .InputStream ;
26- import java .util .HashMap ;
2726import java .util .HashSet ;
27+ import java .util .Objects ;
2828import java .util .Properties ;
2929import java .util .Set ;
3030
3131/**
32- * Action opens dialog for user to set parameters for running SWAN . After which thread is created to run SWAN.
32+ * Action runs SWAN using the configuration provided in the SettingsDialog . After which thread is created to run SWAN.
3333 */
34- public class RunSwanAnalysisAction extends AnAction {
34+ public class RunSwanAction extends AnAction {
3535
3636 protected Set <Method > methods = new HashSet <Method >();
3737
@@ -44,7 +44,6 @@ public class RunSwanAnalysisAction extends AnAction {
4444 public void actionPerformed (AnActionEvent anActionEvent ) {
4545
4646 final Project project = anActionEvent .getRequiredData (CommonDataKeys .PROJECT );
47- MessageBus messageBus = project .getMessageBus ();
4847
4948 Properties config = new Properties ();
5049 InputStream input = null ;
@@ -64,30 +63,27 @@ public void actionPerformed(AnActionEvent anActionEvent) {
6463 }
6564 }
6665
67- //Launch Dialog
68- RunAnalysisDialog dialog = new RunAnalysisDialog ( project , true );
69- dialog . show ();
70-
71- if ( dialog . getExitCode () == DialogWrapper . OK_EXIT_CODE ) {
72-
73- HashMap < String , String > swanParameters = dialog . getParameters ();
66+ if (! PropertiesComponent . getInstance ( project ). isTrueValue ( Constants . SWAN_SETTINGS )) {
67+ anActionEvent . getActionManager (). getAction ( "SWAN_Assist.SettingsAction" ). actionPerformed ( anActionEvent );
68+ //TODO Run SWAN if the tool has been configured
69+ } else {
70+ runSwan ( project );
71+ }
72+ }
7473
75- if (!swanParameters .get (Constants .CONFIGURATION_FILE ).contentEquals (config .getProperty ("swan_default_param_value" ))){
76- String outputPath = swanParameters .get (Constants .OUTPUT_DIRECTORY ) + File .separator + config .getProperty ("input_json_suffix" );
77- //TrainingFileManager trainingFileManager = new TrainingFileManager(project);
74+ public void runSwan (Project project ) {
7875
79- //if (trainingFileManager.mergeExport(JSONFileLoader.getAllMethods(), outputPath))
80- // swanParameters.put(Constants.CONFIGURATION_FILE, outputPath);
81- }
76+ File outputFolder = new File (Objects .requireNonNull (PropertiesComponent .getInstance (project ).getValue (Constants .OUTPUT_DIRECTORY )));
8277
83- RunSwanAnalysisImpl processBuilder = new RunSwanAnalysisImpl ( project , dialog . getParameters ());
84- processBuilder . run ();
78+ if (! outputFolder . exists ())
79+ outputFolder . mkdir ();
8580
86- SwanNotifier publisher = messageBus .syncPublisher (SwanNotifier .START_SWAN_PROCESS_TOPIC );
87- publisher .launchSwan (null );
88- }
81+ ProgressManager .getInstance ().run (new SwanBackgroundTask (project , "Detecting SRMs" , true ,
82+ PerformInBackgroundOption .ALWAYS_BACKGROUND ));
8983
90- }
84+ SwanNotifier publisher = project .getMessageBus ().syncPublisher (SwanNotifier .START_SWAN_PROCESS_TOPIC );
85+ publisher .launchSwan (null );
86+ }
9187
9288 /**
9389 * Controls whether the action is enabled or disabled
0 commit comments