23
23
import org .slf4j .LoggerFactory ;
24
24
import org .slf4j .simple .SimpleLogger ;
25
25
26
+ import pn .app_wish .model .AppCmd ;
27
+ import pn .app_wish .model .CodeBaseCmd ;
26
28
import pn .app_wish .constant .CodeEvent ;
27
29
import pn .app_wish .constant .GUIConstants ;
28
30
import pn .app_wish .constant .StaticAppWishConstants ;
29
- import pn .app_wish .util .AppWishUtil ;
30
31
import pn .cg .app_system .AppSystem ;
31
32
import pn .cg .app_system .code_generation .model .CompilationJob ;
32
33
import pn .cg .datastorage .DataStorage ;
38
39
import java .nio .file .Files ;
39
40
import java .nio .file .Paths ;
40
41
42
+ import java .util .LinkedList ;
41
43
import java .util .List ;
42
44
43
45
44
46
import static java .util .Objects .requireNonNull ;
45
- import static pn .app_wish .constant .GUIConstants .APP_HISTORY_STAGE_TILE ;
46
- import static pn .app_wish .constant .GUIConstants . DEFAULT_FXML_FILE ;
47
+ import static pn .app_wish .constant .GUIConstants .* ;
48
+ import static pn .app_wish .constant .StaticAppWishConstants .* ;
47
49
48
50
49
51
public class AppWish extends Application {
@@ -67,6 +69,8 @@ public class AppWish extends Application {
67
69
public Button btn_StopGeneratedApp ;
68
70
@ FXML
69
71
public ImageView logo ;
72
+ @ FXML
73
+ public Button btn_super_app_creation ;
70
74
71
75
private String javaExecutablePath ;
72
76
private Process executingJavaAppProcess ;
@@ -100,11 +104,13 @@ public void start(Stage primaryStage) throws IOException {
100
104
System .setProperty (SimpleLogger .DEFAULT_LOG_LEVEL_KEY , "DEBUG" );
101
105
Parent root = FXMLLoader .load (requireNonNull (getClass ().getClassLoader ().getResource (DEFAULT_FXML_FILE )));
102
106
mainStage = primaryStage ;
107
+ mainStage .setResizable (false );
103
108
primaryStage .setTitle (GUIConstants .DEFAULT_STAGE_TITLE );
104
109
Scene scene = new Scene (root );
105
110
primaryStage .setScene (scene );
106
111
primaryStage .show ();
107
112
System .out .println ("\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n " );
113
+
108
114
}
109
115
110
116
/**
@@ -149,7 +155,7 @@ private void onAppWish(CodeEvent codeEvent) {
149
155
150
156
waitForCompilationResult ();
151
157
152
- handleCompilationResult ();
158
+ handleCompilationResult (false );
153
159
154
160
});
155
161
@@ -161,21 +167,44 @@ private void onRunJavaApp(ActionEvent ae) {
161
167
btn_StopGeneratedApp .setVisible (true );
162
168
163
169
if (javaExecutablePath != null ) {
164
- System .out .println ("Executing java app on path -> " + javaExecutablePath );
170
+
171
+ if (!output_label .isVisible ()) {
172
+ log .info ("Executing java app on path -> {}" , javaExecutablePath );
173
+ }
165
174
try {
166
- ProcessBuilder pb ;
167
- pb = new ProcessBuilder (StaticAppWishConstants .BASH_PATH , StaticAppWishConstants .C_ARGUMENT , StaticAppWishConstants .JAVA_TEXT + javaExecutablePath );
175
+ ProcessBuilder pb = GetProcessBuilderForRunningGeneratedJavaApplications ();
168
176
executingJavaAppProcess = pb .inheritIO ().start ();
169
177
} catch (IOException e ) {
170
178
throw new RuntimeException (e );
171
179
}
172
180
}
173
181
}
174
182
183
+ private final ProcessBuilder GetProcessBuilderForRunningGeneratedJavaApplications () {
184
+ ProcessBuilder pb = null ;
185
+
186
+ final String classPath = javaExecutablePath .replace (MAIN_DOT_JAVA , NOTHING_STRING );
187
+
188
+ if (output_label .isVisible ()) {
189
+ // Super App Creation
190
+
191
+ // Security
192
+ if (classPath .concat (MAIN_DOT_JAVA ).equals (javaExecutablePath )) {
193
+ log .info ("Executing java app on path -> {}" , javaExecutablePath .replace (MAIN_DOT_JAVA , NOTHING_STRING ) + MAIN_TEXT );
194
+ pb = new ProcessBuilder (new CodeBaseCmd (classPath ).GetCMDForRunningCodeBaseApplication ());
195
+ }
196
+ } else {
197
+ // New App
198
+ // Continue an App
199
+ pb = new ProcessBuilder (new AppCmd (javaExecutablePath ).GetCMDForRunningCodeBaseApplication ());
200
+ }
201
+ return pb ;
202
+ }
203
+
175
204
@ FXML
176
205
private void onViewAppHistory (ActionEvent ae ) throws IOException {
177
206
178
- if (!isCodeGenerationOnGoing ) {
207
+ if (!isCodeGenerationOnGoing ) {
179
208
AnchorPane pane = FXMLLoader .load (
180
209
requireNonNull (getClass ().getClassLoader ().getResource (GUIConstants .APP_HISTORY_FXML_FILE )));
181
210
Scene scene = new Scene (pane );
@@ -220,21 +249,22 @@ private void startGuiThread(CodeEvent codeEvent) {
220
249
/**
221
250
* The method for the event CREATE_APPLICATION
222
251
*/
223
- private void codeEventCreateApplication (){
224
- if (!btn_StopGeneratedApp .isVisible ()){
225
- setButtonGroupVisibilityForCodeGenerationButtons (false );
226
- output_label .setText ("Generating code..." );
227
- }
252
+ private void codeEventCreateApplication () {
253
+ if (!btn_StopGeneratedApp .isVisible ()) {
254
+ setButtonGroupVisibilityForCodeGenerationButtons (false );
255
+ output_label .setText (GUIConstants . GENERATING_CODE_DEFAULT_TEXT );
256
+ }
228
257
}
258
+
229
259
/**
230
260
* The method for the event CONTINUE_ON_EXISTING_APPLICATION
231
261
*/
232
- private void codeEventContinueAnApplication (){
233
- if (!btn_StopGeneratedApp .isVisible ()) {
262
+ private void codeEventContinueAnApplication () {
263
+ if (!btn_StopGeneratedApp .isVisible ()) {
234
264
setButtonGroupVisibilityForCodeGenerationButtons (false );
235
- output_label .setText ("Generating code...\n Continue with existing application" );
236
- }
265
+ output_label .setText (GUIConstants .CONTINUING_CODE_TEXT );
237
266
}
267
+ }
238
268
239
269
/**
240
270
* Create application button event
@@ -260,7 +290,6 @@ private void continueOnExistingApplication(ActionEvent ae) {
260
290
}
261
291
}
262
292
263
-
264
293
/**
265
294
* Starts the AI Code-Generation if the text input field is not null
266
295
*/
@@ -290,20 +319,27 @@ private void waitForCompilationResult() {
290
319
}
291
320
}
292
321
322
+
293
323
/**
294
324
* If a compilation result exist , check if the singleton in code-generator-ollama contains a path for an executable Java file
295
325
* If the above is true , activate the "run application" button and remove the "generating code..." text
296
326
*/
297
- private void handleCompilationResult () {
327
+ private void handleCompilationResult (boolean isSuperGeneration ) {
298
328
if (DataStorage .getInstance ().getCompilationJob ().isResult ()) {
299
329
javaExecutablePath = DataStorage .getInstance ().getJavaExecutionPath ();
300
330
// Draw success or error texts, and show run app button
301
331
Platform .runLater (() -> {
302
- if (DataStorage .getInstance ().getJavaExecutionPath () != null ) {
303
- output_label .setVisible (false );
332
+ if (DataStorage .getInstance ().getJavaExecutionPath () != null || isSuperGeneration ) {
333
+ if (!isSuperGeneration ) {
334
+ output_label .setVisible (false );
335
+ btn_run_application .setVisible (true );
336
+ }
304
337
btn_run_application .setVisible (true );
305
338
setButtonGroupVisibilityForCodeGenerationButtons (true );
306
339
isCodeGenerationOnGoing = false ;
340
+ if (isSuperGeneration ) {
341
+ output_label .setText (SUCCESS_ON_SUPER_APP_CREATION_TEXT );
342
+ }
307
343
} else {
308
344
output_label .setText ("Something went wrong :(" );
309
345
}
@@ -318,6 +354,7 @@ private void handleCompilationResult() {
318
354
private void setButtonGroupVisibilityForCodeGenerationButtons (boolean isVisible ) {
319
355
btn_create_application .setVisible (isVisible );
320
356
btn_continue_on_application .setVisible (isVisible );
357
+ btn_super_app_creation .setVisible (isVisible );
321
358
}
322
359
323
360
/**
@@ -354,4 +391,42 @@ private List<String> readTextByLinesFromFile(File file) {
354
391
return null ;
355
392
}
356
393
}
394
+
395
+ @ FXML
396
+ public void OnSuperAppCreationButton (ActionEvent ae ) {
397
+
398
+ isCodeGenerationOnGoing = true ;
399
+ DataStorage .getInstance ().setCompilationJob (new CompilationJob (GUIConstants .DEFAULT_STAGE_TITLE ));
400
+ ThreadPoolMaster .getInstance ().getExecutor ().execute (() -> {
401
+ StartGuiThreadForSuperAppCreation ();
402
+
403
+ AppSystem .StartSuperAppGeneration (tf_input .getText (), true , false , new LinkedList <>(), false , null );
404
+
405
+ waitUntilAllClassesOfTheSuperAppCreationHasBeenImplemented ();
406
+ handleCompilationResult (true );
407
+ });
408
+ }
409
+
410
+ /**
411
+ * Starts a thread that handles GUI Updates
412
+ */
413
+ private void StartGuiThreadForSuperAppCreation () {
414
+
415
+ Platform .runLater (() -> {
416
+ setButtonGroupVisibilityForCodeGenerationButtons (false );
417
+ setButtonGroupVisibilityToFalseForStartAndStopApplicationsButtons ();
418
+ output_label .setText (GENERATING_CODE_BASE_TEXT );
419
+ output_label .setVisible (true );
420
+ });
421
+ }
422
+
423
+ /**
424
+ * Wait until the singleton in code-generator-ollama has created the entire super app
425
+ */
426
+ private void waitUntilAllClassesOfTheSuperAppCreationHasBeenImplemented () {
427
+
428
+ while (!DataStorage .getInstance ().isSuperAppCreated ()) {
429
+ }
430
+ }
431
+
357
432
}
0 commit comments