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 @@
+
+
-
+
+
+
+
+
+
diff --git a/src/de/geofroggerfx/fx/cachelist/CacheListController.java b/src/de/geofroggerfx/fx/cachelist/CacheListController.java
index bea5464..eb85ac4 100644
--- a/src/de/geofroggerfx/fx/cachelist/CacheListController.java
+++ b/src/de/geofroggerfx/fx/cachelist/CacheListController.java
@@ -26,11 +26,11 @@
package de.geofroggerfx.fx.cachelist;
import de.geofroggerfx.application.SessionContext;
-import de.geofroggerfx.application.SessionContextListener;
import de.geofroggerfx.fx.components.CacheListCell;
import de.geofroggerfx.fx.components.IconManager;
import de.geofroggerfx.fx.components.SortingMenuItem;
import de.geofroggerfx.model.Cache;
+import de.geofroggerfx.model.CacheList;
import de.geofroggerfx.service.CacheService;
import de.geofroggerfx.service.CacheSortField;
import javafx.application.Platform;
@@ -38,10 +38,7 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
-import javafx.scene.control.Label;
-import javafx.scene.control.ListView;
-import javafx.scene.control.Menu;
-import javafx.scene.control.MenuButton;
+import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.util.Callback;
@@ -58,7 +55,7 @@ import static de.geofroggerfx.service.CacheSortField.*;
*
* @author Andreas
*/
-public class CacheListController implements Initializable, SessionContextListener {
+public class CacheListController implements Initializable {
private static final String CACHE_LIST_ACTION_ICONS = "cache-list-action-icons";
@@ -79,6 +76,9 @@ public class CacheListController implements Initializable, SessionContextListene
@FXML
private MenuButton menuIcon;
+ @FXML
+ private ComboBox cacheListComboBox;
+
/**
* Initializes the controller class.
*
@@ -96,19 +96,11 @@ public class CacheListController implements Initializable, SessionContextListene
sessionContext.setData("current-cache", newValue)
);
+ initCacheListComboBox();
initListMenuButton(rb);
}
- @Override
@SuppressWarnings("unchecked")
- public void sessionContextChanged() {
- List caches = (List) sessionContext.getData("cache-list");
- Platform.runLater(() -> {
- cacheNumber.setText("(" + caches.size() + ")");
- cacheListView.getItems().setAll(caches);
- });
- }
-
private void setCellFactory() {
cacheListView.setCellFactory(
(Callback, CacheListCell>)
@@ -116,7 +108,45 @@ public class CacheListController implements Initializable, SessionContextListene
}
private void setSessionListener() {
- sessionContext.addListener("cache-list", this);
+ sessionContext.addListener("cache-list", () -> Platform.runLater(this::resetCacheList));
+ sessionContext.addListener("cache-lists", () -> Platform.runLater(this::refreshCacheListComboAndSelectFirst));
+ }
+
+ @SuppressWarnings("unchecked")
+ private void resetCacheList() {
+ List caches = (List) sessionContext.getData("cache-list");
+ cacheNumber.setText("(" + caches.size() + ")");
+ cacheListView.getItems().setAll(caches);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void refreshCacheListComboAndSelectFirst() {
+ List cacheLists = (List) sessionContext.getData("cache-lists");
+ cacheListComboBox.getItems().clear();
+ cacheListComboBox.getItems().add("All caches");
+ cacheListComboBox.getItems().addAll(cacheLists);
+ cacheListComboBox.getSelectionModel().selectFirst();
+ }
+
+
+ private void initCacheListComboBox() {
+ cacheListComboBox.setOnAction(actionEvent -> {
+ final Object selectedItem = cacheListComboBox.getSelectionModel().getSelectedItem();
+ Platform.runLater(() -> cacheListSelectAction(selectedItem));
+ });
+ }
+
+ private void cacheListSelectAction(Object selectedItem) {
+ if (selectedItem != null) {
+ if (selectedItem.equals("All caches")) {
+ loadAllCaches();
+ } else{
+ CacheList cacheList = (CacheList)selectedItem;
+ sessionContext.setData("cache-list", cacheList.getCaches());
+ }
+ } else {
+ cacheListComboBox.getSelectionModel().selectFirst();
+ }
}
private void initListMenuButton(final ResourceBundle rb) {
@@ -150,12 +180,14 @@ public class CacheListController implements Initializable, SessionContextListene
}
currentSortingButton.setSelected(true);
- sessionContext.setData("cache-list", cacheService.getAllCaches(currentSortingButton.getField(), currentSortingButton.getSortDirection()));
+ loadAllCaches();
});
return button;
}
-
+ private void loadAllCaches() {
+ sessionContext.setData("cache-list", cacheService.getAllCaches(currentSortingButton.getField(), currentSortingButton.getSortDirection()));
+ }
}
diff --git a/src/de/geofroggerfx/fx/cachelist/cache_list.fxml b/src/de/geofroggerfx/fx/cachelist/cache_list.fxml
index 9186b6d..face900 100644
--- a/src/de/geofroggerfx/fx/cachelist/cache_list.fxml
+++ b/src/de/geofroggerfx/fx/cachelist/cache_list.fxml
@@ -16,6 +16,7 @@
+
diff --git a/src/de/geofroggerfx/fx/components/SortingMenuItem.java b/src/de/geofroggerfx/fx/components/SortingMenuItem.java
index a395e51..57805df 100644
--- a/src/de/geofroggerfx/fx/components/SortingMenuItem.java
+++ b/src/de/geofroggerfx/fx/components/SortingMenuItem.java
@@ -1,3 +1,28 @@
+/*
+ * Copyright (c) 2014, 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.fx.components;
import de.geofroggerfx.service.CacheSortField;
diff --git a/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java b/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java
index 097b7c9..b1ae4d0 100644
--- a/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java
+++ b/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java
@@ -39,8 +39,11 @@ import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.Pane;
import javafx.stage.FileChooser;
import org.controlsfx.dialog.Dialog;
@@ -101,6 +104,7 @@ public class GeofroggerController implements Initializable {
private SessionContext sessionContext;
private final LoadCachesFromFileService loadService = new LoadCachesFromFileService();
private final LoadCachesFromDatabaseService loadFromDBService = new LoadCachesFromDatabaseService();
+ private final LoadCacheListsFromDatabaseService loadListsFromDBService = new LoadCacheListsFromDatabaseService();
@Inject
private GPXReader gpxReader;
@@ -120,6 +124,13 @@ public class GeofroggerController implements Initializable {
@FXML
private Menu pluginsMenu;
+ @FXML
+ private BorderPane mainPane;
+
+ @FXML
+ private SplitPane contentPane;
+
+
/**
* Initializes the controller class.
*
@@ -138,6 +149,7 @@ public class GeofroggerController implements Initializable {
gpxReader.addListener((ProgressEvent event) -> updateStatus(event.getMessage(), event.getProgress()));
cacheService.addListener((ProgressEvent event) -> updateStatus(event.getMessage(), event.getProgress()));
+ loadListsFromDBService.start();
loadFromDBService.start();
}
@@ -164,6 +176,13 @@ public class GeofroggerController implements Initializable {
dialog.show();
}
+ @FXML
+ public void showSettings(ActionEvent actionEvent) {
+// mainPane.setCenter();
+
+// FXMLLoader.load()
+ }
+
@FXML
public void exit(ActionEvent actionEvent) {
Platform.exit();
@@ -176,6 +195,25 @@ public class GeofroggerController implements Initializable {
});
}
+
+ private class LoadCacheListsFromDatabaseService extends Service {
+
+ @Override
+ protected Task createTask() {
+ return new Task() {
+ @Override
+ protected Void call() throws Exception {
+ updateStatus("Load cache lists from database.", ProgressIndicator.INDETERMINATE_PROGRESS);
+ sessionContext.setData("cache-lists", cacheService.getAllCacheLists());
+ updateStatus("All cache lists loaded.", 0);
+ return null;
+ }
+ };
+ }
+
+ }
+
+
private class LoadCachesFromDatabaseService extends Service {
@Override
diff --git a/src/de/geofroggerfx/fx/geofrogger/geofrogger.fxml b/src/de/geofroggerfx/fx/geofrogger/geofrogger.fxml
index be979ec..875c733 100644
--- a/src/de/geofroggerfx/fx/geofrogger/geofrogger.fxml
+++ b/src/de/geofroggerfx/fx/geofrogger/geofrogger.fxml
@@ -21,22 +21,27 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/de/geofroggerfx/fx/geofrogger_de.properties b/src/de/geofroggerfx/fx/geofrogger_de.properties
index 6e431ce..e8ba97a 100644
--- a/src/de/geofroggerfx/fx/geofrogger_de.properties
+++ b/src/de/geofroggerfx/fx/geofrogger_de.properties
@@ -2,6 +2,7 @@ menu.title.import.gpx = Importiere GPX
menu.title.file = Datei
menu.title.quit = Beenden
menu.title.help = Hilfe
+menu.title.settings = Einstellungen
menu.title.about = \u00dcber GeoFroggerFX
menu.title.plugins = Plugins
diff --git a/src/de/geofroggerfx/fx/geofrogger_en.properties b/src/de/geofroggerfx/fx/geofrogger_en.properties
index 21cb68a..b6adbc4 100644
--- a/src/de/geofroggerfx/fx/geofrogger_en.properties
+++ b/src/de/geofroggerfx/fx/geofrogger_en.properties
@@ -2,6 +2,7 @@ menu.title.import.gpx = Import GPX
menu.title.file = File
menu.title.quit = Quit
menu.title.help = Help
+menu.title.settings = Settings
menu.title.about = About GeoFroggerFX
menu.title.plugins = Plugins
diff --git a/src/de/geofroggerfx/fx/settings/SettingsController.java b/src/de/geofroggerfx/fx/settings/SettingsController.java
new file mode 100644
index 0000000..2f65963
--- /dev/null
+++ b/src/de/geofroggerfx/fx/settings/SettingsController.java
@@ -0,0 +1,7 @@
+package de.geofroggerfx.fx.settings;
+
+/**
+ * TODO: change this
+ */
+public class SettingsController {
+}
diff --git a/src/de/geofroggerfx/fx/settings/settings.fxml b/src/de/geofroggerfx/fx/settings/settings.fxml
index e69de29..1724407 100644
--- a/src/de/geofroggerfx/fx/settings/settings.fxml
+++ b/src/de/geofroggerfx/fx/settings/settings.fxml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/de/geofroggerfx/model/Cache.java b/src/de/geofroggerfx/model/Cache.java
index 7165121..29020d9 100644
--- a/src/de/geofroggerfx/model/Cache.java
+++ b/src/de/geofroggerfx/model/Cache.java
@@ -240,6 +240,23 @@ public class Cache {
this.found = found;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Cache cache = (Cache) o;
+
+ if (id != null ? !id.equals(cache.id) : cache.id != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return id != null ? id.hashCode() : 0;
+ }
+
@Override
public String toString() {
return "Cache{"
diff --git a/src/de/geofroggerfx/model/CacheList.java b/src/de/geofroggerfx/model/CacheList.java
new file mode 100644
index 0000000..5dd6b9c
--- /dev/null
+++ b/src/de/geofroggerfx/model/CacheList.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2014, 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.model;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import java.util.List;
+
+/**
+ * @author Andreas Billmann
+ */
+@Entity
+public class CacheList {
+
+ @Id
+ private String name;
+
+ private List caches;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @OneToMany(fetch= FetchType.LAZY)
+ public List getCaches() {
+ return caches;
+ }
+
+ public void setCaches(List caches) {
+ this.caches = caches;
+ }
+
+ public void addCache(Cache cache) {
+ if (!getCaches().contains(cache)) {
+ getCaches().add(cache);
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ CacheList cacheList = (CacheList) o;
+
+ if (!name.equals(cacheList.name)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "CacheList{" +
+ "name='" + name + '\'' +
+ '}';
+ }
+}
diff --git a/src/de/geofroggerfx/service/CacheService.java b/src/de/geofroggerfx/service/CacheService.java
index 20181bc..300ec1c 100644
--- a/src/de/geofroggerfx/service/CacheService.java
+++ b/src/de/geofroggerfx/service/CacheService.java
@@ -27,6 +27,7 @@ package de.geofroggerfx.service;
import de.geofroggerfx.application.ProgressListener;
import de.geofroggerfx.model.Cache;
+import de.geofroggerfx.model.CacheList;
import javax.inject.Singleton;
import java.util.List;
@@ -35,9 +36,36 @@ import java.util.List;
* @author Andreas
*/
public interface CacheService {
+
+ /**
+ * Store the whole list of caches
+ * @param caches list of caches
+ */
void storeCaches(List caches);
+ /**
+ * Receive all caches from the database
+ * @param sortField sort the list based on the field
+ * @param direction sort direction (ASC/DESC)
+ * @return sorted list of caches
+ */
List getAllCaches(CacheSortField sortField, SortDirection direction);
+ /**
+ * Add a ProgressListener to inform about loading/storing progress.
+ * @param listener progress listener
+ */
void addListener(ProgressListener listener);
+
+ /**
+ * Receive all cache lists
+ * @return list of available cachelists
+ */
+ List getAllCacheLists();
+
+ /**
+ * Stores a cache list
+ * @param list list of caches
+ */
+ void storeCacheList(CacheList list);
}
diff --git a/src/de/geofroggerfx/service/CacheServiceImpl.java b/src/de/geofroggerfx/service/CacheServiceImpl.java
index 32eb7bb..5940efe 100644
--- a/src/de/geofroggerfx/service/CacheServiceImpl.java
+++ b/src/de/geofroggerfx/service/CacheServiceImpl.java
@@ -7,10 +7,7 @@ package de.geofroggerfx.service;
import de.geofroggerfx.application.ProgressEvent;
import de.geofroggerfx.application.ProgressListener;
-import de.geofroggerfx.model.Attribute;
-import de.geofroggerfx.model.Cache;
-import de.geofroggerfx.model.Log;
-import de.geofroggerfx.model.TravelBug;
+import de.geofroggerfx.model.*;
import de.geofroggerfx.sql.DatabaseService;
import javax.inject.Inject;
@@ -99,6 +96,7 @@ public class CacheServiceImpl implements CacheService {
public List getAllCaches(CacheSortField sortField, SortDirection direction) {
List caches = new ArrayList<>();
+
try {
EntityManager em = dbService.getEntityManager();
String query = "select c from Cache c order by c."+sortField.getFieldName()+" "+direction.toString();
@@ -117,6 +115,39 @@ public class CacheServiceImpl implements CacheService {
listeners.stream().forEach((l) -> l.progress(event));
}
+ /**
+ * Receive all cache lists
+ */
+ @Override
+ public List getAllCacheLists() {
+ List lists = new ArrayList<>();
+ try {
+ EntityManager em = dbService.getEntityManager();
+ String query = "select l from CacheList l order by l.name";
+ List result = em.createQuery(query).getResultList();
+ if (result != null) {
+ lists = result;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return lists;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void storeCacheList(CacheList list) {
+ EntityManager em = dbService.getEntityManager();
+ try {
+ em.getTransaction().begin();
+ em.persist(list);
+ em.getTransaction().commit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ em.getTransaction().rollback();
+ }
+ }
}