Custom Exceptions
This commit is contained in:
parent
699f36c95c
commit
7e9efc138c
@ -17,18 +17,22 @@ public class DirectionMap {
|
||||
* @param start Startpunkt
|
||||
* @param ende Endpunkt
|
||||
* @param tourname Name der Aktuellen Tour
|
||||
* @throws IOException Fehler beim Image der Map
|
||||
* @throws DirectionMapException Fehler beim Image der Map
|
||||
*/
|
||||
public DirectionMap (String start, String ende, String tourname) throws IOException {
|
||||
getDirections(start, ende);
|
||||
Image map = getMap(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "size"));
|
||||
Image mappdf = getMap(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "sizePdf"));
|
||||
String file = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + ".jpg";
|
||||
String filepdf = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + "_pdf.jpg";
|
||||
FileHelper.saveImage(map, "jpg", new File(file));
|
||||
FileHelper.saveImage(mappdf, "jpg", new File(filepdf));
|
||||
if(ConfigHelper.getIniInt(ConfigHelper.getStandartConfig(), "settings", "openmap") == 1) {
|
||||
FileHelper.openDefault(file);
|
||||
public DirectionMap (String start, String ende, String tourname) throws DirectionMapException {
|
||||
try {
|
||||
getDirections(start, ende);
|
||||
Image map = getMap(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "size"));
|
||||
Image mappdf = getMap(ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "sizePdf"));
|
||||
String file = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + ".jpg";
|
||||
String filepdf = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + "_pdf.jpg";
|
||||
FileHelper.saveImage(map, "jpg", new File(file));
|
||||
FileHelper.saveImage(mappdf, "jpg", new File(filepdf));
|
||||
if(ConfigHelper.getIniInt(ConfigHelper.getStandartConfig(), "settings", "openmap") == 1) {
|
||||
FileHelper.openDefault(file);
|
||||
}
|
||||
}catch (IOException e){
|
||||
throw new DirectionMapException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,23 +55,31 @@ public class DirectionMap {
|
||||
/**
|
||||
* Downloadet die Map von Mapquest
|
||||
* @return Image von der Map
|
||||
* @throws IOException Fehler beim Get der Map
|
||||
* @throws DirectionMapException Fehler beim Get der Map
|
||||
*/
|
||||
private Image getMap(String size) throws IOException {
|
||||
return HttpHelper.httpGetImage("https://www.mapquestapi.com/staticmap/v5/map?session="+this.sessionId+"&size="+size+"&key="+ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "key"));
|
||||
private Image getMap(String size) throws DirectionMapException {
|
||||
try {
|
||||
return HttpHelper.httpGetImage("https://www.mapquestapi.com/staticmap/v5/map?session="+this.sessionId+"&size="+size+"&key="+ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "key"));
|
||||
}catch (IOException e){
|
||||
throw new DirectionMapException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Besorgt die Infos der Tour von Mapquest Directions
|
||||
* @param start Start der Tour
|
||||
* @param ende Ende der Tour
|
||||
* @throws IOException Fehler beim besorgen der infos über die Tour
|
||||
* @throws DirectionMapException Fehler beim besorgen der infos über die Tour
|
||||
*/
|
||||
private void getDirections(String start, String ende) throws IOException {
|
||||
String json = HttpHelper.httpGetJsonString("https://www.mapquestapi.com/directions/v2/route?key="+ ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "key")+"&from="+start+"&to="+ende+"&outFormat=json&ambiguities=ignore&routeType=fastest&doReverseGeocode=false&enhancedNarrative=false&avoidTimedConditions=false");
|
||||
this.strecke = JsonHelper.getDoubleFromJson(json, "distance");
|
||||
this.dauer = formatetTimeToMinutes(JsonHelper.getStingFromJson(json, "formattedTime"));
|
||||
this.sessionId = JsonHelper.getStingFromJson(json, "sessionId");
|
||||
private void getDirections(String start, String ende) throws DirectionMapException {
|
||||
try {
|
||||
String json = HttpHelper.httpGetJsonString("https://www.mapquestapi.com/directions/v2/route?key="+ ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "key")+"&from="+start+"&to="+ende+"&outFormat=json&ambiguities=ignore&routeType=fastest&doReverseGeocode=false&enhancedNarrative=false&avoidTimedConditions=false");
|
||||
this.strecke = JsonHelper.getDoubleFromJson(json, "distance");
|
||||
this.dauer = formatetTimeToMinutes(JsonHelper.getStingFromJson(json, "formattedTime"));
|
||||
this.sessionId = JsonHelper.getStingFromJson(json, "sessionId");
|
||||
}catch (IOException e){
|
||||
throw new DirectionMapException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
12
src/tourplaner/business/DirectionMapException.java
Normal file
12
src/tourplaner/business/DirectionMapException.java
Normal file
@ -0,0 +1,12 @@
|
||||
package tourplaner.business;
|
||||
|
||||
/**
|
||||
* Wird bei einem Fehler in der DirectionMap geworfen
|
||||
*/
|
||||
public class DirectionMapException extends Exception{
|
||||
|
||||
public DirectionMapException(String message){
|
||||
super("DirectionMap Error: -> "+message);
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package tourplaner.business;
|
||||
|
||||
import tourplaner.data.DbConnect;
|
||||
import tourplaner.data.DbErrorException;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
import tourplaner.ui.ProgressBar;
|
||||
@ -56,7 +57,7 @@ public class Exporter {
|
||||
allTours.forEach(t -> {
|
||||
try {
|
||||
TourPlaner.delTour(t.getName());
|
||||
} catch (SQLException throwables) {
|
||||
} catch (DbErrorException throwables) {
|
||||
LogHelper.error(throwables);
|
||||
}
|
||||
progressBar.addProgress(size);
|
||||
@ -76,7 +77,7 @@ public class Exporter {
|
||||
}
|
||||
progressBar.addProgress(finalSize);
|
||||
}
|
||||
} catch (IOException | SQLException e) {
|
||||
} catch (DbErrorException | DirectionMapException | FileNotFoundException e) {
|
||||
LogHelper.error(e);
|
||||
progressBar.setProgress(progressMax);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package tourplaner.business;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
import tourplaner.data.DbConnect;
|
||||
import tourplaner.data.DbErrorException;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
import tourplaner.ui.ProgressBar;
|
||||
@ -41,7 +42,7 @@ public class TourPlaner{
|
||||
* @return false bei error
|
||||
* @throws IOException Fehler beim editieren der Tour
|
||||
*/
|
||||
public static void editTour(String oldname, Tour tour) throws IOException, SQLException {
|
||||
public static void editTour(String oldname, Tour tour) throws DbErrorException, DirectionMapException {
|
||||
ProgressBar progressBar = new ProgressBar("Edit...");
|
||||
int step = progressBar.getProgressSize(3, 100);
|
||||
FileHelper.delFile(new File(getImagePath(oldname)));
|
||||
@ -59,7 +60,7 @@ public class TourPlaner{
|
||||
* Löscht eine Tour
|
||||
* @param tourname Tourname
|
||||
*/
|
||||
public static void delTour(String tourname) throws SQLException {
|
||||
public static void delTour(String tourname) throws DbErrorException {
|
||||
FileHelper.delFile(new File(getImagePath(tourname)));
|
||||
FileHelper.delFile(new File(getImagePdfPath(tourname)));
|
||||
new DbConnect().delTour(tourname);
|
||||
@ -71,7 +72,7 @@ public class TourPlaner{
|
||||
* @param progressMax Maximale anzeige der Progress bar
|
||||
* @throws IOException Fehler beim hinzufügen der Tour
|
||||
*/
|
||||
public static void addTourMax(Tour newTour, ProgressBar progressBar, int progressMax) throws IOException, SQLException {
|
||||
public static void addTourMax(Tour newTour, ProgressBar progressBar, int progressMax) throws DbErrorException, DirectionMapException {
|
||||
int step = progressBar.getProgressSize(2, progressMax);
|
||||
DirectionMap directionMap = new DirectionMap(newTour.getStart(), newTour.getZiel(), newTour.getName());
|
||||
progressBar.addProgress(step);
|
||||
@ -87,7 +88,7 @@ public class TourPlaner{
|
||||
* @param progressBar Aktuelle Progressbar
|
||||
* @throws IOException Fehler beim hinzufügen der Tour
|
||||
*/
|
||||
public static void addTour(Tour newTour, ProgressBar progressBar) throws IOException, SQLException {
|
||||
public static void addTour(Tour newTour, ProgressBar progressBar) throws DbErrorException, DirectionMapException {
|
||||
addTourMax(newTour, progressBar, 100);
|
||||
}
|
||||
|
||||
@ -141,7 +142,7 @@ public class TourPlaner{
|
||||
* @param tourname Name der Tour
|
||||
* @param log Neues Log
|
||||
*/
|
||||
public static void addLog(String tourname, Log log) throws SQLException {
|
||||
public static void addLog(String tourname, Log log) throws DbErrorException {
|
||||
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
|
||||
new DbConnect().addLog(tourname, log);
|
||||
}
|
||||
@ -151,7 +152,7 @@ public class TourPlaner{
|
||||
* @param tourname Name der Tour
|
||||
* @param id Id des Logs
|
||||
*/
|
||||
public static void delLog(String tourname, String id) throws SQLException {
|
||||
public static void delLog(String tourname, String id) throws DbErrorException {
|
||||
new DbConnect().delLog(tourname, id);
|
||||
}
|
||||
|
||||
@ -160,7 +161,7 @@ public class TourPlaner{
|
||||
* @param tourname Name der Tour
|
||||
* @param log Neues Log
|
||||
*/
|
||||
public static void editLog(String tourname, Log log) throws SQLException {
|
||||
public static void editLog(String tourname, Log log) throws DbErrorException {
|
||||
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
|
||||
new DbConnect().editLog(tourname, log);
|
||||
}
|
||||
|
@ -41,39 +41,56 @@ public class DbConnect {
|
||||
* @param oldname Alter Tour name
|
||||
* @param tour Neues Tour Object
|
||||
*/
|
||||
public void editTour(String oldname, Tour tour) throws SQLException {
|
||||
public void editTour(String oldname, Tour tour) throws DbErrorException {
|
||||
String tourname = tour.getName();
|
||||
ArrayList<Log> logs = getLogs(oldname);
|
||||
delLogs(oldname);
|
||||
PostgresHelper.executeUpdateEditTour("UPDATE public.tour SET tourname = ?, dauer = 1, mapjson = ?, start = ?, ziel = ?, strecke = ? WHERE tourname =?;", tour.getName(), tour.getMapJson(), tour.getStart(), tour.getZiel(), tour.getStrecke(), oldname);
|
||||
logs.forEach(log -> {
|
||||
try {
|
||||
addLog(tourname, log);
|
||||
} catch (SQLException throwables) {
|
||||
LogHelper.error(throwables);
|
||||
}
|
||||
});
|
||||
try {
|
||||
delLogs(oldname);
|
||||
PostgresHelper.executeUpdateEditTour("UPDATE public.tour SET tourname = ?, dauer = 1, mapjson = ?, start = ?, ziel = ?, strecke = ? WHERE tourname =?;", tour.getName(), tour.getMapJson(), tour.getStart(), tour.getZiel(), tour.getStrecke(), oldname);
|
||||
logs.forEach(log -> {
|
||||
try {
|
||||
addLog(tourname, log);
|
||||
} catch (DbErrorException throwables) {
|
||||
LogHelper.error(throwables);
|
||||
}
|
||||
});
|
||||
}catch (Exception e){
|
||||
throw new DbErrorException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void delLogs(String tourname) throws SQLException {
|
||||
PostgresHelper.executeUpdateString("DELETE FROM public.log WHERE tourname = ?", tourname);
|
||||
|
||||
private void delLogs(String tourname) throws DbErrorException {
|
||||
try {
|
||||
PostgresHelper.executeUpdateString("DELETE FROM public.log WHERE tourname = ?", tourname);
|
||||
}catch (SQLException e){
|
||||
throw new DbErrorException(e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Fügt eine Tour hinzu
|
||||
* @param tour Neue Tour
|
||||
* @return false bei error
|
||||
*/
|
||||
public void addTour(Tour tour) throws SQLException {
|
||||
PostgresHelper.executeUpdateAddTour("INSERT INTO public.tour (tourname, dauer, mapjson, start, ziel, strecke) VALUES (?, ?, ?, ?, ?, ?)", tour.getName(), tour.getDauer(), tour.getMapJson(), tour.getStart(), tour.getZiel(), tour.getStrecke());
|
||||
public void addTour(Tour tour) throws DbErrorException {
|
||||
try{
|
||||
PostgresHelper.executeUpdateAddTour("INSERT INTO public.tour (tourname, dauer, mapjson, start, ziel, strecke) VALUES (?, ?, ?, ?, ?, ?)", tour.getName(), tour.getDauer(), tour.getMapJson(), tour.getStart(), tour.getZiel(), tour.getStrecke());
|
||||
}catch (SQLException e){
|
||||
throw new DbErrorException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht eine Tour anhand des Tournamens
|
||||
* @param tourname Tourname der zu löschen ist
|
||||
*/
|
||||
public void delTour(String tourname) throws SQLException {
|
||||
delLogs(tourname);
|
||||
PostgresHelper.executeUpdateString("DELETE FROM public.tour WHERE tourname = ?",tourname);
|
||||
public void delTour(String tourname) throws DbErrorException {
|
||||
try {
|
||||
delLogs(tourname);
|
||||
PostgresHelper.executeUpdateString("DELETE FROM public.tour WHERE tourname = ?", tourname);
|
||||
}catch (SQLException e){
|
||||
throw new DbErrorException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Log> getLogs(String tourname){
|
||||
@ -120,32 +137,48 @@ public class DbConnect {
|
||||
* @param log Der Logeintrag
|
||||
* @return false bei error
|
||||
*/
|
||||
public void addLog(String tourname, Log log) throws SQLException {
|
||||
public void addLog(String tourname, Log log) throws DbErrorException {
|
||||
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
|
||||
PostgresHelper.executeUpdateAddLog("INSERT INTO public.log (tourname, id, bemerkung, datum, strecke, avg, hightmeter, pause, gegangen, dauer, rating) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)", tourname, log.getId(),log.getBemerkung(),log.getDatum(),log.getStrecke(),log.getAvgspeed(),log.getHightmeter(),log.getPause(),log.getGegangen(),log.getDauer(),log.getRating());
|
||||
}
|
||||
|
||||
public void editLog(String tourname, Log log) throws SQLException {
|
||||
PostgresHelper.executeUpdateEditLog("UPDATE public.log SET bemerkung = ?, datum = ?, strecke = ?, avg = ?, hightmeter = ?, pause = ?, gegangen = ?, dauer = ?, rating = ? WHERE tourname = ? and id = ?", log.getBemerkung(),log.getDatum(),log.getStrecke(),log.getAvgspeed(),log.getHightmeter(),log.getPause(),log.getGegangen(),log.getDauer(),log.getRating(),tourname ,log.getId());
|
||||
}
|
||||
|
||||
public void delLog(String tourname, String id) throws SQLException {
|
||||
PostgresHelper.executeUpdateDelLog("DELETE FROM public.log WHERE tourname = ? and id = ?", tourname, id);
|
||||
}
|
||||
|
||||
private int getTourSize() throws SQLException {
|
||||
Connection con = PostgresHelper.con();
|
||||
Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM tour;");
|
||||
int size;
|
||||
if (rs != null)
|
||||
{
|
||||
rs.last(); // moves cursor to the last row
|
||||
size = rs.getInt("count"); // get row id
|
||||
con.close();
|
||||
return size;
|
||||
try{
|
||||
PostgresHelper.executeUpdateAddLog("INSERT INTO public.log (tourname, id, bemerkung, datum, strecke, avg, hightmeter, pause, gegangen, dauer, rating) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)", tourname, log.getId(),log.getBemerkung(),log.getDatum(),log.getStrecke(),log.getAvgspeed(),log.getHightmeter(),log.getPause(),log.getGegangen(),log.getDauer(),log.getRating());
|
||||
}catch (SQLException e){
|
||||
throw new DbErrorException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void editLog(String tourname, Log log) throws DbErrorException {
|
||||
try{
|
||||
PostgresHelper.executeUpdateEditLog("UPDATE public.log SET bemerkung = ?, datum = ?, strecke = ?, avg = ?, hightmeter = ?, pause = ?, gegangen = ?, dauer = ?, rating = ? WHERE tourname = ? and id = ?", log.getBemerkung(),log.getDatum(),log.getStrecke(),log.getAvgspeed(),log.getHightmeter(),log.getPause(),log.getGegangen(),log.getDauer(),log.getRating(),tourname ,log.getId());
|
||||
}catch (SQLException e){
|
||||
throw new DbErrorException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void delLog(String tourname, String id) throws DbErrorException {
|
||||
try{
|
||||
PostgresHelper.executeUpdateDelLog("DELETE FROM public.log WHERE tourname = ? and id = ?", tourname, id);
|
||||
}catch (SQLException e){
|
||||
throw new DbErrorException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private int getTourSize() throws DbErrorException {
|
||||
Connection con = PostgresHelper.con();
|
||||
try{
|
||||
Statement s = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM tour;");
|
||||
int size;
|
||||
if (rs != null)
|
||||
{
|
||||
rs.last(); // moves cursor to the last row
|
||||
size = rs.getInt("count"); // get row id
|
||||
con.close();
|
||||
return size;
|
||||
}
|
||||
con.close();
|
||||
}catch (SQLException e){
|
||||
throw new DbErrorException(e.getMessage());
|
||||
}
|
||||
con.close();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
11
src/tourplaner/data/DbErrorException.java
Normal file
11
src/tourplaner/data/DbErrorException.java
Normal file
@ -0,0 +1,11 @@
|
||||
package tourplaner.data;
|
||||
|
||||
/**
|
||||
* Wird bei einem DB Error geworfen, damit der DAL auch austauschbar ist
|
||||
*/
|
||||
public class DbErrorException extends Exception{
|
||||
|
||||
public DbErrorException(String message){
|
||||
super("DB Error: " + message);
|
||||
}
|
||||
}
|
@ -39,6 +39,7 @@ public class PostgresHelper {
|
||||
c.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param sql SQL aus dem das prepared statement gebildet wird
|
||||
*/
|
||||
|
@ -12,7 +12,9 @@ import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import tourplaner.Main;
|
||||
import tourplaner.business.ConfigHelper;
|
||||
import tourplaner.business.DirectionMapException;
|
||||
import tourplaner.business.LogHelper;
|
||||
import tourplaner.data.DbErrorException;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.viewmodels.ViewModel;
|
||||
|
||||
@ -58,7 +60,7 @@ public class TourplanerController implements Initializable {
|
||||
try {
|
||||
this.viewModel.copyLog();
|
||||
syncLogs();
|
||||
} catch (SQLException throwables) {
|
||||
} catch (DbErrorException throwables) {
|
||||
LogHelper.error(throwables);
|
||||
}
|
||||
}
|
||||
@ -85,7 +87,7 @@ public class TourplanerController implements Initializable {
|
||||
private void editTourBtn(){
|
||||
try {
|
||||
this.viewModel.editTour();
|
||||
} catch (IOException | SQLException e) {
|
||||
} catch (DirectionMapException | DbErrorException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
String name = this.viewModel.getSelectedTour().getName();
|
||||
@ -100,7 +102,7 @@ public class TourplanerController implements Initializable {
|
||||
try {
|
||||
this.viewModel.editLog();
|
||||
syncLogs();
|
||||
} catch (SQLException throwables) {
|
||||
} catch (DbErrorException throwables) {
|
||||
LogHelper.error(throwables);
|
||||
}
|
||||
}
|
||||
@ -273,7 +275,7 @@ public class TourplanerController implements Initializable {
|
||||
try {
|
||||
this.viewModel.delLog();
|
||||
syncLogs();
|
||||
} catch (SQLException throwables) {
|
||||
} catch (DbErrorException throwables) {
|
||||
LogHelper.error(throwables);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.image.Image;
|
||||
import tourplaner.business.*;
|
||||
import tourplaner.data.DbErrorException;
|
||||
import tourplaner.ui.AlertHelper;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
@ -13,7 +14,6 @@ import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -41,7 +41,7 @@ public class ViewModel {
|
||||
* prüft ob eine tour ausgewählt ist
|
||||
* @throws IOException Fehler beim editieren der Tour
|
||||
*/
|
||||
public void editTour() throws IOException, SQLException {
|
||||
public void editTour() throws DbErrorException, DirectionMapException {
|
||||
if (this.selectedTour == null){
|
||||
AlertHelper.warn(ConfigHelper.getLangIniString("achtung"),
|
||||
ConfigHelper.getLangIniString("keinetourselected"),
|
||||
@ -167,7 +167,7 @@ public class ViewModel {
|
||||
progressBar.addProgress(10);
|
||||
try {
|
||||
TourPlaner.addTour(newTour, progressBar);
|
||||
} catch (IOException | SQLException e) {
|
||||
} catch (Exception e) {
|
||||
LogHelper.error(e);
|
||||
return false;
|
||||
}
|
||||
@ -196,7 +196,7 @@ public class ViewModel {
|
||||
* Bearbeitet einen gewählten Log eintrag
|
||||
*/
|
||||
@SuppressWarnings("UnusedAssignment")
|
||||
public void editLog() throws SQLException {
|
||||
public void editLog() throws DbErrorException {
|
||||
if(this.selectedTour != null) {
|
||||
if(this.selectedLog != null) {
|
||||
AtomicReference<Tour> tourAkt = new AtomicReference<>();
|
||||
@ -381,7 +381,7 @@ public class ViewModel {
|
||||
this.logData.add(newLog);
|
||||
try {
|
||||
TourPlaner.addLog(this.selectedTour.getName(), newLog);
|
||||
} catch (SQLException throwables) {
|
||||
} catch (DbErrorException throwables) {
|
||||
LogHelper.error(throwables);
|
||||
}
|
||||
s.addLog(newLog);
|
||||
@ -404,7 +404,7 @@ public class ViewModel {
|
||||
/**
|
||||
* Entfernt ein Log anhand des selectierten Logs
|
||||
*/
|
||||
public void delLog() throws SQLException {
|
||||
public void delLog() throws DbErrorException {
|
||||
if(this.selectedLog != null) {
|
||||
TourPlaner.delLog(this.selectedTour.getName(), this.selectedLog.getId());
|
||||
this.selectedLog = null;
|
||||
@ -508,7 +508,7 @@ public class ViewModel {
|
||||
TourPlaner.delTour(tourname);
|
||||
setSelectedTour(null);
|
||||
progressBar.setProgress(100);
|
||||
} catch (NullPointerException | SQLException e) {
|
||||
} catch (NullPointerException | DbErrorException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}else {
|
||||
@ -524,18 +524,20 @@ public class ViewModel {
|
||||
*/
|
||||
public void suche(String sucheInput, ProgressBar progressBar, int maxProgress){
|
||||
if(sucheInput.isEmpty()){
|
||||
progressBar.setProgress(maxProgress);
|
||||
AlertHelper.warn(ConfigHelper.getLangIniString("achtung"),
|
||||
ConfigHelper.getLangIniString("suchfeldleer"),
|
||||
ConfigHelper.getLangIniString("suchtextzuerst"));
|
||||
}else {
|
||||
ArrayList<Tour> result = TourPlaner.sucheTour(sucheInput, progressBar, maxProgress / 2);
|
||||
int steps = progressBar.getProgressSize(result.size(), maxProgress);
|
||||
tourNamen.clear();
|
||||
for (Tour tour : result) {
|
||||
tourNamen.add(tour.getName());
|
||||
progressBar.addProgress(steps);
|
||||
}
|
||||
this.sucheAktiv = true;
|
||||
}
|
||||
ArrayList<Tour> result = TourPlaner.sucheTour(sucheInput, progressBar, maxProgress/2);
|
||||
int steps = progressBar.getProgressSize(result.size(), maxProgress);
|
||||
tourNamen.clear();
|
||||
for (Tour tour:result) {
|
||||
tourNamen.add(tour.getName());
|
||||
progressBar.addProgress(steps);
|
||||
}
|
||||
this.sucheAktiv = true;
|
||||
progressBar.setProgress(maxProgress);
|
||||
}
|
||||
|
||||
@ -650,7 +652,7 @@ public class ViewModel {
|
||||
/**
|
||||
* Kopiert einen Log eintrag und erstellt dafür eine neue Id für das kopierte log
|
||||
*/
|
||||
public void copyLog() throws SQLException {
|
||||
public void copyLog() throws DbErrorException {
|
||||
Log selectedLog = getSelectedLog();
|
||||
Tour selectedTour = getSelectedTour();
|
||||
if(selectedTour == null){
|
||||
@ -690,7 +692,7 @@ public class ViewModel {
|
||||
logs.forEach(l -> {
|
||||
try {
|
||||
TourPlaner.addLog(newName, l);
|
||||
} catch (SQLException throwables) {
|
||||
} catch (DbErrorException throwables) {
|
||||
LogHelper.error(throwables);
|
||||
}
|
||||
progressBar.addProgress(steps);
|
||||
@ -702,7 +704,7 @@ public class ViewModel {
|
||||
// getLogData();
|
||||
selectTour(newName);
|
||||
progressBar.setProgress(maxLevel);
|
||||
} catch (IOException | SQLException e) {
|
||||
} catch (DbErrorException |DirectionMapException e) {
|
||||
LogHelper.error(e);
|
||||
progressBar.setProgress(maxLevel);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user