Skip to content

Commit f8e7698

Browse files
authored
Merge pull request #145 from pwgit-create/develop
Develop
2 parents 814f853 + 373d325 commit f8e7698

File tree

9 files changed

+136
-62
lines changed

9 files changed

+136
-62
lines changed

AppWish/AppWish/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>pn.dev</groupId>
77
<artifactId>code-generator-gui-ollama</artifactId>
8-
<version>1.7.3</version>
8+
<version>1.8</version>
99
<name>CodeGenerator-GUI</name>
1010

1111

@@ -45,7 +45,7 @@
4545
<dependency>
4646
<groupId>pn.dev</groupId>
4747
<artifactId>code-generator-ollama</artifactId>
48-
<version>1.7.3</version>
48+
<version>1.8</version>
4949
</dependency>
5050
<dependency>
5151
<groupId>org.openjfx</groupId>

AppWish/AppWish/src/main/java/pn/app_wish/AppWish.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public static Stage getMainStage() {
8383
@Override
8484
public void init() throws Exception {
8585
super.init();
86+
87+
8688
}
8789

8890
@Override
@@ -172,12 +174,15 @@ private void onRunJavaApp(ActionEvent ae) {
172174

173175
@FXML
174176
private void onViewAppHistory(ActionEvent ae) throws IOException {
175-
AnchorPane pane = FXMLLoader.load(
176-
requireNonNull(getClass().getClassLoader().getResource(GUIConstants.APP_HISTORY_FXML_FILE)));
177-
Scene scene = new Scene(pane);
178-
mainStage.setScene(scene);
179-
mainStage.setTitle(APP_HISTORY_STAGE_TILE);
180-
mainStage.show();
177+
178+
if(!isCodeGenerationOnGoing) {
179+
AnchorPane pane = FXMLLoader.load(
180+
requireNonNull(getClass().getClassLoader().getResource(GUIConstants.APP_HISTORY_FXML_FILE)));
181+
Scene scene = new Scene(pane);
182+
mainStage.setScene(scene);
183+
mainStage.setTitle(APP_HISTORY_STAGE_TILE);
184+
mainStage.show();
185+
}
181186
}
182187

183188
@FXML
@@ -202,18 +207,35 @@ private void startGuiThread(CodeEvent codeEvent) {
202207

203208
switch (codeEvent) {
204209
case CREATE_APPLICATION:
205-
output_label.setText("Generating code...");
210+
codeEventCreateApplication();
206211
break;
207212
case CONTINUE_ON_EXISTING_APPLICATION:
208-
output_label.setText("Generating code...\nContinue with existing application");
213+
codeEventContinueAnApplication();
209214
break;
210215
}
211216

212-
setButtonGroupVisibilityForCodeGenerationButtons(false);
213-
btn_StopGeneratedApp.setVisible(false);
214217
});
215218
}
216219

220+
/**
221+
* The method for the event CREATE_APPLICATION
222+
*/
223+
private void codeEventCreateApplication(){
224+
if(!btn_StopGeneratedApp.isVisible()){
225+
setButtonGroupVisibilityForCodeGenerationButtons(false);
226+
output_label.setText("Generating code...");
227+
}
228+
}
229+
/**
230+
* The method for the event CONTINUE_ON_EXISTING_APPLICATION
231+
*/
232+
private void codeEventContinueAnApplication(){
233+
if(!btn_StopGeneratedApp.isVisible()) {
234+
setButtonGroupVisibilityForCodeGenerationButtons(false);
235+
output_label.setText("Generating code...\nContinue with existing application");
236+
}
237+
}
238+
217239
/**
218240
* Create application button event
219241
*/
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package pn.app_wish.constant;
22

