2323import org .slf4j .LoggerFactory ;
2424import org .slf4j .simple .SimpleLogger ;
2525
26+ import pn .app_wish .model .AppCmd ;
27+ import pn .app_wish .model .CodeBaseCmd ;
2628import pn .app_wish .constant .CodeEvent ;
2729import pn .app_wish .constant .GUIConstants ;
2830import pn .app_wish .constant .StaticAppWishConstants ;
29- import pn .app_wish .util .AppWishUtil ;
3031import pn .cg .app_system .AppSystem ;
3132import pn .cg .app_system .code_generation .model .CompilationJob ;
3233import pn .cg .datastorage .DataStorage ;
3839import java .nio .file .Files ;
3940import java .nio .file .Paths ;
4041
42+ import java .util .LinkedList ;
4143import java .util .List ;
4244
4345
4446import 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 .* ;
4749
4850
4951public class AppWish extends Application {
@@ -67,6 +69,8 @@ public class AppWish extends Application {
6769 public Button btn_StopGeneratedApp ;
6870 @ FXML
6971 public ImageView logo ;
72+ @ FXML
73+ public Button btn_super_app_creation ;
7074
7175 private String javaExecutablePath ;
7276 private Process executingJavaAppProcess ;
@@ -100,11 +104,13 @@ public void start(Stage primaryStage) throws IOException {
100104 System .setProperty (SimpleLogger .DEFAULT_LOG_LEVEL_KEY , "DEBUG" );
101105 Parent root = FXMLLoader .load (requireNonNull (getClass ().getClassLoader ().getResource (DEFAULT_FXML_FILE )));
102106 mainStage = primaryStage ;
107+ mainStage .setResizable (false );
103108 primaryStage .setTitle (GUIConstants .DEFAULT_STAGE_TITLE );
104109 Scene scene = new Scene (root );
105110 primaryStage .setScene (scene );
106111 primaryStage .show ();
107112 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+
108114 }
109115
110116 /**
@@ -149,7 +155,7 @@ private void onAppWish(CodeEvent codeEvent) {
149155
150156 waitForCompilationResult ();
151157
152- handleCompilationResult ();
158+ handleCompilationResult (false );
153159
154160 });
155161
@@ -161,21 +167,44 @@ private void onRunJavaApp(ActionEvent ae) {
161167 btn_StopGeneratedApp .setVisible (true );
162168
163169 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+ }
165174 try {
166- ProcessBuilder pb ;
167- pb = new ProcessBuilder (StaticAppWishConstants .BASH_PATH , StaticAppWishConstants .C_ARGUMENT , StaticAppWishConstants .JAVA_TEXT + javaExecutablePath );
175+ ProcessBuilder pb = GetProcessBuilderForRunningGeneratedJavaApplications ();
168176 executingJavaAppProcess = pb .inheritIO ().start ();
169177 } catch (IOException e ) {
170178 throw new RuntimeException (e );
171179 }
172180 }
173181 }
174182
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+
175204 @ FXML
176205 private void onViewAppHistory (ActionEvent ae ) throws IOException {
177206
178- if (!isCodeGenerationOnGoing ) {
207+ if (!isCodeGenerationOnGoing ) {
179208 AnchorPane pane = FXMLLoader .load (
180209 requireNonNull (getClass ().getClassLoader ().getResource (GUIConstants .APP_HISTORY_FXML_FILE )));
181210 Scene scene = new Scene (pane );
@@ -220,21 +249,22 @@ private void startGuiThread(CodeEvent codeEvent) {
220249 /**
221250 * The method for the event CREATE_APPLICATION
222251 */
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+ }
228257 }
258+
229259 /**
230260 * The method for the event CONTINUE_ON_EXISTING_APPLICATION
231261 */
232- private void codeEventContinueAnApplication (){
233- if (!btn_StopGeneratedApp .isVisible ()) {
262+ private void codeEventContinueAnApplication () {
263+ if (!btn_StopGeneratedApp .isVisible ()) {
234264 setButtonGroupVisibilityForCodeGenerationButtons (false );
235- output_label .setText ("Generating code...\n Continue with existing application" );
236- }
265+ output_label .setText (GUIConstants .CONTINUING_CODE_TEXT );
237266 }
267+ }
238268
239269 /**
240270 * Create application button event
@@ -260,7 +290,6 @@ private void continueOnExistingApplication(ActionEvent ae) {
260290 }
261291 }
262292
263-
264293 /**
265294 * Starts the AI Code-Generation if the text input field is not null
266295 */
@@ -290,20 +319,27 @@ private void waitForCompilationResult() {
290319 }
291320 }
292321
322+
293323 /**
294324 * If a compilation result exist , check if the singleton in code-generator-ollama contains a path for an executable Java file
295325 * If the above is true , activate the "run application" button and remove the "generating code..." text
296326 */
297- private void handleCompilationResult () {
327+ private void handleCompilationResult (boolean isSuperGeneration ) {
298328 if (DataStorage .getInstance ().getCompilationJob ().isResult ()) {
299329 javaExecutablePath = DataStorage .getInstance ().getJavaExecutionPath ();
300330 // Draw success or error texts, and show run app button
301331 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+ }
304337 btn_run_application .setVisible (true );
305338 setButtonGroupVisibilityForCodeGenerationButtons (true );
306339 isCodeGenerationOnGoing = false ;
340+ if (isSuperGeneration ) {
341+ output_label .setText (SUCCESS_ON_SUPER_APP_CREATION_TEXT );
342+ }
307343 } else {
308344 output_label .setText ("Something went wrong :(" );
309345 }
@@ -318,6 +354,7 @@ private void handleCompilationResult() {
318354 private void setButtonGroupVisibilityForCodeGenerationButtons (boolean isVisible ) {
319355 btn_create_application .setVisible (isVisible );
320356 btn_continue_on_application .setVisible (isVisible );
357+ btn_super_app_creation .setVisible (isVisible );
321358 }
322359
323360 /**
@@ -354,4 +391,42 @@ private List<String> readTextByLinesFromFile(File file) {
354391 return null ;
355392 }
356393 }
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+
357432}
0 commit comments