diff --git a/src/de/geofroggerfx/application/SessionConstants.java b/src/de/geofroggerfx/application/SessionConstants.java new file mode 100644 index 0000000..682cbef --- /dev/null +++ b/src/de/geofroggerfx/application/SessionConstants.java @@ -0,0 +1,35 @@ +/* + * 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.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"; +} diff --git a/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java b/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java index 67f8a6c..e0c8ce0 100644 --- a/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java +++ b/src/de/geofroggerfx/fx/cachedetails/CacheDetailsController.java @@ -25,6 +25,7 @@ */ package de.geofroggerfx.fx.cachedetails; +import de.geofroggerfx.application.SessionConstants; import de.geofroggerfx.application.SessionContext; import de.geofroggerfx.application.SessionContextListener; import de.geofroggerfx.fx.components.MapPaneWrapper; @@ -56,6 +57,9 @@ import java.util.Arrays; import java.util.List; import java.util.ResourceBundle; +import static de.geofroggerfx.application.SessionConstants.CACHE_LISTS; +import static de.geofroggerfx.application.SessionConstants.CURRENT_CACHE; + /** * FXML Controller class * @@ -137,7 +141,7 @@ public class CacheDetailsController implements Initializable, SessionContextList @Override public void sessionContextChanged() { - Cache currentCache = (Cache) sessionContext.getData("current-cache"); + Cache currentCache = (Cache) sessionContext.getData(CURRENT_CACHE); if (currentCache != null) { fillForm(currentCache); fadeIn(); @@ -154,13 +158,13 @@ public class CacheDetailsController implements Initializable, SessionContextList private void setSessionListener() { - sessionContext.addListener("current-cache", this); - sessionContext.addListener("cache-lists", () -> Platform.runLater(this::refreshCacheListMenu)); + 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"); + List cacheLists = (List) sessionContext.getData(CACHE_LISTS); addToListMenuButton.getItems().clear(); cacheLists.stream().forEach(this::addToListMenuItem); } @@ -173,7 +177,7 @@ public class CacheDetailsController implements Initializable, SessionContextList } private void addCacheAction(CacheList cacheList) { - Cache currentCache = (Cache) sessionContext.getData("current-cache"); + Cache currentCache = (Cache) sessionContext.getData(CURRENT_CACHE); cacheList.addCache(currentCache); cacheService.storeCacheList(cacheList); } diff --git a/src/de/geofroggerfx/fx/cachelist/CacheListController.java b/src/de/geofroggerfx/fx/cachelist/CacheListController.java index fa768c1..341110c 100644 --- a/src/de/geofroggerfx/fx/cachelist/CacheListController.java +++ b/src/de/geofroggerfx/fx/cachelist/CacheListController.java @@ -25,6 +25,7 @@ */ package de.geofroggerfx.fx.cachelist; +import de.geofroggerfx.application.SessionConstants; import de.geofroggerfx.application.SessionContext; import de.geofroggerfx.fx.components.CacheListCell; import de.geofroggerfx.fx.components.IconManager; @@ -48,6 +49,7 @@ import java.net.URL; import java.util.List; import java.util.ResourceBundle; +import static de.geofroggerfx.application.SessionConstants.*; import static de.geofroggerfx.fx.utils.JavaFXUtils.addClasses; 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 ResourceBundle resourceBundle; + @Inject private SessionContext sessionContext; @@ -89,16 +93,18 @@ public class CacheListController implements Initializable { @Override @SuppressWarnings("unchecked") public void initialize(URL url, ResourceBundle rb) { + this.resourceBundle = rb; + setSessionListener(); setCellFactory(); cacheListView.getSelectionModel().selectedItemProperty().addListener( (ChangeListener) (ObservableValue ov, Cache oldValue, Cache newValue) -> - sessionContext.setData("current-cache", newValue) + sessionContext.setData(CURRENT_CACHE, newValue) ); initCacheListComboBox(); - initListMenuButton(rb); + initListMenuButton(); } @SuppressWarnings("unchecked") @@ -109,22 +115,22 @@ public class CacheListController implements Initializable { } private void setSessionListener() { - sessionContext.addListener("cache-list", () -> Platform.runLater(this::resetCacheList)); - sessionContext.addListener("cache-lists", () -> Platform.runLater(this::refreshCacheListComboAndSelectFirst)); + 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"); + 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"); + List cacheLists = (List) sessionContext.getData(CACHE_LISTS); cacheListComboBox.getItems().clear(); - cacheListComboBox.getItems().add("All caches"); + cacheListComboBox.getItems().add(resourceBundle.getString("all.caches")); cacheListComboBox.getItems().addAll(cacheLists); cacheListComboBox.getSelectionModel().selectFirst(); } @@ -139,42 +145,42 @@ public class CacheListController implements Initializable { private void cacheListSelectAction(Object selectedItem) { if (selectedItem != null) { - if (selectedItem.equals("All caches")) { + if (selectedItem.equals(resourceBundle.getString("all.caches"))) { loadAllCaches(); } else{ CacheList cacheList = (CacheList)selectedItem; - sessionContext.setData("cache-list", cacheList.getCaches()); + sessionContext.setData(CACHE_LIST, cacheList.getCaches()); } } else { cacheListComboBox.getSelectionModel().selectFirst(); } } - private void initListMenuButton(final ResourceBundle rb) { + private void initListMenuButton() { addClasses(menuIcon, CACHE_LIST_ACTION_ICONS); 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.prefHeightProperty().bind(cacheListComboBox.heightProperty()); menuIcon.maxHeightProperty().bind(cacheListComboBox.heightProperty()); } - private Menu createSortMenu(final ResourceBundle rb) { - Menu sortMenu = new Menu(rb.getString("menu.title.sort")); - currentSortingButton = createSortButton(rb, NAME); + private Menu createSortMenu() { + Menu sortMenu = new Menu(resourceBundle.getString("menu.title.sort")); + currentSortingButton = createSortButton(NAME); currentSortingButton.setSelected(true); sortMenu.getItems().addAll( currentSortingButton, - createSortButton(rb, TYPE), - createSortButton(rb, DIFFICULTY), - createSortButton(rb, TERRAIN), - createSortButton(rb, OWNER), - createSortButton(rb, PLACEDBY)); + createSortButton(TYPE), + createSortButton(DIFFICULTY), + createSortButton(TERRAIN), + createSortButton(OWNER), + createSortButton(PLACEDBY)); return sortMenu; } - private SortingMenuItem createSortButton(final ResourceBundle rb, final CacheSortField field) { - SortingMenuItem button = new SortingMenuItem(rb.getString("sort.cache."+field.getFieldName()), field); + private SortingMenuItem createSortButton(final CacheSortField field) { + SortingMenuItem button = new SortingMenuItem(resourceBundle.getString("sort.cache."+field.getFieldName()), field); button.setOnAction(actionEvent -> { // if there was another button selected, change the selection @@ -190,8 +196,7 @@ public class CacheListController implements Initializable { } private void loadAllCaches() { - sessionContext.setData("cache-list", cacheService.getAllCaches(currentSortingButton.getField(), currentSortingButton.getSortDirection())); + sessionContext.setData(CACHE_LIST, cacheService.getAllCaches(currentSortingButton.getField(), currentSortingButton.getSortDirection())); } - } diff --git a/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java b/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java index 2d28acd..70379bb 100644 --- a/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java +++ b/src/de/geofroggerfx/fx/geofrogger/GeofroggerController.java @@ -26,6 +26,7 @@ package de.geofroggerfx.fx.geofrogger; import de.geofroggerfx.application.ProgressEvent; +import de.geofroggerfx.application.SessionConstants; import de.geofroggerfx.application.SessionContext; import de.geofroggerfx.gpx.GPXReader; import de.geofroggerfx.model.Cache; @@ -58,8 +59,11 @@ import java.util.ResourceBundle; import java.util.logging.Level; 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.SortDirection.ASC; +import static java.util.logging.Level.SEVERE; /** * FXML Controller class @@ -69,7 +73,7 @@ import static de.geofroggerfx.service.SortDirection.ASC; public class GeofroggerController implements Initializable { private static final String LICENSE = "/*\n" + - " * Copyright (c) 2013, Andreas Billmann \n" + + " * Copyright (c) 2013-2014, Andreas Billmann \n" + " * All rights reserved.\n" + " *\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 "; private static final String ABOUT_TEXT = "Used libs:\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- H2 1.3.173\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 LoadCachesFromDatabaseService loadFromDBService = new LoadCachesFromDatabaseService(); private final LoadCacheListsFromDatabaseService loadListsFromDBService = new LoadCacheListsFromDatabaseService(); + private ResourceBundle resourceBundle; @Inject private GPXReader gpxReader; @@ -142,6 +147,8 @@ public class GeofroggerController implements Initializable { @Override public void initialize(URL url, ResourceBundle rb) { + resourceBundle = rb; + List plugins = pluginService.getAllPlugins(); for (Plugin plugin: plugins) { MenuItem menuItem = new MenuItem(plugin.getName()+" ("+plugin.getVersion()+")"); @@ -171,7 +178,7 @@ public class GeofroggerController implements Initializable { @FXML 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.setContent(ABOUT_TEXT); dialog.setExpandableContent(new TextArea(LICENSE)); @@ -189,34 +196,36 @@ public class GeofroggerController implements Initializable { public void newList(ActionEvent actionEvent) { final Optional listNameOption = Dialogs. create(). - title("New list"). - message("List name"). + title(resourceBundle.getString("dialog.title.new_list")). + message(resourceBundle.getString("dialog.label.listname")). showTextInput(); if (hasValue(listNameOption)) { final String listName = listNameOption.get().trim(); if (cacheService.doesCacheListNameExist(listName)) { - Dialogs.create().message("List does already exist!").showError(); + Dialogs. + create(). + message(resourceBundle.getString("dialog.msg.list.does.exist")). + showError(); } else { CacheList list = new CacheList(); list.setName(listName); cacheService.storeCacheList(list); - sessionContext.setData("cache-lists", cacheService.getAllCacheLists()); + setCacheListInContext(); } } } - @FXML public void deleteList(ActionEvent actionEvent) { final Optional listOption = Dialogs. create(). - title("Delete list"). - message("List name"). + title("dialog.title.delete_list"). + message("dialog.label.listname"). showChoices(cacheService.getAllCacheLists()); if (listOption.isPresent()) { cacheService.deleteCacheList(listOption.get()); - sessionContext.setData("cache-lists", cacheService.getAllCacheLists()); + setCacheListInContext(); } } @@ -225,6 +234,10 @@ public class GeofroggerController implements Initializable { Platform.exit(); } + private void setCacheListInContext() { + sessionContext.setData(CACHE_LISTS, cacheService.getAllCacheLists()); + } + private void updateStatus(String text, double progressValue) { Platform.runLater(() -> { leftStatus.setText(text); @@ -243,9 +256,9 @@ public class GeofroggerController implements Initializable { 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); + updateStatus(resourceBundle.getString("status.load.all.caches.from.db"), ProgressIndicator.INDETERMINATE_PROGRESS); + sessionContext.setData(CACHE_LISTS, cacheService.getAllCacheLists()); + updateStatus(resourceBundle.getString("status.all.cache.lists.loaded"), 0); return null; } }; @@ -261,9 +274,9 @@ public class GeofroggerController implements Initializable { return new Task() { @Override protected Void call() throws Exception { - updateStatus("Load caches from database.", ProgressIndicator.INDETERMINATE_PROGRESS); - sessionContext.setData("cache-list", cacheService.getAllCaches(NAME, ASC)); - updateStatus("All caches loaded.", 0); + updateStatus(resourceBundle.getString("status.load.caches.from.db"), ProgressIndicator.INDETERMINATE_PROGRESS); + sessionContext.setData(CACHE_LIST, cacheService.getAllCaches(NAME, ASC)); + updateStatus(resourceBundle.getString("status.all.caches.loaded"), 0); return null; } }; @@ -296,16 +309,16 @@ public class GeofroggerController implements Initializable { final List cacheList = gpxReader.load(file.get().getAbsolutePath()); 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); - updateStatus("All caches are stored in database", 0); + updateStatus(resourceBundle.getString("status.all.caches.stored"), 0); - updateStatus("Load caches from database.", ProgressIndicator.INDETERMINATE_PROGRESS); - sessionContext.setData("cache-list", cacheService.getAllCaches(NAME, ASC)); - updateStatus("All caches loaded.", 0); + updateStatus(resourceBundle.getString("status.load.caches.from.db"), ProgressIndicator.INDETERMINATE_PROGRESS); + sessionContext.setData(CACHE_LIST, cacheService.getAllCaches(NAME, ASC)); + updateStatus(resourceBundle.getString("status.all.caches.loaded"), 0); } } catch (IOException ex) { - Logger.getLogger(GeofroggerController.class.getName()).log(Level.SEVERE, null, ex); + Logger.getLogger(GeofroggerController.class.getName()).log(SEVERE, null, ex); } return null; } diff --git a/src/de/geofroggerfx/fx/geofrogger_de.properties b/src/de/geofroggerfx/fx/geofrogger_de.properties index b5f5327..abd2741 100644 --- a/src/de/geofroggerfx/fx/geofrogger_de.properties +++ b/src/de/geofroggerfx/fx/geofrogger_de.properties @@ -34,4 +34,19 @@ sort.cache.type = Art sort.cache.difficulty = Schwierigkeitsgrad sort.cache.terrain = Gel\u00E4nde sort.cache.placedBy = Platziert von -sort.cache.owner = Betreut von \ No newline at end of file +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. \ No newline at end of file diff --git a/src/de/geofroggerfx/fx/geofrogger_en.properties b/src/de/geofroggerfx/fx/geofrogger_en.properties index 5579b80..41802fb 100644 --- a/src/de/geofroggerfx/fx/geofrogger_en.properties +++ b/src/de/geofroggerfx/fx/geofrogger_en.properties @@ -35,4 +35,19 @@ sort.cache.type = Type sort.cache.difficulty = Difficulty sort.cache.terrain = Terrain sort.cache.placedBy = Placed by -sort.cache.owner = Owner \ No newline at end of file +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. \ No newline at end of file diff --git a/src/de/geofroggerfx/service/CacheServiceImpl.java b/src/de/geofroggerfx/service/CacheServiceImpl.java index 970d322..a94c433 100644 --- a/src/de/geofroggerfx/service/CacheServiceImpl.java +++ b/src/de/geofroggerfx/service/CacheServiceImpl.java @@ -170,7 +170,7 @@ public class CacheServiceImpl implements CacheService { EntityManager em = dbService.getEntityManager(); try { em.getTransaction().begin(); - em.persist(list); + em.merge(list); em.getTransaction().commit(); } catch (Exception e) { e.printStackTrace();