33
public record StaticAppWishConstants() {
4-
public static final String BASH_PATH="/bin/bash";
4+
public static final String BASH_PATH = "/bin/bash";
55
public static final String C_ARGUMENT = "-c";
6-
public final static String JAVA_TEXT="java ";
7-
public final static String CONTINUE_ON_APPLICATION_FILTER_ON_JAVA_EXTENSION="*.java";
8-
public final static String CONTINUE_ON_APPLICATION_FILTER_ON_JAVA_EXTENSION_DESCRIPTION="A extension filter with purpose to only show .java files";
9-
public final static String FOLDER_NAME_OF_GENERATED_JAVA_APPLICATIONS="java_source_code_classes_tmp";
6+
public final static String JAVA_TEXT = "java ";
7+
8+
public final static String CONTINUE_ON_APPLICATION_FILTER_ON_JAVA_EXTENSION = "*.java";
9+
public final static String CONTINUE_ON_APPLICATION_FILTER_ON_JAVA_EXTENSION_DESCRIPTION = "A extension filter with purpose to only show .java files";
10+
public final static String FOLDER_NAME_OF_GENERATED_JAVA_APPLICATIONS = "java_source_code_classes_tmp";
1011
}

AppWish/AppWish/src/main/java/pn/app_wish/controller/AppHistoryController.java

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
package pn.app_wish.controller;
22

3+
import javafx.application.Platform;
34
import javafx.event.ActionEvent;
45
import javafx.fxml.FXML;
56
import javafx.fxml.FXMLLoader;
67
import javafx.fxml.Initializable;
78
import javafx.scene.Scene;
8-
import javafx.scene.control.Button;
9-
import javafx.scene.control.ListCell;
10-
import javafx.scene.control.ListView;
9+
import javafx.scene.control.*;
1110
import javafx.scene.layout.AnchorPane;
1211
import javafx.scene.layout.Pane;
1312
import javafx.stage.Stage;
1413
import javafx.util.Callback;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
1516
import pn.app_wish.AppWish;
1617
import pn.app_wish.constant.GUIConstants;
18+
import pn.app_wish.constant.StaticAppWishConstants;
1719
import pn.app_wish.util.AppWishUtil;
1820
import pn.cg.datastorage.constant.PathConstants;
1921

2022
import java.io.File;
2123
import java.io.IOException;
2224
import java.net.URL;
2325

24-
import java.util.Arrays;
25-
import java.util.List;
26-
import java.util.Objects;
27-
import java.util.ResourceBundle;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
28+
import java.util.*;
2829
import java.util.stream.Collectors;
2930

3031
import static pn.app_wish.constant.GUIConstants.DEFAULT_STAGE_TITLE;
@@ -33,6 +34,8 @@
3334

