resourcebundle and session constants
This commit is contained in:
35
src/de/geofroggerfx/application/SessionConstants.java
Normal file
35
src/de/geofroggerfx/application/SessionConstants.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Andreas Billmann <abi@geofroggerfx.de>
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andreas Billmann
|
||||||
|
*/
|
||||||
|
public class SessionConstants {
|
||||||
|
public static final String CURRENT_CACHE = "current-cache";
|
||||||
|
public static final String CACHE_LIST = "cache-list";
|
||||||
|
public static final String CACHE_LISTS = "cache-lists";
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.geofroggerfx.fx.cachedetails;
|
package de.geofroggerfx.fx.cachedetails;
|
||||||
|
|
||||||
|
import de.geofroggerfx.application.SessionConstants;
|
||||||
import de.geofroggerfx.application.SessionContext;
|
import de.geofroggerfx.application.SessionContext;
|
||||||
import de.geofroggerfx.application.SessionContextListener;
|
import de.geofroggerfx.application.SessionContextListener;
|
||||||
import de.geofroggerfx.fx.components.MapPaneWrapper;
|
import de.geofroggerfx.fx.components.MapPaneWrapper;
|
||||||
@@ -56,6 +57,9 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import static de.geofroggerfx.application.SessionConstants.CACHE_LISTS;
|
||||||
|
import static de.geofroggerfx.application.SessionConstants.CURRENT_CACHE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FXML Controller class
|
* FXML Controller class
|
||||||
*
|
*
|
||||||
@@ -137,7 +141,7 @@ public class CacheDetailsController implements Initializable, SessionContextList
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sessionContextChanged() {
|
public void sessionContextChanged() {
|
||||||
Cache currentCache = (Cache) sessionContext.getData("current-cache");
|
Cache currentCache = (Cache) sessionContext.getData(CURRENT_CACHE);
|
||||||
if (currentCache != null) {
|
if (currentCache != null) {
|
||||||
fillForm(currentCache);
|
fillForm(currentCache);
|
||||||
fadeIn();
|
fadeIn();
|
||||||
@@ -154,13 +158,13 @@ public class CacheDetailsController implements Initializable, SessionContextList
|
|||||||
|
|
||||||
|
|
||||||
private void setSessionListener() {
|
private void setSessionListener() {
|
||||||
sessionContext.addListener("current-cache", this);
|
sessionContext.addListener(CURRENT_CACHE, this);
|
||||||
sessionContext.addListener("cache-lists", () -> Platform.runLater(this::refreshCacheListMenu));
|
sessionContext.addListener(CACHE_LISTS, () -> Platform.runLater(this::refreshCacheListMenu));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void refreshCacheListMenu() {
|
private void refreshCacheListMenu() {
|
||||||
List<CacheList> cacheLists = (List<CacheList>) sessionContext.getData("cache-lists");
|
List<CacheList> cacheLists = (List<CacheList>) sessionContext.getData(CACHE_LISTS);
|
||||||
addToListMenuButton.getItems().clear();
|
addToListMenuButton.getItems().clear();
|
||||||
cacheLists.stream().forEach(this::addToListMenuItem);
|
cacheLists.stream().forEach(this::addToListMenuItem);
|
||||||
}
|
}
|
||||||
@@ -173,7 +177,7 @@ public class CacheDetailsController implements Initializable, SessionContextList
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addCacheAction(CacheList cacheList) {
|
private void addCacheAction(CacheList cacheList) {
|
||||||
Cache currentCache = (Cache) sessionContext.getData("current-cache");
|
Cache currentCache = (Cache) sessionContext.getData(CURRENT_CACHE);
|
||||||
cacheList.addCache(currentCache);
|
cacheList.addCache(currentCache);
|
||||||
cacheService.storeCacheList(cacheList);
|
cacheService.storeCacheList(cacheList);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.geofroggerfx.fx.cachelist;
|
package de.geofroggerfx.fx.cachelist;
|
||||||
|
|
||||||
|
import de.geofroggerfx.application.SessionConstants;
|
||||||
import de.geofroggerfx.application.SessionContext;
|
import de.geofroggerfx.application.SessionContext;
|
||||||
import de.geofroggerfx.fx.components.CacheListCell;
|
import de.geofroggerfx.fx.components.CacheListCell;
|
||||||
import de.geofroggerfx.fx.components.IconManager;
|
import de.geofroggerfx.fx.components.IconManager;
|
||||||
@@ -48,6 +49,7 @@ import java.net.URL;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import static de.geofroggerfx.application.SessionConstants.*;
|
||||||
import static de.geofroggerfx.fx.utils.JavaFXUtils.addClasses;
|
import static de.geofroggerfx.fx.utils.JavaFXUtils.addClasses;
|
||||||
import static de.geofroggerfx.service.CacheSortField.*;
|
import static de.geofroggerfx.service.CacheSortField.*;
|
||||||
|
|
||||||
@@ -60,6 +62,8 @@ public class CacheListController implements Initializable {
|
|||||||
|
|
||||||
private static final String CACHE_LIST_ACTION_ICONS = "cache-list-action-icons";
|
private static final String CACHE_LIST_ACTION_ICONS = "cache-list-action-icons";
|
||||||
|
|
||||||
|
private ResourceBundle resourceBundle;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SessionContext sessionContext;
|
private SessionContext sessionContext;
|
||||||
|
|
||||||
@@ -89,16 +93,18 @@ public class CacheListController implements Initializable {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void initialize(URL url, ResourceBundle rb) {
|
public void initialize(URL url, ResourceBundle rb) {
|
||||||
|
this.resourceBundle = rb;
|
||||||
|
|
||||||
setSessionListener();
|
setSessionListener();
|
||||||
setCellFactory();
|
setCellFactory();
|
||||||
|
|
||||||
cacheListView.getSelectionModel().selectedItemProperty().addListener(
|
cacheListView.getSelectionModel().selectedItemProperty().addListener(
|
||||||
(ChangeListener<Cache>) (ObservableValue<? extends Cache> ov, Cache oldValue, Cache newValue) ->
|
(ChangeListener<Cache>) (ObservableValue<? extends Cache> ov, Cache oldValue, Cache newValue) ->
|
||||||
sessionContext.setData("current-cache", newValue)
|
sessionContext.setData(CURRENT_CACHE, newValue)
|
||||||
);
|
);
|
||||||
|
|
||||||
initCacheListComboBox();
|
initCacheListComboBox();
|
||||||
initListMenuButton(rb);
|
initListMenuButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -109,22 +115,22 @@ public class CacheListController implements Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setSessionListener() {
|
private void setSessionListener() {
|
||||||
sessionContext.addListener("cache-list", () -> Platform.runLater(this::resetCacheList));
|
sessionContext.addListener(CACHE_LIST, () -> Platform.runLater(this::resetCacheList));
|
||||||
sessionContext.addListener("cache-lists", () -> Platform.runLater(this::refreshCacheListComboAndSelectFirst));
|
sessionContext.addListener(CACHE_LISTS, () -> Platform.runLater(this::refreshCacheListComboAndSelectFirst));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void resetCacheList() {
|
private void resetCacheList() {
|
||||||
List<Cache> caches = (List<Cache>) sessionContext.getData("cache-list");
|
List<Cache> caches = (List<Cache>) sessionContext.getData(CACHE_LIST);
|
||||||
cacheNumber.setText(" " + caches.size());
|
cacheNumber.setText(" " + caches.size());
|
||||||
cacheListView.getItems().setAll(caches);
|
cacheListView.getItems().setAll(caches);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void refreshCacheListComboAndSelectFirst() {
|
private void refreshCacheListComboAndSelectFirst() {
|
||||||
List<CacheList> cacheLists = (List<CacheList>) sessionContext.getData("cache-lists");
|
List<CacheList> cacheLists = (List<CacheList>) sessionContext.getData(CACHE_LISTS);
|
||||||
cacheListComboBox.getItems().clear();
|
cacheListComboBox.getItems().clear();
|
||||||
cacheListComboBox.getItems().add("All caches");
|
cacheListComboBox.getItems().add(resourceBundle.getString("all.caches"));
|
||||||
cacheListComboBox.getItems().addAll(cacheLists);
|
cacheListComboBox.getItems().addAll(cacheLists);
|
||||||
cacheListComboBox.getSelectionModel().selectFirst();
|
cacheListComboBox.getSelectionModel().selectFirst();
|
||||||
}
|
}
|
||||||
@@ -139,42 +145,42 @@ public class CacheListController implements Initializable {
|
|||||||
|
|
||||||
private void cacheListSelectAction(Object selectedItem) {
|
private void cacheListSelectAction(Object selectedItem) {
|
||||||
if (selectedItem != null) {
|
if (selectedItem != null) {
|
||||||
if (selectedItem.equals("All caches")) {
|
if (selectedItem.equals(resourceBundle.getString("all.caches"))) {
|
||||||
loadAllCaches();
|
loadAllCaches();
|
||||||
} else{
|
} else{
|
||||||
CacheList cacheList = (CacheList)selectedItem;
|
CacheList cacheList = (CacheList)selectedItem;
|
||||||
sessionContext.setData("cache-list", cacheList.getCaches());
|
sessionContext.setData(CACHE_LIST, cacheList.getCaches());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cacheListComboBox.getSelectionModel().selectFirst();
|
cacheListComboBox.getSelectionModel().selectFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initListMenuButton(final ResourceBundle rb) {
|
private void initListMenuButton() {
|
||||||
addClasses(menuIcon, CACHE_LIST_ACTION_ICONS);
|
addClasses(menuIcon, CACHE_LIST_ACTION_ICONS);
|
||||||
menuIcon.setGraphic(new ImageView(IconManager.getIcon("iconmonstr-menu-icon.png", IconManager.IconSize.SMALL)));
|
menuIcon.setGraphic(new ImageView(IconManager.getIcon("iconmonstr-menu-icon.png", IconManager.IconSize.SMALL)));
|
||||||
menuIcon.getItems().addAll(createSortMenu(rb));
|
menuIcon.getItems().addAll(createSortMenu());
|
||||||
menuIcon.minHeightProperty().bind(cacheListComboBox.heightProperty());
|
menuIcon.minHeightProperty().bind(cacheListComboBox.heightProperty());
|
||||||
menuIcon.prefHeightProperty().bind(cacheListComboBox.heightProperty());
|
menuIcon.prefHeightProperty().bind(cacheListComboBox.heightProperty());
|
||||||
menuIcon.maxHeightProperty().bind(cacheListComboBox.heightProperty());
|
menuIcon.maxHeightProperty().bind(cacheListComboBox.heightProperty());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Menu createSortMenu(final ResourceBundle rb) {
|
private Menu createSortMenu() {
|
||||||
Menu sortMenu = new Menu(rb.getString("menu.title.sort"));
|
Menu sortMenu = new Menu(resourceBundle.getString("menu.title.sort"));
|
||||||
currentSortingButton = createSortButton(rb, NAME);
|
currentSortingButton = createSortButton(NAME);
|
||||||
currentSortingButton.setSelected(true);
|
currentSortingButton.setSelected(true);
|
||||||
sortMenu.getItems().addAll(
|
sortMenu.getItems().addAll(
|
||||||
currentSortingButton,
|
currentSortingButton,
|
||||||
createSortButton(rb, TYPE),
|
createSortButton(TYPE),
|
||||||
createSortButton(rb, DIFFICULTY),
|
createSortButton(DIFFICULTY),
|
||||||
createSortButton(rb, TERRAIN),
|
createSortButton(TERRAIN),
|
||||||
createSortButton(rb, OWNER),
|
createSortButton(OWNER),
|
||||||
createSortButton(rb, PLACEDBY));
|
createSortButton(PLACEDBY));
|
||||||
return sortMenu;
|
return sortMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SortingMenuItem createSortButton(final ResourceBundle rb, final CacheSortField field) {
|
private SortingMenuItem createSortButton(final CacheSortField field) {
|
||||||
SortingMenuItem button = new SortingMenuItem(rb.getString("sort.cache."+field.getFieldName()), field);
|
SortingMenuItem button = new SortingMenuItem(resourceBundle.getString("sort.cache."+field.getFieldName()), field);
|
||||||
button.setOnAction(actionEvent -> {
|
button.setOnAction(actionEvent -> {
|
||||||
|
|
||||||
// if there was another button selected, change the selection
|
// if there was another button selected, change the selection
|
||||||
@@ -190,8 +196,7 @@ public class CacheListController implements Initializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadAllCaches() {
|
private void loadAllCaches() {
|
||||||
sessionContext.setData("cache-list", cacheService.getAllCaches(currentSortingButton.getField(), currentSortingButton.getSortDirection()));
|
sessionContext.setData(CACHE_LIST, cacheService.getAllCaches(currentSortingButton.getField(), currentSortingButton.getSortDirection()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
package de.geofroggerfx.fx.geofrogger;
|
package de.geofroggerfx.fx.geofrogger;
|
||||||
|
|
||||||
import de.geofroggerfx.application.ProgressEvent;
|
import de.geofroggerfx.application.ProgressEvent;
|
||||||
|
import de.geofroggerfx.application.SessionConstants;
|
||||||
import de.geofroggerfx.application.SessionContext;
|
import de.geofroggerfx.application.SessionContext;
|
||||||
import de.geofroggerfx.gpx.GPXReader;
|
import de.geofroggerfx.gpx.GPXReader;
|
||||||
import de.geofroggerfx.model.Cache;
|
import de.geofroggerfx.model.Cache;
|
||||||
@@ -58,8 +59,11 @@ import java.util.ResourceBundle;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static de.geofroggerfx.application.SessionConstants.CACHE_LIST;
|
||||||
|
import static de.geofroggerfx.application.SessionConstants.CACHE_LISTS;
|
||||||
import static de.geofroggerfx.service.CacheSortField.NAME;
|
import static de.geofroggerfx.service.CacheSortField.NAME;
|
||||||
import static de.geofroggerfx.service.SortDirection.ASC;
|
import static de.geofroggerfx.service.SortDirection.ASC;
|
||||||
|
import static java.util.logging.Level.SEVERE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FXML Controller class
|
* FXML Controller class
|
||||||
@@ -69,7 +73,7 @@ import static de.geofroggerfx.service.SortDirection.ASC;
|
|||||||
public class GeofroggerController implements Initializable {
|
public class GeofroggerController implements Initializable {
|
||||||
|
|
||||||
private static final String LICENSE = "/*\n" +
|
private static final String LICENSE = "/*\n" +
|
||||||
" * Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>\n" +
|
" * Copyright (c) 2013-2014, Andreas Billmann <abi@geofroggerfx.de>\n" +
|
||||||
" * All rights reserved.\n" +
|
" * All rights reserved.\n" +
|
||||||
" *\n" +
|
" *\n" +
|
||||||
" * Redistribution and use in source and binary forms, with or without\n" +
|
" * Redistribution and use in source and binary forms, with or without\n" +
|
||||||
@@ -97,7 +101,7 @@ public class GeofroggerController implements Initializable {
|
|||||||
private static final String MASTHEAD_TEXT = "GeoFroggerFX by Andreas Billmann <abi@geofroggerfx.de>";
|
private static final String MASTHEAD_TEXT = "GeoFroggerFX by Andreas Billmann <abi@geofroggerfx.de>";
|
||||||
private static final String ABOUT_TEXT = "Used libs:\n"
|
private static final String ABOUT_TEXT = "Used libs:\n"
|
||||||
+ "\t- JFXtras 8.0 r1\n"
|
+ "\t- JFXtras 8.0 r1\n"
|
||||||
+ "\t- ControlsFX 8.0.2 developer preview 1\n"
|
+ "\t- ControlsFX 8.0.6\n"
|
||||||
+ "\t- jdom 2.x\n"
|
+ "\t- jdom 2.x\n"
|
||||||
+ "\t- H2 1.3.173\n"
|
+ "\t- H2 1.3.173\n"
|
||||||
+ "\t- Icons by http://iconmonstr.com/\n";
|
+ "\t- Icons by http://iconmonstr.com/\n";
|
||||||
@@ -107,6 +111,7 @@ public class GeofroggerController implements Initializable {
|
|||||||
private final LoadCachesFromFileService loadService = new LoadCachesFromFileService();
|
private final LoadCachesFromFileService loadService = new LoadCachesFromFileService();
|
||||||
private final LoadCachesFromDatabaseService loadFromDBService = new LoadCachesFromDatabaseService();
|
private final LoadCachesFromDatabaseService loadFromDBService = new LoadCachesFromDatabaseService();
|
||||||
private final LoadCacheListsFromDatabaseService loadListsFromDBService = new LoadCacheListsFromDatabaseService();
|
private final LoadCacheListsFromDatabaseService loadListsFromDBService = new LoadCacheListsFromDatabaseService();
|
||||||
|
private ResourceBundle resourceBundle;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private GPXReader gpxReader;
|
private GPXReader gpxReader;
|
||||||
@@ -142,6 +147,8 @@ public class GeofroggerController implements Initializable {
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb) {
|
public void initialize(URL url, ResourceBundle rb) {
|
||||||
|
|
||||||
|
resourceBundle = rb;
|
||||||
|
|
||||||
List<Plugin> plugins = pluginService.getAllPlugins();
|
List<Plugin> plugins = pluginService.getAllPlugins();
|
||||||
for (Plugin plugin: plugins) {
|
for (Plugin plugin: plugins) {
|
||||||
MenuItem menuItem = new MenuItem(plugin.getName()+" ("+plugin.getVersion()+")");
|
MenuItem menuItem = new MenuItem(plugin.getName()+" ("+plugin.getVersion()+")");
|
||||||
@@ -171,7 +178,7 @@ public class GeofroggerController implements Initializable {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void showAboutDialog(ActionEvent actionEvent) {
|
public void showAboutDialog(ActionEvent actionEvent) {
|
||||||
Dialog dialog = new Dialog(null, "About");
|
Dialog dialog = new Dialog(null, resourceBundle.getString("dialog.title.about"));
|
||||||
dialog.setMasthead(MASTHEAD_TEXT);
|
dialog.setMasthead(MASTHEAD_TEXT);
|
||||||
dialog.setContent(ABOUT_TEXT);
|
dialog.setContent(ABOUT_TEXT);
|
||||||
dialog.setExpandableContent(new TextArea(LICENSE));
|
dialog.setExpandableContent(new TextArea(LICENSE));
|
||||||
@@ -189,34 +196,36 @@ public class GeofroggerController implements Initializable {
|
|||||||
public void newList(ActionEvent actionEvent) {
|
public void newList(ActionEvent actionEvent) {
|
||||||
final Optional<String> listNameOption = Dialogs.
|
final Optional<String> listNameOption = Dialogs.
|
||||||
create().
|
create().
|
||||||
title("New list").
|
title(resourceBundle.getString("dialog.title.new_list")).
|
||||||
message("List name").
|
message(resourceBundle.getString("dialog.label.listname")).
|
||||||
showTextInput();
|
showTextInput();
|
||||||
if (hasValue(listNameOption)) {
|
if (hasValue(listNameOption)) {
|
||||||
final String listName = listNameOption.get().trim();
|
final String listName = listNameOption.get().trim();
|
||||||
if (cacheService.doesCacheListNameExist(listName)) {
|
if (cacheService.doesCacheListNameExist(listName)) {
|
||||||
Dialogs.create().message("List does already exist!").showError();
|
Dialogs.
|
||||||
|
create().
|
||||||
|
message(resourceBundle.getString("dialog.msg.list.does.exist")).
|
||||||
|
showError();
|
||||||
} else {
|
} else {
|
||||||
CacheList list = new CacheList();
|
CacheList list = new CacheList();
|
||||||
list.setName(listName);
|
list.setName(listName);
|
||||||
cacheService.storeCacheList(list);
|
cacheService.storeCacheList(list);
|
||||||
sessionContext.setData("cache-lists", cacheService.getAllCacheLists());
|
setCacheListInContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void deleteList(ActionEvent actionEvent) {
|
public void deleteList(ActionEvent actionEvent) {
|
||||||
final Optional<CacheList> listOption = Dialogs.
|
final Optional<CacheList> listOption = Dialogs.
|
||||||
create().
|
create().
|
||||||
title("Delete list").
|
title("dialog.title.delete_list").
|
||||||
message("List name").
|
message("dialog.label.listname").
|
||||||
showChoices(cacheService.getAllCacheLists());
|
showChoices(cacheService.getAllCacheLists());
|
||||||
|
|
||||||
if (listOption.isPresent()) {
|
if (listOption.isPresent()) {
|
||||||
cacheService.deleteCacheList(listOption.get());
|
cacheService.deleteCacheList(listOption.get());
|
||||||
sessionContext.setData("cache-lists", cacheService.getAllCacheLists());
|
setCacheListInContext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +234,10 @@ public class GeofroggerController implements Initializable {
|
|||||||
Platform.exit();
|
Platform.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setCacheListInContext() {
|
||||||
|
sessionContext.setData(CACHE_LISTS, cacheService.getAllCacheLists());
|
||||||
|
}
|
||||||
|
|
||||||
private void updateStatus(String text, double progressValue) {
|
private void updateStatus(String text, double progressValue) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
leftStatus.setText(text);
|
leftStatus.setText(text);
|
||||||
@@ -243,9 +256,9 @@ public class GeofroggerController implements Initializable {
|
|||||||
return new Task() {
|
return new Task() {
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
updateStatus("Load cache lists from database.", ProgressIndicator.INDETERMINATE_PROGRESS);
|
updateStatus(resourceBundle.getString("status.load.all.caches.from.db"), ProgressIndicator.INDETERMINATE_PROGRESS);
|
||||||
sessionContext.setData("cache-lists", cacheService.getAllCacheLists());
|
sessionContext.setData(CACHE_LISTS, cacheService.getAllCacheLists());
|
||||||
updateStatus("All cache lists loaded.", 0);
|
updateStatus(resourceBundle.getString("status.all.cache.lists.loaded"), 0);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -261,9 +274,9 @@ public class GeofroggerController implements Initializable {
|
|||||||
return new Task() {
|
return new Task() {
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
updateStatus("Load caches from database.", ProgressIndicator.INDETERMINATE_PROGRESS);
|
updateStatus(resourceBundle.getString("status.load.caches.from.db"), ProgressIndicator.INDETERMINATE_PROGRESS);
|
||||||
sessionContext.setData("cache-list", cacheService.getAllCaches(NAME, ASC));
|
sessionContext.setData(CACHE_LIST, cacheService.getAllCaches(NAME, ASC));
|
||||||
updateStatus("All caches loaded.", 0);
|
updateStatus(resourceBundle.getString("status.all.caches.loaded"), 0);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -296,16 +309,16 @@ public class GeofroggerController implements Initializable {
|
|||||||
final List<Cache> cacheList = gpxReader.load(file.get().getAbsolutePath());
|
final List<Cache> cacheList = gpxReader.load(file.get().getAbsolutePath());
|
||||||
if (cacheList != null && !cacheList.isEmpty()) {
|
if (cacheList != null && !cacheList.isEmpty()) {
|
||||||
|
|
||||||
updateStatus("Store caches in database", ProgressIndicator.INDETERMINATE_PROGRESS);
|
updateStatus(resourceBundle.getString("status.store.all.caches"), ProgressIndicator.INDETERMINATE_PROGRESS);
|
||||||
cacheService.storeCaches(cacheList);
|
cacheService.storeCaches(cacheList);
|
||||||
updateStatus("All caches are stored in database", 0);
|
updateStatus(resourceBundle.getString("status.all.caches.stored"), 0);
|
||||||
|
|
||||||
updateStatus("Load caches from database.", ProgressIndicator.INDETERMINATE_PROGRESS);
|
updateStatus(resourceBundle.getString("status.load.caches.from.db"), ProgressIndicator.INDETERMINATE_PROGRESS);
|
||||||
sessionContext.setData("cache-list", cacheService.getAllCaches(NAME, ASC));
|
sessionContext.setData(CACHE_LIST, cacheService.getAllCaches(NAME, ASC));
|
||||||
updateStatus("All caches loaded.", 0);
|
updateStatus(resourceBundle.getString("status.all.caches.loaded"), 0);
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(GeofroggerController.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(GeofroggerController.class.getName()).log(SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,3 +35,18 @@ sort.cache.difficulty = Schwierigkeitsgrad
|
|||||||
sort.cache.terrain = Gel\u00E4nde
|
sort.cache.terrain = Gel\u00E4nde
|
||||||
sort.cache.placedBy = Platziert von
|
sort.cache.placedBy = Platziert von
|
||||||
sort.cache.owner = Betreut von
|
sort.cache.owner = Betreut von
|
||||||
|
|
||||||
|
dialog.title.about = Über
|
||||||
|
dialog.title.new_list = Neue Liste
|
||||||
|
dialog.label.listname = Name der Liste:
|
||||||
|
dialog.msg.list.does.exist = Diese Liste existiert schon!
|
||||||
|
dialog.title.delete_list = Liste löschen
|
||||||
|
|
||||||
|
all.caches = Alle Caches
|
||||||
|
|
||||||
|
status.load.all.caches.from.db = Lade alle Caches von der Datenbank.
|
||||||
|
status.all.cache.lists.loaded = Alle Listen geladen.
|
||||||
|
status.load.caches.from.db = Lade Caches von der Datenbank.
|
||||||
|
status.all.caches.loaded = Alle Caches geladen.
|
||||||
|
status.store.all.caches = Speichere Caches in Datenbank.
|
||||||
|
status.all.caches.stored = Alle Caches in der Datenbank gespeichert.
|
||||||
@@ -36,3 +36,18 @@ sort.cache.difficulty = Difficulty
|
|||||||
sort.cache.terrain = Terrain
|
sort.cache.terrain = Terrain
|
||||||
sort.cache.placedBy = Placed by
|
sort.cache.placedBy = Placed by
|
||||||
sort.cache.owner = Owner
|
sort.cache.owner = Owner
|
||||||
|
|
||||||
|
dialog.title.about = About
|
||||||
|
dialog.title.new_list = New list
|
||||||
|
dialog.label.listname = Name of list:
|
||||||
|
dialog.msg.list.does.exist = List does already exist!
|
||||||
|
dialog.title.delete_list = Delete list
|
||||||
|
|
||||||
|
all.caches = All caches
|
||||||
|
|
||||||
|
status.load.all.caches.from.db = Load cache lists from database.
|
||||||
|
status.all.cache.lists.loaded = All cache lists loaded.
|
||||||
|
status.load.caches.from.db = Load caches from database.
|
||||||
|
status.all.caches.loaded = All caches loaded.
|
||||||
|
status.store.all.caches = Store caches in database.
|
||||||
|
status.all.caches.stored = All caches are stored in database.
|
||||||
@@ -170,7 +170,7 @@ public class CacheServiceImpl implements CacheService {
|
|||||||
EntityManager em = dbService.getEntityManager();
|
EntityManager em = dbService.getEntityManager();
|
||||||
try {
|
try {
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
em.persist(list);
|
em.merge(list);
|
||||||
em.getTransaction().commit();
|
em.getTransaction().commit();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
Reference in New Issue
Block a user