diff --git a/build.gradle b/build.gradle
index 7ca74a8..5d150c7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -49,13 +49,14 @@ repositories {
// dependecies //
///////////////////////////////////////////////////////////////////////////////////
dependencies {
- //compile group: 'org.jfxtras', name: 'jfxtras-labs', version: '8.0-r1-SNAPSHOT' this is not an actual version and the map part is missing
- compile files('lib/JFXtras/jfxtras-labs-8.0-r1-SNAPSHOT.jar', 'lib/ScenicView/ScenicView.jar')
- compile group: 'org.jdom', name: 'jdom2', version: '2.0.5'
- compile group: 'org.controlsfx', name: 'controlsfx', version: '8.0.5'
- compile group: 'com.h2database', name: 'h2', version: '1.3.173'
- compile group: 'org.eclipse.persistence', name: 'eclipselink', version: '2.5.0'
- compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.2.1'
+ //compile group: 'org.jfxtras', name: 'jfxtras-labs', version: '8.0-r1-SNAPSHOT' this is not an actual version and the map part is missing
+ compile files('lib/JFXtras/jfxtras-labs-8.0-r1-SNAPSHOT.jar', 'lib/ScenicView/ScenicView.jar')
+ compile group: 'org.jdom', name: 'jdom2', version: '2.0.5'
+ compile group: 'org.controlsfx', name: 'controlsfx', version: '8.0.5'
+ compile group: 'com.h2database', name: 'h2', version: '1.4.178'
+ compile group: 'org.eclipse.persistence', name: 'eclipselink', version: '2.5.0'
+ compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.2.1'
+ compile group: 'org.jboss.weld.se', name: 'weld-se', version: '2.2.0.Final'
}
///////////////////////////////////////////////////////////////////////////////////
diff --git a/resources/META-INF/beans.xml b/resources/META-INF/beans.xml
new file mode 100644
index 0000000..a90afcf
--- /dev/null
+++ b/resources/META-INF/beans.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/de/geofroggerfx/application/ServiceManager.java b/src/de/geofroggerfx/application/ServiceManager.java
deleted file mode 100644
index 58f2154..0000000
--- a/src/de/geofroggerfx/application/ServiceManager.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2013, Andreas Billmann
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.geofroggerfx.application;
-
-import de.geofroggerfx.gpx.GPXReader;
-import de.geofroggerfx.gpx.GroundspeakGPXReader;
-import de.geofroggerfx.plugins.PluginService;
-import de.geofroggerfx.plugins.PluginServiceImpl;
-import de.geofroggerfx.service.CacheService;
-import de.geofroggerfx.service.CacheServiceImpl;
-import de.geofroggerfx.sql.DatabaseService;
-import de.geofroggerfx.sql.DatabaseServiceImpl;
-
-/**
- * @author Andreas
- */
-public class ServiceManager {
-
- private static final ServiceManager INSTANCE = new ServiceManager();
-
- private GPXReader gpxReader;
- private DatabaseService databaseService;
- private CacheService cacheService;
- private PluginService pluginService;
-
- private ServiceManager() {
- // private for singleton pattern
- }
-
- public static ServiceManager getInstance() {
- return INSTANCE;
- }
-
- public synchronized GPXReader getGPXReader() {
- if (gpxReader == null) {
- gpxReader = new GroundspeakGPXReader();
- }
- return gpxReader;
- }
-
- public synchronized DatabaseService getDatabaseService() {
- if (databaseService == null) {
- databaseService = new DatabaseServiceImpl();
- }
- return databaseService;
- }
-
- public synchronized CacheService getCacheService() {
- if (cacheService == null) {
- cacheService = new CacheServiceImpl();
- }
- return cacheService;
- }
-
- public synchronized PluginService getPluginService() {
- if (pluginService == null) {
- pluginService = new PluginServiceImpl();
- }
- return pluginService;
- }
-
-}
diff --git a/src/de/geofroggerfx/application/SessionContext.java b/src/de/geofroggerfx/application/SessionContext.java
index c82e871..dfbb00b 100644
--- a/src/de/geofroggerfx/application/SessionContext.java
+++ b/src/de/geofroggerfx/application/SessionContext.java
@@ -25,6 +25,7 @@
*/
package de.geofroggerfx.application;
+import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -34,19 +35,12 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* @author Andreas
*/
+@Singleton
public class SessionContext {
- private static final SessionContext INSTANCE = new SessionContext();
private final Map map = new ConcurrentHashMap<>();
private final Map> sessionListeners = new HashMap<>();
- private SessionContext() {
- }
-
- public static SessionContext getInstance() {
- return INSTANCE;
- }
-
public void setData(String key, Object value) {
if (value == null && map.containsKey(key)) {
map.remove(key);
diff --git a/src/de/geofroggerfx/fx/FxMain.java b/src/de/geofroggerfx/fx/FxMain.java
new file mode 100644
index 0000000..c5d4284
--- /dev/null
+++ b/src/de/geofroggerfx/fx/FxMain.java
@@ -0,0 +1,49 @@
+package de.geofroggerfx.fx;
+
+import de.geofroggerfx.fx.utils.StartupScene;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.scene.input.KeyCode;
+import javafx.scene.input.KeyEvent;
+import javafx.stage.Stage;
+import org.scenicview.ScenicView;
+
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ResourceBundle;
+
+/**
+ * This class is based on the tutorial
+ * http://blog.matthieu.brouillard.fr/2012/08/fxml-javafx-powered-by-cdi-jboss-weld_6.html
+ *
+ * Thanks to Matthieu BROUILLARD
+ */
+public class FxMain {
+
+ @Inject
+ private FXMLLoader fxmlLoader;
+
+ public void start( @Observes @StartupScene Stage stage) throws IOException
+ {
+ try (InputStream fxml = getClass().getResourceAsStream( "geofrogger/geofrogger.fxml" )) {
+ fxmlLoader.setResources(ResourceBundle.getBundle("de.geofroggerfx.fx.geofrogger"));
+ final Parent root = fxmlLoader.load(fxml);
+ final Scene scene = new Scene(root);
+ stage.setScene(scene);
+ stage.show();
+
+ scene.setOnKeyPressed(keyEvent -> {
+ if (isScenicViewShortcutPressed(keyEvent)) {
+ ScenicView.show(scene);
+ }
+ });
+ }
+ }
+
+ private boolean isScenicViewShortcutPressed(final KeyEvent keyEvent) {
+ return keyEvent.isAltDown() && keyEvent.isControlDown() && keyEvent.getCode().equals(KeyCode.V);
+ }
+}
diff --git a/src/de/geofroggerfx/fx/GeoFroggerFXMain.java b/src/de/geofroggerfx/fx/GeoFroggerFXMain.java
index 8c54a73..a01cdda 100644
--- a/src/de/geofroggerfx/fx/GeoFroggerFXMain.java
+++ b/src/de/geofroggerfx/fx/GeoFroggerFXMain.java
@@ -25,38 +25,47 @@
*/
package de.geofroggerfx.fx;
-import de.geofroggerfx.application.ServiceManager;
+import de.geofroggerfx.fx.utils.ApplicationParametersProvider;
+import de.geofroggerfx.fx.utils.StartupScene;
+import de.geofroggerfx.sql.DatabaseService;
import javafx.application.Application;
-import javafx.fxml.FXMLLoader;
-import javafx.scene.Parent;
-import javafx.scene.Scene;
-import javafx.scene.input.KeyCode;
-import javafx.scene.input.KeyEvent;
import javafx.scene.text.Font;
import javafx.stage.Stage;
-import org.scenicview.ScenicView;
+import org.jboss.weld.environment.se.Weld;
+import org.jboss.weld.environment.se.WeldContainer;
-import java.util.ResourceBundle;
+import javax.enterprise.util.AnnotationLiteral;
/**
* @author Andreas
*/
public class GeoFroggerFXMain extends Application {
+ private Weld weld;
+ private WeldContainer weldContainer;
+
+ @Override
+ public void init() throws Exception {
+ super.init();
+
+ // Init Weld CDI
+ weld = new Weld();
+ }
+
@Override
public void start(Stage stage) throws Exception {
loadCustomFonts();
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("geofrogger/geofrogger.fxml"), ResourceBundle.getBundle("de.geofroggerfx.fx.geofrogger"));
- Parent root = (Parent)fxmlLoader.load();
- Scene scene = new Scene(root);
- stage.setScene(scene);
- stage.show();
- scene.setOnKeyPressed(keyEvent -> {
- if (isScenicViewShortcutPressed(keyEvent)) {
- ScenicView.show(scene);
- }
- });
+ weldContainer = weld.initialize();
+
+ // Make the application parameters injectable with a standard CDI
+ // annotation
+ weldContainer.instance().select(ApplicationParametersProvider.class).get().setParameters(getParameters());
+
+ // Now that JavaFX thread is ready
+ // let's inform whoever cares using standard CDI notification mechanism:
+ // CDI events
+ weldContainer.event().select(Stage.class, new AnnotationLiteral() {}).fire(stage);
}
private void loadCustomFonts() {
@@ -72,13 +81,10 @@ public class GeoFroggerFXMain extends Application {
Font.loadFont(GeoFroggerFXMain.class.getResource("/fonts/FiraSansOT-RegularItalic.otf").toExternalForm(), 12);
}
- private boolean isScenicViewShortcutPressed(final KeyEvent keyEvent) {
- return keyEvent.isAltDown() && keyEvent.isControlDown() && keyEvent.getCode().equals(KeyCode.V);
- }
-
@Override
public void stop() throws Exception {
- ServiceManager.getInstance().getDatabaseService().getEntityManager().close();
+ weldContainer.instance().select(DatabaseService.class).get().getEntityManager().close();
+ weld.shutdown();
super.stop();
}
diff --git a/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java b/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java
index 7327ae2..3409125 100644
--- a/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java
+++ b/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java
@@ -45,6 +45,7 @@ import javafx.util.Duration;
import jfxtras.labs.map.render.ImageMapMarker;
import jfxtras.labs.map.render.MapMarkable;
+import javax.inject.Inject;
import java.net.URL;
import java.time.LocalDate;
import java.util.Arrays;
@@ -97,7 +98,8 @@ public class CacheDetailsController implements Initializable, SessionContextList
private WebView shortDescriptionWebView;
private WebView longDescriptionWebView;
- private final SessionContext sessionContext = SessionContext.getInstance();
+ @Inject
+ private SessionContext sessionContext;
/**
* Initializes the controller class.
diff --git a/src/de/geofroggerfx/fx/cachedetails/cache_details.fxml b/src/de/geofroggerfx/fx/cachedetails/cache_details.fxml
index 085db1a..810b9a5 100644
--- a/src/de/geofroggerfx/fx/cachedetails/cache_details.fxml
+++ b/src/de/geofroggerfx/fx/cachedetails/cache_details.fxml
@@ -142,6 +142,6 @@
-
+
diff --git a/src/de/geofroggerfx/fx/cachelist/CacheListController.java b/src/de/geofroggerfx/fx/cachelist/CacheListController.java
index dc57abb..bea5464 100644
--- a/src/de/geofroggerfx/fx/cachelist/CacheListController.java
+++ b/src/de/geofroggerfx/fx/cachelist/CacheListController.java
@@ -25,7 +25,6 @@
*/
package de.geofroggerfx.fx.cachelist;
-import de.geofroggerfx.application.ServiceManager;
import de.geofroggerfx.application.SessionContext;
import de.geofroggerfx.application.SessionContextListener;
import de.geofroggerfx.fx.components.CacheListCell;
@@ -39,10 +38,14 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
-import javafx.scene.control.*;
+import javafx.scene.control.Label;
+import javafx.scene.control.ListView;
+import javafx.scene.control.Menu;
+import javafx.scene.control.MenuButton;
import javafx.scene.image.ImageView;
import javafx.util.Callback;
+import javax.inject.Inject;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
@@ -59,8 +62,12 @@ public class CacheListController implements Initializable, SessionContextListene
private static final String CACHE_LIST_ACTION_ICONS = "cache-list-action-icons";
- private final SessionContext sessionContext = SessionContext.getInstance();
- private final CacheService cacheService = ServiceManager.getInstance().getCacheService();
+ @Inject
+ private SessionContext sessionContext;
+
+ @Inject
+ private CacheService cacheService;
+
private SortingMenuItem currentSortingButton = null;
@FXML
diff --git a/src/de/geofroggerfx/fx/cachelist/cache_list.fxml b/src/de/geofroggerfx/fx/cachelist/cache_list.fxml
index f54c3ca..9186b6d 100644
--- a/src/de/geofroggerfx/fx/cachelist/cache_list.fxml
+++ b/src/de/geofroggerfx/fx/cachelist/cache_list.fxml
@@ -26,6 +26,6 @@
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0"/>
-
+
diff --git a/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java b/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java
index be8397e..097b7c9 100644
--- a/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java
+++ b/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java
@@ -26,7 +26,6 @@
package de.geofroggerfx.fx.geofrogger;
import de.geofroggerfx.application.ProgressEvent;
-import de.geofroggerfx.application.ServiceManager;
import de.geofroggerfx.application.SessionContext;
import de.geofroggerfx.gpx.GPXReader;
import de.geofroggerfx.model.Cache;
@@ -45,6 +44,7 @@ import javafx.scene.control.*;
import javafx.stage.FileChooser;
import org.controlsfx.dialog.Dialog;
+import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -53,8 +53,8 @@ import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
-import static de.geofroggerfx.service.CacheSortField.*;
-import static de.geofroggerfx.service.SortDirection.*;
+import static de.geofroggerfx.service.CacheSortField.NAME;
+import static de.geofroggerfx.service.SortDirection.ASC;
/**
* FXML Controller class
@@ -97,13 +97,19 @@ public class GeofroggerController implements Initializable {
+ "\t- H2 1.3.173\n"
+ "\t- Icons by http://iconmonstr.com/\n";
- private final SessionContext sessionContext = SessionContext.getInstance();
+ @Inject
+ private SessionContext sessionContext;
private final LoadCachesFromFileService loadService = new LoadCachesFromFileService();
private final LoadCachesFromDatabaseService loadFromDBService = new LoadCachesFromDatabaseService();
- private final GPXReader gpxReader = ServiceManager.getInstance().getGPXReader();
- private final CacheService cacheService = ServiceManager.getInstance().getCacheService();
- private final PluginService pluginService = ServiceManager.getInstance().getPluginService();
+ @Inject
+ private GPXReader gpxReader;
+
+ @Inject
+ private CacheService cacheService;
+
+ @Inject
+ private PluginService pluginService;
@FXML
private Label leftStatus;
diff --git a/src/de/geofroggerfx/fx/geofrogger/geofrogger.fxml b/src/de/geofroggerfx/fx/geofrogger/geofrogger.fxml
index d74d292..be979ec 100644
--- a/src/de/geofroggerfx/fx/geofrogger/geofrogger.fxml
+++ b/src/de/geofroggerfx/fx/geofrogger/geofrogger.fxml
@@ -29,10 +29,10 @@
-
+
-
+
@@ -56,6 +56,6 @@
-
+
diff --git a/src/de/geofroggerfx/fx/utils/ApplicationParametersProvider.java b/src/de/geofroggerfx/fx/utils/ApplicationParametersProvider.java
new file mode 100644
index 0000000..3c1568d
--- /dev/null
+++ b/src/de/geofroggerfx/fx/utils/ApplicationParametersProvider.java
@@ -0,0 +1,25 @@
+package de.geofroggerfx.fx.utils;
+
+import javafx.application.Application;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Singleton;
+
+/**
+ * This class is based on the tutorial
+ * http://blog.matthieu.brouillard.fr/2012/08/fxml-javafx-powered-by-cdi-jboss-weld_6.html
+ *
+ * Thanks to Matthieu BROUILLARD
+ */
+@Singleton
+public class ApplicationParametersProvider {
+ private Application.Parameters parameters;
+
+ public void setParameters(Application.Parameters p) {
+ this.parameters = p;
+ }
+
+ public @Produces Application.Parameters getParameters() {
+ return parameters;
+ }
+}
diff --git a/src/de/geofroggerfx/fx/utils/FXMLLoaderProducer.java b/src/de/geofroggerfx/fx/utils/FXMLLoaderProducer.java
new file mode 100644
index 0000000..df58ef3
--- /dev/null
+++ b/src/de/geofroggerfx/fx/utils/FXMLLoaderProducer.java
@@ -0,0 +1,27 @@
+package de.geofroggerfx.fx.utils;
+
+import javafx.fxml.FXMLLoader;
+
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+/**
+ * This class is based on the tutorial
+ * http://blog.matthieu.brouillard.fr/2012/08/fxml-javafx-powered-by-cdi-jboss-weld_6.html
+ *
+ * Thanks to Matthieu BROUILLARD
+ */
+public class FXMLLoaderProducer {
+
+ @Inject
+ private Instance