diff --git a/build.sh b/build.sh index 95d96ec377..1b56c56c1d 100644 --- a/build.sh +++ b/build.sh @@ -23,7 +23,6 @@ doRunCommand "mvn install $MVN_SETTINGS bundle:bundle -Pp2-build,p2-bundle -Dski log_step "Package & Run E2E Tests" doRunCommand "mvn test $MVN_SETTINGS -f cobigen/cobigen-core-systemtest $ENABLED_TEST $DEBUG $BATCH_MODE" -doRunCommand "mvn install $MVN_SETTINGS -f cobigen-gui $ENABLED_TEST $DEBUG $BATCH_MODE" doRunCommand "mvn install $MVN_SETTINGS -f cobigen-cli $ENABLED_TEST $DEBUG $BATCH_MODE" doRunCommand "mvn install $MVN_SETTINGS -f cobigen-maven $ENABLED_TEST $DEBUG $BATCH_MODE" doRunCommand "mvn install $MVN_SETTINGS -f cobigen-templates $ENABLED_TEST $DEBUG $BATCH_MODE" diff --git a/cobigen/gui/pom.xml b/cobigen/gui/pom.xml index 8a822e0a2f..26ae4900b9 100644 --- a/cobigen/gui/pom.xml +++ b/cobigen/gui/pom.xml @@ -15,7 +15,7 @@ UTF-8 11 11 - 11 + 18 0.0.6 @@ -47,6 +47,12 @@ 4.0.15-alpha test + + org.assertj + assertj-core + 3.13.2 + test + @@ -62,7 +68,15 @@ javafx-maven-plugin ${javafx.maven.plugin.version} - com.devonfw.cobigen.gui.Main + com.devonfw.cobigen.gui.App + + + + org.apache.maven.plugins + maven-surefire-plugin + + + false diff --git a/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/App.java b/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/App.java index 304871c0c1..a3e6251837 100644 --- a/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/App.java +++ b/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/App.java @@ -47,33 +47,19 @@ public void printSomething() { } @Override - public void start(Stage stage) throws IOException { + public void start(Stage primaryStage) throws IOException { this.window = new Stage(); + Parent root = FXMLLoader.load(getClass().getResource("Primary.fxml")); - scene = new Scene(loadFXML("primary")); - scene.getStylesheets().add(getClass().getResource("styles.css").toExternalForm()); + App.scene = new Scene(root); + App.scene.getStylesheets().add(getClass().getResource("styles.css").toExternalForm()); Image image = new Image(App.class.getResource("icons/devon-icon.jpg").toExternalForm()); - this.window.getIcons().add(image); this.window.setTitle("Template Set Manager"); - - this.window.setScene(scene); + this.window.getIcons().add(image); + this.window.setScene(App.scene); this.window.showAndWait(); - // stage.setScene(scene); - // stage.show(); - - } - - static void setRoot(String fxml) throws IOException { - - scene.setRoot(loadFXML(fxml)); - } - - private static Parent loadFXML(String fxml) throws IOException { - - FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml")); - return fxmlLoader.load(); } } diff --git a/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/Controller.java b/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/Controller.java index ff022c4ddd..5a147b058d 100644 --- a/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/Controller.java +++ b/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/Controller.java @@ -1,5 +1,6 @@ package com.devonfw.cobigen.gui; +import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; @@ -8,11 +9,13 @@ import java.util.stream.Collectors; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.ListView; import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; +import javafx.scene.layout.AnchorPane; /** * Controller for the Template Set Management GUI @@ -22,6 +25,15 @@ public class Controller implements Initializable { ArrayList templateSets = new ArrayList<>(Arrays.asList("templates-devon4j-tests", "templates-devon4j-utils", "crud-openapi-net", "crud-angular-client-app", "crud-ionic-client-app", "rest-documentation")); + @FXML + private AnchorPane detailsPane; + + @FXML + private AnchorPane homePane; + + @FXML + public Button homeButton; + @FXML public Button clearSearchResultsButton; @@ -32,6 +44,33 @@ public class Controller implements Initializable { @FXML public ListView searchResultsView; + /** + * Initial View + */ + @Override + public void initialize(URL arg0, ResourceBundle arg1) { + + this.searchResultsView.getItems().addAll(this.templateSets); + } + + @FXML + public void loadHome(javafx.event.ActionEvent actionEvent) throws IOException { + + AnchorPane homePane = FXMLLoader.load(getClass().getResource("Home.fxml")); + this.detailsPane.getChildren().setAll(homePane); + } + + /** + * @param actionEvent + * @throws IOException + */ + public void details(javafx.event.ActionEvent actionEvent) throws IOException { + + } + + /** + * @param event + */ @FXML public void search(KeyEvent event) { @@ -50,15 +89,6 @@ public void clearSearchResults() { this.searchResultsView.getItems().addAll(this.templateSets); } - /** - * Initial View - */ - @Override - public void initialize(URL arg0, ResourceBundle arg1) { - - this.searchResultsView.getItems().addAll(this.templateSets); - } - /** * @param text * @param templateSets2 diff --git a/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/HomeController.java b/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/HomeController.java new file mode 100644 index 0000000000..6b559ae431 --- /dev/null +++ b/cobigen/gui/src/main/java/com/devonfw/cobigen/gui/HomeController.java @@ -0,0 +1,21 @@ +package com.devonfw.cobigen.gui; + +import java.net.URL; +import java.util.ResourceBundle; + +import javafx.fxml.Initializable; + +/** + * TODO nneuhaus This type ... + * + */ +public class HomeController implements Initializable { + + @Override + public void initialize(URL location, ResourceBundle resources) { + + // TODO Auto-generated method stub + + } + +} diff --git a/cobigen/gui/src/main/java/module-info.java b/cobigen/gui/src/main/java/module-info.java deleted file mode 100644 index 5ccd640e6f..0000000000 --- a/cobigen/gui/src/main/java/module-info.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * @author nneuhaus - * - */ -module gui { - requires javafx.controls; - - requires javafx.fxml; - - requires transitive javafx.graphics; - - requires junit; - - opens com.devonfw.cobigen.gui to javafx.fxml; - - exports com.devonfw.cobigen.gui; -} \ No newline at end of file diff --git a/cobigen/gui/src/main/resources/com/devonfw/cobigen/gui/Home.fxml b/cobigen/gui/src/main/resources/com/devonfw/cobigen/gui/Home.fxml new file mode 100644 index 0000000000..e3733ec692 --- /dev/null +++ b/cobigen/gui/src/main/resources/com/devonfw/cobigen/gui/Home.fxml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cobigen/gui/src/main/resources/com/devonfw/cobigen/gui/primary.fxml b/cobigen/gui/src/main/resources/com/devonfw/cobigen/gui/Primary.fxml similarity index 55% rename from cobigen/gui/src/main/resources/com/devonfw/cobigen/gui/primary.fxml rename to cobigen/gui/src/main/resources/com/devonfw/cobigen/gui/Primary.fxml index 66e547b63d..e3a6cdc062 100644 --- a/cobigen/gui/src/main/resources/com/devonfw/cobigen/gui/primary.fxml +++ b/cobigen/gui/src/main/resources/com/devonfw/cobigen/gui/Primary.fxml @@ -18,7 +18,7 @@ - + @@ -27,7 +27,7 @@ + + + diff --git a/cobigen/gui/src/test/java/com/devonfw/cobigen/gui/HomePageTest.java b/cobigen/gui/src/test/java/com/devonfw/cobigen/gui/HomePageTest.java index 5c8b9e8166..8fe9b34830 100644 --- a/cobigen/gui/src/test/java/com/devonfw/cobigen/gui/HomePageTest.java +++ b/cobigen/gui/src/test/java/com/devonfw/cobigen/gui/HomePageTest.java @@ -2,9 +2,10 @@ import org.junit.Test; import org.testfx.api.FxRobotException; +import org.testfx.assertions.api.Assertions; /** - * TODO nneuhaus This type ... + * Tests for the Home Page of GUI * */ public class HomePageTest extends TestFXBase { @@ -18,4 +19,22 @@ public void clickOnBogusElement() { clickOn("#NotExisting"); } + /** + * Test if the home page is shown when GUI is started + */ + @Test + public void ensureHomePageIsShownOnStartUp() { + + Assertions.assertThat(this.mainRoot.lookup("#homePane").getParent().equals(this.mainRoot.lookup("#detailsPane"))); + } + + @Test + public void ensureHomePageIsShownOnHomeButtonClicked() { + + // TODO: Switch to a Template Set before switching back to Home + String HOME_BUTTON = "#homeButton"; + clickOn(HOME_BUTTON); + // Assertions.assertThat(lookup("#homePane")); + } + } diff --git a/cobigen/gui/src/test/java/com/devonfw/cobigen/gui/TestFXBase.java b/cobigen/gui/src/test/java/com/devonfw/cobigen/gui/TestFXBase.java index e25b7c4e9b..b275a3250d 100644 --- a/cobigen/gui/src/test/java/com/devonfw/cobigen/gui/TestFXBase.java +++ b/cobigen/gui/src/test/java/com/devonfw/cobigen/gui/TestFXBase.java @@ -1,15 +1,20 @@ package com.devonfw.cobigen.gui; +import java.util.ResourceBundle; import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.testfx.api.FxToolkit; import org.testfx.framework.junit.ApplicationTest; +import javafx.fxml.FXMLLoader; import javafx.scene.Node; +import javafx.scene.Scene; import javafx.scene.input.KeyCode; import javafx.scene.input.MouseButton; +import javafx.scene.layout.Pane; import javafx.stage.Stage; /** @@ -18,21 +23,49 @@ */ public class TestFXBase extends ApplicationTest { + Pane mainRoot; + + Stage mainStage; + + Controller controller; + + protected static ResourceBundle bundle; + + /** + * + */ + @BeforeClass + public static void setupHeadlessMode() { + + if (Boolean.getBoolean("headless")) { + System.setProperty("testfx.robot", "glass"); + System.setProperty("testfx.headless", "true"); + System.setProperty("prism.order", "sw"); + System.setProperty("prism.text", "t2k"); + System.setProperty("java.awt.headless", "true"); + } + + // bundle = ResourceBundle.getBundle("Bundle"); + } + /** * @throws Exception */ - @SuppressWarnings("javadoc") @Before - public void setUpClass() throws Exception { + public void setUp() throws Exception { - ApplicationTest.launch(App.class); } @Override public void start(Stage stage) throws Exception { - // TODO Auto-generated method stub - + this.mainStage = stage; + FXMLLoader loader = new FXMLLoader(getClass().getResource("Primary.fxml")); + this.mainRoot = loader.load(); + this.controller = loader.getController(); + stage.setScene(new Scene(this.mainRoot)); + stage.show(); + stage.toFront(); } /**