diff --git a/build.gradle b/build.gradle index 5d150c7..e474fb4 100644 --- a/build.gradle +++ b/build.gradle @@ -52,7 +52,7 @@ 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: 'org.controlsfx', name: 'controlsfx', version: '8.0.6' 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' diff --git a/resources/META-INF/persistence.xml b/resources/META-INF/persistence.xml index b52add1..78da4a6 100644 --- a/resources/META-INF/persistence.xml +++ b/resources/META-INF/persistence.xml @@ -11,6 +11,7 @@ de.geofroggerfx.model.Type de.geofroggerfx.model.User de.geofroggerfx.model.Waypoint + de.geofroggerfx.model.CacheList diff --git a/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java b/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java index 3409125..67f8a6c 100644 --- a/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java +++ b/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java @@ -31,7 +31,11 @@ import de.geofroggerfx.fx.components.MapPaneWrapper; import de.geofroggerfx.fx.components.GeocachingIcons; import de.geofroggerfx.fx.components.IconManager; import de.geofroggerfx.model.Cache; +import de.geofroggerfx.model.CacheList; +import de.geofroggerfx.service.CacheService; import javafx.animation.FadeTransition; +import javafx.application.Platform; +import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.Node; @@ -49,6 +53,7 @@ import javax.inject.Inject; import java.net.URL; import java.time.LocalDate; import java.util.Arrays; +import java.util.List; import java.util.ResourceBundle; /** @@ -90,6 +95,9 @@ public class CacheDetailsController implements Initializable, SessionContextList private CheckBox shortDescriptionHtml; @FXML private CheckBox longDescriptionHtml; + @FXML + private MenuButton addToListMenuButton; + private ImageView icon; private FadeTransition ft; @@ -101,6 +109,9 @@ public class CacheDetailsController implements Initializable, SessionContextList @Inject private SessionContext sessionContext; + @Inject + private CacheService cacheService; + /** * Initializes the controller class. * @@ -119,11 +130,11 @@ public class CacheDetailsController implements Initializable, SessionContextList longDescriptionWebView = new WebView(); shortDescriptionField = new TextArea(); longDescriptionField = new TextArea(); + editableForm(false); initFading(); } - @Override public void sessionContextChanged() { Cache currentCache = (Cache) sessionContext.getData("current-cache"); @@ -136,8 +147,35 @@ public class CacheDetailsController implements Initializable, SessionContextList } } + @FXML + public void editCache(final ActionEvent actionEvent) { + + } + + private void setSessionListener() { sessionContext.addListener("current-cache", this); + sessionContext.addListener("cache-lists", () -> Platform.runLater(this::refreshCacheListMenu)); + } + + @SuppressWarnings("unchecked") + private void refreshCacheListMenu() { + List cacheLists = (List) sessionContext.getData("cache-lists"); + addToListMenuButton.getItems().clear(); + cacheLists.stream().forEach(this::addToListMenuItem); + } + + private void addToListMenuItem(CacheList cacheList) { + final MenuItem listItem = new MenuItem(cacheList.getName()); + addToListMenuButton.getItems().add(listItem); + listItem.setOnAction(actionEvent -> addCacheAction(cacheList) + ); + } + + private void addCacheAction(CacheList cacheList) { + Cache currentCache = (Cache) sessionContext.getData("current-cache"); + cacheList.addCache(currentCache); + cacheService.storeCacheList(cacheList); } private void initFading() { diff --git a/src/de/geofroggerfx/fx/cachedetails/cache_details.fxml b/src/de/geofroggerfx/fx/cachedetails/cache_details.fxml index 810b9a5..bdfff7d 100644 --- a/src/de/geofroggerfx/fx/cachedetails/cache_details.fxml +++ b/src/de/geofroggerfx/fx/cachedetails/cache_details.fxml @@ -12,14 +12,21 @@ +