3435
public class AppHistoryController implements Initializable {
3536

37+
private static final Logger log = LoggerFactory.getLogger(AppHistoryController.class);
38+
3639
@FXML
3740
private ListView<File> fileListView;
3841

@@ -45,6 +48,9 @@ public class AppHistoryController implements Initializable {
4548
@FXML
4649
private Button btnMainScene;
4750

51+
@FXML
52+
private Button btnDeleteApp;
53+
4854
private Process executingJavaAppProcess;
4955

5056

@@ -108,7 +114,9 @@ protected void updateItem(File item, boolean empty) {
108114

109115
@FXML
110116
private void goToMainScene(ActionEvent ae) {
111-
117+
if(this.executingJavaAppProcess != null) {
118+
this.executingJavaAppProcess.toHandle().destroy();
119+
}
112120
Pane pane;
113121
try {
114122
pane = FXMLLoader.load(
@@ -128,4 +136,42 @@ private void stopExecutedJavaApp(ActionEvent ae) {
128136
btnStopApp.setVisible(false);
129137
this.executingJavaAppProcess.toHandle().destroy();
130138
}
139+
140+
@FXML private void showConfirmDialogForDeletionOfAnJavaApplication(ActionEvent ae) {
141+
142+
if (fileListView != null) {
143+
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
144+
alert.setTitle("Delete an Java Application");
145+
alert.setHeaderText("Are you sure?\nYou can´t regret this action later!");
146+
alert.setContentText("Do you want to proceed with the action?");
147+
Optional<ButtonType> result = alert.showAndWait();
148+
if (result.isPresent() && result.get() == ButtonType.OK) {
149+
deleteJavaApp(fileListView.getSelectionModel().selectedItemProperty().getValue());
150+
} else {log.info("Action Canceled");}
151+
}
152+
}
153+
private void deleteJavaApp(File classFileOfApplication){
154+
155+
Platform.runLater(() -> {
156+
157+
try {
158+
159+
// Delete the Class File of the chosen application
160+
Files.delete(classFileOfApplication.toPath());
161+
log.info("The class file of your selected application has been deleted");
162+
} catch (IOException e) {
163+
164+
log.error("Could not delete the application");
165+
}
166+
});
167+
168+
Platform.runLater(() -> {
169+
try {
170+
listHistoryApplications();
171+
fileListView.refresh();
172+
} catch (Exception e) {
173+
throw new RuntimeException(e);
174+
}
175+
});
176+
}
131177
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<?import javafx.scene.control.ListView?>
4-
<?import javafx.scene.layout.AnchorPane?>
5-
<?import javafx.scene.control.Button?>
3+
<?import javafx.scene.control.*?>
4+
<?import javafx.scene.layout.*?>
65

7-
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19.0.2.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pn.app_wish.controller.AppHistoryController">
6+
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pn.app_wish.controller.AppHistoryController">
87

98
<ListView fx:id="fileListView" prefHeight="400.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
10-
<Button fx:id="selectButton" style="-fx-background-color: green;" layoutX="210.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleSelectButtonAction" text="Run" />
9+
<Button fx:id="selectButton" layoutX="210.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleSelectButtonAction" style="-fx-background-color: green;" text="Run" textFill="#f8f8f8" />
1110
<Button fx:id="btnMainScene" mnemonicParsing="false" onAction="#goToMainScene" style="-fx-background-color: #00328c" text="Back" textFill="WHITE" />
1211
<Button fx:id="btnStopApp" mnemonicParsing="false" onAction="#stopExecutedJavaApp" style="-fx-background-color: red" text="Stop your app" textFill="WHITE" />
13-
</AnchorPane>
12+
<Button fx:id="btnDeleteApp" layoutX="531.0" layoutY="368.0" mnemonicParsing="false" onAction="#showConfirmDialogForDeletionOfAnJavaApplication" style="-fx-background-color:red;" text="Delete" textFill="#f5eef5" />
13+
14+
</AnchorPane>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
MODEL_NAME=codestral:22b
1+
MODEL_NAME=llama3:latest

AppWish/AppWish/src/main/resources/start.fxml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<Font name="Century" size="18.0"/>
2525
</font>
2626
</Label>
27-
<Button fx:id="btn_create_application" mnemonicParsing="false" onAction="#createApplication"
28-
style="-fx-background-color: #00328c" text="Create application" textFill="WHITE"
27+
<Button fx:id="btn_continue_on_application" mnemonicParsing="false" onAction="#continueOnExistingApplication"
28+
style="-fx-background-color: #00328c; -fx-padding:3" text="Continue an app" textFill="WHITE"
2929
BorderPane.alignment="BOTTOM_LEFT"/>
3030
</VBox>
3131
</bottom>
@@ -62,9 +62,9 @@
6262
</TextField>
6363
</center>
6464
<left>
65-
<Button fx:id="btn_continue_on_application" mnemonicParsing="false"
66-
onAction="#continueOnExistingApplication"
67-
style="-fx-background-color: #00328c" text="Continue" textFill="ORANGE"
65+
<Button fx:id="btn_create_application" mnemonicParsing="false"
66+
onAction="#createApplication"
67+
style="-fx-background-color: #00328c" text="New App" textFill="WHITE"
6868
BorderPane.alignment="BOTTOM_LEFT"/>
6969
</left>
7070
<right>

cg/CodeGenerator/CodeGenerator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>pn.dev</groupId>
88
<artifactId>code-generator-ollama</artifactId>
9-
<version>1.7.3</version>
9+
<version>1.8</version>
1010

1111

1212
<description>The Java Application-Generator (pn.dev.code-generator-ollama) creates applications by giving a string of your desired features for a Java application, like this: AppSystem.StartCodeGenerator(String appWish)</description>

cg/CodeGenerator/CodeGenerator/src/main/java/pn/cg/app_system/AppSystem.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.slf4j.LoggerFactory;
55

66
import pn.cg.ollama_ai_remote.OllamaRemoteSystem;
7+
78
import java.util.List;
89

910
import static pn.cg.util.CodeGeneratorUtil.isThisACreateNewAppRequest;
@@ -21,25 +22,27 @@ public class AppSystem {
2122
* @param isFirstRun Flag that shows if this is the first request attempt to ollama
2223
* @param appWishCompileResult The method will call itself recursively unless this is true
2324
*/
24-
private static void StartCodeGenerator(String appWish, boolean isFirstRun, boolean appWishCompileResult,boolean isCreateAppGeneration,
25-
String pathOfJavaFileIfModifyRequest, List<String> javaFileContentInLines) {
26-
log.info("Started the AppSystem");
25+
private static void StartCodeGenerator(String appWish, boolean isFirstRun, boolean appWishCompileResult, boolean isCreateAppGeneration,
26+
String pathOfJavaFileIfModifyRequest, List<String> javaFileContentInLines) {
27+
2728

2829
OllamaRemoteSystem ollamaRemoteSystem = new OllamaRemoteSystem();
2930

3031
try {
31-
Thread.sleep(2500);
32+
Thread.sleep(1500);
3233
} catch (InterruptedException e) {
3334

35+
Thread.currentThread().interrupt();
3436
}
35-
if (isFirstRun) {
3637

38+
39+
if (isFirstRun) {
40+
log.info("Started the AppSystem");
3741
retryCounter = 1;
38-
if(isCreateAppGeneration){
39-
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, true,"",null);
40-
}
41-
else{
42-
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish,true,pathOfJavaFileIfModifyRequest,javaFileContentInLines);
42+
if (isCreateAppGeneration) {
43+
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, true, "", null);
44+
} else {
45+
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, true, pathOfJavaFileIfModifyRequest, javaFileContentInLines);
4346
}
4447
}
4548

@@ -53,32 +56,33 @@ private static void StartCodeGenerator(String appWish, boolean isFirstRun, boole
5356
retryCounter++;
5457
log.debug("In CheckCompilationRetryCounter with counter -> {}", retryCounter);
5558

56-
if(isCreateAppGeneration)
57-
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, false,"",null);
59+
if (isCreateAppGeneration)
60+
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, false, "", null);
5861
else
59-
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish,false,pathOfJavaFileIfModifyRequest,javaFileContentInLines);
62+
appWishCompileResult = ollamaRemoteSystem.CreateApp(appWish, false, pathOfJavaFileIfModifyRequest, javaFileContentInLines);
6063

61-
if(isCreateAppGeneration){
62-
StartCodeGenerator(appWish, false, appWishCompileResult,isCreateAppGeneration,"",null);}
63-
else{
64-
StartCodeGenerator(appWish,false,appWishCompileResult,isCreateAppGeneration,pathOfJavaFileIfModifyRequest,javaFileContentInLines);}
64+
if (isCreateAppGeneration) {
65+
StartCodeGenerator(appWish, false, appWishCompileResult, isCreateAppGeneration, "", null);
66+
} else {
67+
StartCodeGenerator(appWish, false, appWishCompileResult, isCreateAppGeneration, pathOfJavaFileIfModifyRequest, javaFileContentInLines);
68+
}
6569
}
6670
}
6771

6872
/**
6973
* Create a new App with Code Generation
7074
*/
71-
public static void StartCodeGenerator(String appWish){
72-
StartCodeGenerator( appWish,true, false,true,"", null);
73-
}
75+
public static void StartCodeGenerator(String appWish) {
76+
StartCodeGenerator(appWish, true, false, true, "", null);
77+
}
7478

7579
/**
7680
* Continue with improvements for an existing app
7781
*/
78-
public static void StartCodeGenerator(String continueWithImprovementText,String javaClassName, List<String> javaFileContentInLines){
79-
80-
StartCodeGenerator(continueWithImprovementText,true, false ,false ,javaClassName,javaFileContentInLines);
81-
}
82+
public static void StartCodeGenerator(String continueWithImprovementText, String javaClassName, List<String> javaFileContentInLines) {
83+
84+
StartCodeGenerator(continueWithImprovementText, true, false, false, javaClassName, javaFileContentInLines);
85+
}
8286

8387
}
8488

0 commit comments

Comments
 (0)