minimum list management implemented
This commit is contained in:
@@ -33,6 +33,7 @@ import javafx.scene.text.Font;
|
|||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.jboss.weld.environment.se.Weld;
|
import org.jboss.weld.environment.se.Weld;
|
||||||
import org.jboss.weld.environment.se.WeldContainer;
|
import org.jboss.weld.environment.se.WeldContainer;
|
||||||
|
import org.scenicview.ScenicView;
|
||||||
|
|
||||||
import javax.enterprise.util.AnnotationLiteral;
|
import javax.enterprise.util.AnnotationLiteral;
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import javafx.fxml.Initializable;
|
|||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
|
import org.scenicview.ScenicView;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -115,7 +116,7 @@ public class CacheListController implements Initializable {
|
|||||||
@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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +154,9 @@ public class CacheListController implements Initializable {
|
|||||||
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(rb));
|
||||||
|
menuIcon.minHeightProperty().bind(cacheListComboBox.heightProperty());
|
||||||
|
menuIcon.prefHeightProperty().bind(cacheListComboBox.heightProperty());
|
||||||
|
menuIcon.maxHeightProperty().bind(cacheListComboBox.heightProperty());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Menu createSortMenu(final ResourceBundle rb) {
|
private Menu createSortMenu(final ResourceBundle rb) {
|
||||||
|
|||||||
@@ -1,30 +1,43 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import java.net.*?>
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import javafx.scene.text.Font?>
|
|
||||||
<?import java.net.URL?>
|
<?import java.net.URL?>
|
||||||
<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="de.geofroggerfx.fx.cachelist.CacheListController">
|
|
||||||
|
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="de.geofroggerfx.fx.cachelist.CacheListController">
|
||||||
<children>
|
<children>
|
||||||
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="-1.0" styleClass="cache-header"
|
<HBox alignment="CENTER_LEFT" prefHeight="40.0" prefWidth="-1.0" styleClass="cache-header" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
|
||||||
<children>
|
<children>
|
||||||
<Label alignment="CENTER_LEFT" minWidth="60.0" prefWidth="-1.0" style=" " text="%label.text.cache.list"
|
<Label alignment="CENTER_LEFT" prefWidth="-1.0" style=" " text="%label.text.cache.list" textAlignment="LEFT" textFill="WHITE" wrapText="false">
|
||||||
textAlignment="LEFT" textFill="WHITE" wrapText="false">
|
<HBox.margin>
|
||||||
</Label>
|
<Insets right="10.0" />
|
||||||
<Label fx:id="cacheNumber" alignment="CENTER_LEFT" minWidth="60.0" prefWidth="-1.0" maxWidth="Infinity"
|
</HBox.margin></Label>
|
||||||
style=" " text="(0)" textAlignment="LEFT" textFill="WHITE" wrapText="false" HBox.hgrow="ALWAYS">
|
<ComboBox fx:id="cacheListComboBox" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" HBox.hgrow="ALWAYS">
|
||||||
</Label>
|
<HBox.margin>
|
||||||
<ComboBox fx:id="cacheListComboBox"/>
|
<Insets right="10.0" />
|
||||||
<MenuButton fx:id="menuIcon"/>
|
</HBox.margin></ComboBox>
|
||||||
|
<MenuButton fx:id="menuIcon" minHeight="16.0" />
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
<padding>
|
||||||
<Insets left="16.0" right="16.0" fx:id="x2"/>
|
<Insets left="16.0" right="16.0" />
|
||||||
|
</padding>
|
||||||
|
</HBox>
|
||||||
|
<ListView fx:id="cacheListView" prefHeight="507.0" prefWidth="221.0" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0" />
|
||||||
|
|
||||||
|
<HBox alignment="CENTER_LEFT" prefHeight="20.0" prefWidth="221.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||||
|
<children>
|
||||||
|
<Label alignment="CENTER_LEFT" minWidth="60.0" prefWidth="-1.0" style=" " text="%label.text.cache.list.count" textAlignment="LEFT" wrapText="false" />
|
||||||
|
<Label fx:id="cacheNumber" />
|
||||||
|
</children>
|
||||||
|
|
||||||
|
<padding>
|
||||||
|
<Insets left="16.0" right="16.0" />
|
||||||
</padding>
|
</padding>
|
||||||
</HBox>
|
</HBox>
|
||||||
<ListView fx:id="cacheListView" prefHeight="507.0" prefWidth="221.0" AnchorPane.bottomAnchor="0.0"
|
|
||||||
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="40.0"/>
|
|
||||||
</children>
|
</children>
|
||||||
<stylesheets>
|
<stylesheets>
|
||||||
<URL value="@/de/geofroggerfx/fx/geofrogger.css" />
|
<URL value="@/de/geofroggerfx/fx/geofrogger.css" />
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import de.geofroggerfx.application.ProgressEvent;
|
|||||||
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;
|
||||||
|
import de.geofroggerfx.model.CacheList;
|
||||||
import de.geofroggerfx.plugins.Plugin;
|
import de.geofroggerfx.plugins.Plugin;
|
||||||
import de.geofroggerfx.plugins.PluginService;
|
import de.geofroggerfx.plugins.PluginService;
|
||||||
import de.geofroggerfx.service.CacheService;
|
import de.geofroggerfx.service.CacheService;
|
||||||
@@ -39,19 +40,20 @@ import javafx.concurrent.Service;
|
|||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.Pane;
|
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import org.controlsfx.dialog.Dialog;
|
import org.controlsfx.dialog.Dialog;
|
||||||
|
import org.controlsfx.dialog.Dialogs;
|
||||||
|
import org.scenicview.ScenicView;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -183,6 +185,41 @@ public class GeofroggerController implements Initializable {
|
|||||||
// FXMLLoader.load()
|
// FXMLLoader.load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void newList(ActionEvent actionEvent) {
|
||||||
|
final Optional<String> listNameOption = Dialogs.
|
||||||
|
create().
|
||||||
|
title("New list").
|
||||||
|
message("List name").
|
||||||
|
showTextInput();
|
||||||
|
if (hasValue(listNameOption)) {
|
||||||
|
final String listName = listNameOption.get().trim();
|
||||||
|
if (cacheService.doesCacheListNameExist(listName)) {
|
||||||
|
Dialogs.create().message("List does already exist!").showError();
|
||||||
|
} else {
|
||||||
|
CacheList list = new CacheList();
|
||||||
|
list.setName(listName);
|
||||||
|
cacheService.storeCacheList(list);
|
||||||
|
sessionContext.setData("cache-lists", cacheService.getAllCacheLists());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void deleteList(ActionEvent actionEvent) {
|
||||||
|
final Optional<CacheList> listOption = Dialogs.
|
||||||
|
create().
|
||||||
|
title("Delete list").
|
||||||
|
message("List name").
|
||||||
|
showChoices(cacheService.getAllCacheLists());
|
||||||
|
|
||||||
|
if (listOption.isPresent()) {
|
||||||
|
cacheService.deleteCacheList(listOption.get());
|
||||||
|
sessionContext.setData("cache-lists", cacheService.getAllCacheLists());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void exit(ActionEvent actionEvent) {
|
public void exit(ActionEvent actionEvent) {
|
||||||
Platform.exit();
|
Platform.exit();
|
||||||
@@ -195,6 +232,9 @@ public class GeofroggerController implements Initializable {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasValue(Optional<String> listNameOption) {
|
||||||
|
return listNameOption.isPresent() && !listNameOption.get().trim().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private class LoadCacheListsFromDatabaseService extends Service {
|
private class LoadCacheListsFromDatabaseService extends Service {
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,12 @@
|
|||||||
<MenuItem mnemonicParsing="false" onAction="#exit" text="%menu.title.quit"/>
|
<MenuItem mnemonicParsing="false" onAction="#exit" text="%menu.title.quit"/>
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
<Menu mnemonicParsing="false" text="%menu.title.list">
|
||||||
|
<items>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#newList" text="%menu.title.list.new"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#deleteList" text="%menu.title.list.delete"/>
|
||||||
|
</items>
|
||||||
|
</Menu>
|
||||||
<Menu fx:id="pluginsMenu" mnemonicParsing="false" text="%menu.title.plugins"/>
|
<Menu fx:id="pluginsMenu" mnemonicParsing="false" text="%menu.title.plugins"/>
|
||||||
<Menu mnemonicParsing="false" text="%menu.title.help">
|
<Menu mnemonicParsing="false" text="%menu.title.help">
|
||||||
<items>
|
<items>
|
||||||
|
|||||||
@@ -5,11 +5,15 @@ menu.title.help = Hilfe
|
|||||||
menu.title.settings = Einstellungen
|
menu.title.settings = Einstellungen
|
||||||
menu.title.about = \u00dcber GeoFroggerFX
|
menu.title.about = \u00dcber GeoFroggerFX
|
||||||
menu.title.plugins = Plugins
|
menu.title.plugins = Plugins
|
||||||
|
menu.title.list = Listen
|
||||||
|
menu.title.list.new = Liste anlegen
|
||||||
|
menu.title.list.delete = Liste l\u00F6schen
|
||||||
|
|
||||||
menu.title.sort = Sortieren
|
menu.title.sort = Sortieren
|
||||||
menu.title.filter = Filtern
|
menu.title.filter = Filtern
|
||||||
|
|
||||||
label.text.cache.list=Caches
|
label.text.cache.list=Liste:
|
||||||
|
label.text.cache.list.count=Anzahl:
|
||||||
label.text.name=Name:
|
label.text.name=Name:
|
||||||
label.text.difficulty=Schwierigkeit:
|
label.text.difficulty=Schwierigkeit:
|
||||||
label.text.terrain=Gel\u00E4nde
|
label.text.terrain=Gel\u00E4nde
|
||||||
|
|||||||
@@ -5,11 +5,16 @@ menu.title.help = Help
|
|||||||
menu.title.settings = Settings
|
menu.title.settings = Settings
|
||||||
menu.title.about = About GeoFroggerFX
|
menu.title.about = About GeoFroggerFX
|
||||||
menu.title.plugins = Plugins
|
menu.title.plugins = Plugins
|
||||||
|
menu.title.list = Lists
|
||||||
|
menu.title.list.new = New list
|
||||||
|
menu.title.list.delete = Delete list
|
||||||
|
|
||||||
|
|
||||||
menu.title.sort = Sort
|
menu.title.sort = Sort
|
||||||
menu.title.filter = Filter
|
menu.title.filter = Filter
|
||||||
|
|
||||||
label.text.cache.list=Caches
|
label.text.cache.list=List:
|
||||||
|
label.text.cache.list.count=Number:
|
||||||
label.text.name=Name:
|
label.text.name=Name:
|
||||||
label.text.difficulty=Difficulty:
|
label.text.difficulty=Difficulty:
|
||||||
label.text.terrain=Terrain:
|
label.text.terrain=Terrain:
|
||||||
|
|||||||
@@ -84,8 +84,6 @@ public class CacheList {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CacheList{" +
|
return getName();
|
||||||
"name='" + name + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,9 +63,22 @@ public interface CacheService {
|
|||||||
*/
|
*/
|
||||||
List<CacheList> getAllCacheLists();
|
List<CacheList> getAllCacheLists();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache list with the given name already exists
|
||||||
|
* @param name of the cache list
|
||||||
|
* @return true if a list with the given name exists
|
||||||
|
*/
|
||||||
|
boolean doesCacheListNameExist(String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a cache list
|
* Stores a cache list
|
||||||
* @param list list of caches
|
* @param list list of caches
|
||||||
*/
|
*/
|
||||||
void storeCacheList(CacheList list);
|
void storeCacheList(CacheList list);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a cache list
|
||||||
|
* @param cacheList deletes the given cache list
|
||||||
|
*/
|
||||||
|
void deleteCacheList(CacheList cacheList);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,6 +135,33 @@ public class CacheServiceImpl implements CacheService {
|
|||||||
return lists;
|
return lists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doesCacheListNameExist(String name) {
|
||||||
|
boolean doesExist = false;
|
||||||
|
try {
|
||||||
|
EntityManager em = dbService.getEntityManager();
|
||||||
|
String query = "select count(l) from CacheList l where l.name = :name";
|
||||||
|
Long result = (Long)em.createQuery(query).setParameter("name", name).getSingleResult();
|
||||||
|
doesExist = result > 0;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return doesExist;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteCacheList(CacheList cacheList) {
|
||||||
|
EntityManager em = dbService.getEntityManager();
|
||||||
|
try {
|
||||||
|
em.getTransaction().begin();
|
||||||
|
em.remove(cacheList);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user