diff --git a/simpleexample2/fxui/build.gradle b/simpleexample2/fxui/build.gradle index 24d94bd5805dfc6223fbe3511ba416bd4757b0d3..5123a2bdf3a7c82f0148d5206f3738dbf39529bb 100644 --- a/simpleexample2/fxui/build.gradle +++ b/simpleexample2/fxui/build.gradle @@ -25,6 +25,10 @@ application { mainClassName = 'simpleex.ui.FxApp' // application plugin } +run { + args = ["http://localhost:8080/", "[[63.1, 11.2], [63.2, 11.0]]"] +} + // javafx specific way of specifying dependencies javafx { version = '11' @@ -61,13 +65,16 @@ dependencies { implementation project(':core') // brukergrensesnitt implementation name: 'fx-map-control-1.0' - + // rest-server (siden den foreløpig må startes av app-en) + implementation project(':restserver') + testImplementation 'junit:junit:4.12' - // brukergrensesnitt + // rest-server testCompile project(':restapi') testImplementation project(':restserver') + // brukergrensesnitt testImplementation 'org.testfx:testfx-core:4.0.16-alpha' testImplementation 'org.testfx:testfx-junit:4.0.16-alpha' testImplementation 'org.mockito:mockito-core:2.28.2' diff --git a/simpleexample2/fxui/src/main/java/simpleex/ui/FxApp.java b/simpleexample2/fxui/src/main/java/simpleex/ui/FxApp.java index cd1bdc3328b893269b2a1eb683f226a5019fccd4..aa0b92aa23cc31f27649bc7a4a06b279518eb036 100644 --- a/simpleexample2/fxui/src/main/java/simpleex/ui/FxApp.java +++ b/simpleexample2/fxui/src/main/java/simpleex/ui/FxApp.java @@ -1,25 +1,57 @@ package simpleex.ui; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import org.glassfish.grizzly.http.server.HttpServer; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; import simpleex.core.LatLongs; +import simpleex.restapi.LatLongsService; +import simpleex.restserver.LatLongGrizzlyApp; public class FxApp extends Application { + private HttpServer restServer = null; @Override public void start(final Stage stage) throws Exception { - final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FxApp.fxml")); + URI baseUri = null; + final List<String> args = getParameters().getRaw(); + if (args.size() >= 1) { + final List<String> serverArgs = new ArrayList<String>(); + baseUri = URI.create(args.get(0)); + serverArgs.add(baseUri.toString()); + if (args.size() >= 2) { + // json of initial data + serverArgs.add(args.get(1)); + } + restServer = LatLongGrizzlyApp.startServer(serverArgs.toArray(new String[serverArgs.size()])); + } + final String fxml = (baseUri != null ? "FxAppUsingRest.fxml" : "FxApp.fxml"); + final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(fxml)); final Parent root = fxmlLoader.load(); - final FxAppController controller = fxmlLoader.getController(); - controller.setLatLongs(new LatLongs(63.1, 11.2, 63.2, 11.0)); + if (baseUri == null) { + // set initial data manually + final FxAppController controller = fxmlLoader.getController(); + controller.setLatLongs(new LatLongs(63.1, 11.2, 63.2, 11.0)); + } else { + final FxAppUsingRestController controller = fxmlLoader.getController(); + controller.setDataAccess(new RestLatLongsDataAccess(baseUri + LatLongsService.LAT_LONG_SERVICE_PATH, controller.getObjectMapper())); + } final Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } + @Override + public void stop() throws Exception { + restServer.shutdown(); + super.stop(); + } + /** * Launches the app. * @param args the command line arguments diff --git a/simpleexample2/fxui/src/main/java/simpleex/ui/FxAppUsingRestController.java b/simpleexample2/fxui/src/main/java/simpleex/ui/FxAppUsingRestController.java index 905bac6013c813bf176d3106550a73fc273792ad..e424f3bd280a9bdad278f7c58c831771d1f3b0de 100644 --- a/simpleexample2/fxui/src/main/java/simpleex/ui/FxAppUsingRestController.java +++ b/simpleexample2/fxui/src/main/java/simpleex/ui/FxAppUsingRestController.java @@ -25,6 +25,6 @@ FxAppController --> ListView: "locationListView" public class FxAppUsingRestController extends AbstractFxAppController { public FxAppUsingRestController() { - setDataAccess(new RestLatLongsDataAccess("http://localhost:8080/dict", getObjectMapper())); +// setDataAccess(new RestLatLongsDataAccess("http://localhost:8080/latLong", getObjectMapper())); } } diff --git a/simpleexample2/restserver/build.gradle b/simpleexample2/restserver/build.gradle index c472e7c019a9cbbe04ce39c747f2da0868d79dce..ce20dad6262705dbe2bd6748906c0b9fbd2013b0 100644 --- a/simpleexample2/restserver/build.gradle +++ b/simpleexample2/restserver/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'application' + id 'java-library' } ext { @@ -7,15 +7,18 @@ ext { jerseyVersion = '2.28' } -application { - sourceCompatibility = JavaVersion.VERSION_1_10 - targetCompatibility = JavaVersion.VERSION_1_10 - mainClassName = 'simpleex.restserver.LatLongGrizzlyApp' -} +sourceCompatibility = JavaVersion.VERSION_1_10 +targetCompatibility = JavaVersion.VERSION_1_10 + +//application { +// sourceCompatibility = JavaVersion.VERSION_1_10 +// targetCompatibility = JavaVersion.VERSION_1_10 +// // mainClassName = 'simpleex.restserver.LatLongGrizzlyApp' +//} dependencies { implementation project(':core') - implementation project(':restapi') + compile project(':restapi') compile "org.slf4j:slf4j-api:$slf4jVersion" compile "org.slf4j:slf4j-simple:$slf4jVersion"