Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
49b6407ce6 | |||
9472a5537a | |||
f4e9b16792 | |||
c261652ce6 |
@ -1,25 +1,72 @@
|
||||
package tourplaner.business;
|
||||
|
||||
import tourplaner.object.Data;
|
||||
import tourplaner.data.DbConnect;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
import tourplaner.ui.AlertHelper;
|
||||
import tourplaner.ui.ProgressBar;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Ist für das importieren und Exportieren der Daten zuständig
|
||||
*/
|
||||
public class Exporter {
|
||||
|
||||
private Data data;
|
||||
private ArrayList<Tour> touren;
|
||||
private String path;
|
||||
|
||||
public Exporter(Data data, String path) {
|
||||
this.data = data;
|
||||
/**
|
||||
* Erstellt den Exporter mit dem gegebenen Path
|
||||
* @param path Gegebener Path
|
||||
*/
|
||||
public Exporter(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt den Export aus -> Holt daten, erstellt file
|
||||
* @throws IOException Fehler beim File erstellen
|
||||
*/
|
||||
public void doExport() throws IOException {
|
||||
JsonHelper.getJsonFromObj(data, new FileWriter(path));
|
||||
ProgressBar progressBar = new ProgressBar("Exportieren");
|
||||
int step = progressBar.getProgressSize(4, 100);
|
||||
ArrayList<Tour> data = new DbConnect().getAllTouren();
|
||||
progressBar.addProgress(step);
|
||||
FileWriter fileWriter = new FileWriter(path + ".json");
|
||||
progressBar.addProgress(step);
|
||||
JsonHelper.getJsonFromObj(data, fileWriter);
|
||||
progressBar.addProgress(step);
|
||||
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
|
||||
progressBar.addProgress(step);
|
||||
bufferedWriter.close();
|
||||
}
|
||||
|
||||
public void doImport(){
|
||||
|
||||
/**
|
||||
* Führt den Imput aus -> File holen, Daten in db erstellen
|
||||
* @throws IOException Fehler beim File öffnen
|
||||
*/
|
||||
public void doImport() throws IOException {
|
||||
this.touren = JsonHelper.getTourenFromJson(new FileReader(this.path));
|
||||
ProgressBar progressBar = new ProgressBar("Importiere Daten");
|
||||
DbConnect dbConnect = new DbConnect();
|
||||
progressBar.addProgress(5);
|
||||
dbConnect.delAllData();
|
||||
progressBar.addProgress(5);
|
||||
int size = progressBar.getProgressSize(this.touren.size() * 3, 100);
|
||||
for (Tour tour:this.touren) {
|
||||
new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName());
|
||||
progressBar.addProgress(size);
|
||||
dbConnect.addTour(tour);
|
||||
progressBar.addProgress(size);
|
||||
ArrayList<Log> logs = tour.getLogs();
|
||||
for (Log log:logs) {
|
||||
dbConnect.addLog(tour.getName(), log);
|
||||
}
|
||||
progressBar.addProgress(size);
|
||||
}
|
||||
progressBar.addProgress(size);
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,12 @@ package tourplaner.business;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import tourplaner.object.Tour;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Hilfsklasse für Json (Gson)
|
||||
@ -48,6 +52,15 @@ public class JsonHelper {
|
||||
new Gson().toJson(obj, writer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wandelt ein Json file in ein Data Objekt um
|
||||
* @param reader File aus dem gelesen wird
|
||||
* @return Data objekt das gelesen wurde
|
||||
*/
|
||||
public static ArrayList<Tour> getTourenFromJson(FileReader reader){
|
||||
return new Gson().fromJson(reader, new TypeToken<ArrayList<Tour>>() {}.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Json String to JsonObject
|
||||
* @param json Json string
|
||||
|
@ -3,6 +3,7 @@ package tourplaner.business;
|
||||
import com.itextpdf.text.*;
|
||||
import com.itextpdf.text.Font;
|
||||
import com.itextpdf.text.Image;
|
||||
import tourplaner.data.DbConnect;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
|
||||
@ -36,6 +37,59 @@ public class Reporter {
|
||||
private static Font smallBold = new Font(Font.TIMES_ROMAN, 12,
|
||||
Font.BOLD);
|
||||
|
||||
/**
|
||||
* Erstellt den Summary Report
|
||||
*/
|
||||
public static void sumReport(){
|
||||
ArrayList<Tour> tours = TourPlaner.getAllTours();
|
||||
String file = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "report", "path") + "summary.pdf";
|
||||
try {
|
||||
Document document = new Document();
|
||||
PdfWriter.getInstance(document, new FileOutputStream(file));
|
||||
document.open();
|
||||
addSumRepo(document, tours);
|
||||
|
||||
document.close();
|
||||
} catch (DocumentException | FileNotFoundException e) {
|
||||
LogHelper.error(e.getMessage(), e.getClass().getName());
|
||||
}
|
||||
FileHelper.openDefault(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Content des Sumary reports
|
||||
* @param document Document auf das geschrieben wird
|
||||
* @param touren Touren die berechnet werden
|
||||
* @throws DocumentException Fehler beim schreiben auf das Dokument
|
||||
*/
|
||||
private static void addSumRepo(Document document, ArrayList<Tour> touren) throws DocumentException {
|
||||
double dauer = 0;
|
||||
double strecke = 0;
|
||||
double calDauer = 0;
|
||||
double calStecke = 0;
|
||||
for (Tour tour:touren) {
|
||||
calStecke += tour.getStrecke();
|
||||
calDauer += Double.parseDouble(tour.getDauer());
|
||||
ArrayList<Log> logs = tour.getLogs();
|
||||
for (Log log:logs) {
|
||||
dauer += log.getDauer();
|
||||
strecke += log.getStrecke();
|
||||
}
|
||||
}
|
||||
Anchor anchor = new Anchor("Zusammengefasster Report", catFont);
|
||||
anchor.setName("Zusammengefasster Report");
|
||||
// Second parameter is the number of the chapter
|
||||
Chapter catPart = new Chapter(new Paragraph(anchor), 1);
|
||||
Paragraph subPara = new Paragraph("Daten", subFont);
|
||||
Section subCatPart = catPart.addSection(subPara);
|
||||
subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportvon") + System.getProperty("user.name") + ", " + new Date()));
|
||||
subCatPart.add(new Paragraph("Gesammte Zeit aller Logs: " + dauer));
|
||||
subCatPart.add(new Paragraph("gesammte Strecke aller Logs: " + strecke));
|
||||
subCatPart.add(new Paragraph("Berechnete Zeit aller Logs: " + calDauer));
|
||||
subCatPart.add(new Paragraph("Berechnete Strecke aller Touren: " + calStecke));
|
||||
document.add(catPart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen Tour Report
|
||||
* @param tourname Name der Tour die Gereportet werden soll
|
||||
|
@ -7,6 +7,7 @@ import tourplaner.object.Tour;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -46,6 +47,11 @@ public class TourPlaner{
|
||||
return new DbConnect().editTour(oldname, tour);
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht eine Tour
|
||||
* @param tourname Tourname
|
||||
* @return false bei error
|
||||
*/
|
||||
public static boolean delTour(String tourname){
|
||||
FileHelper.delFile(new File(getImagePath(tourname)));
|
||||
FileHelper.delFile(new File(getImagePdfPath(tourname)));
|
||||
@ -63,51 +69,125 @@ public class TourPlaner{
|
||||
return new DbConnect().addTour(newTour);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt das Gui Bild
|
||||
* @param tourname Name der Tour
|
||||
* @return Das Bild
|
||||
* @throws IOException Error beim Bild holen
|
||||
*/
|
||||
public static Image getImage(String tourname) throws IOException {
|
||||
return FileHelper.getImage(new File(getImagePath(tourname)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Path zu dem Bild für die GUI
|
||||
* @param tourname Name der Tour
|
||||
* @return Path zu dem Bild für die GUI
|
||||
*/
|
||||
public static String getImagePath(String tourname){
|
||||
return ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + ".jpg";
|
||||
}
|
||||
|
||||
/**
|
||||
* Path zu dem Bild für die PDF
|
||||
* @param tourname Name der Tour
|
||||
* @return Path zu dem Bild für die PDF
|
||||
*/
|
||||
public static String getImagePdfPath(String tourname){
|
||||
return ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "map", "path") + tourname + "_pdf.jpg";
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffnet ein Bild einer Tour
|
||||
* @param tourname Tourname
|
||||
*/
|
||||
public static void openImage(String tourname){
|
||||
FileHelper.openDefault(getImagePath(tourname));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Holt alle Logs einer Tour
|
||||
* @param tourname Tourname
|
||||
* @return Alle Logs der Tour
|
||||
*/
|
||||
public static ArrayList<Log> getLogs(String tourname){
|
||||
return new DbConnect().getLogs(tourname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt einen Rport aus
|
||||
* @param tourname Name der Tour die gereportet wird
|
||||
*/
|
||||
public static void doReport(String tourname){
|
||||
Reporter.createTourReport(tourname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt eine Tour
|
||||
* @param tourname Name der zu holenden Tour
|
||||
* @return Tour die geholt werden soll
|
||||
*/
|
||||
public static Tour getTour(String tourname){
|
||||
return new DbConnect().getTour(tourname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt ein Log hinzu
|
||||
* @param tourname Name der Tour
|
||||
* @param log Neues Log
|
||||
* @return false bei error
|
||||
*/
|
||||
public static boolean addLog(String tourname, Log log){
|
||||
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
|
||||
return new DbConnect().addLog(tourname, log);
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht ein Log
|
||||
* @param tourname Name der Tour
|
||||
* @param id Id des Logs
|
||||
* @return false bei error
|
||||
*/
|
||||
public static boolean delLog(String tourname, String id){
|
||||
return new DbConnect().delLog(tourname, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Editiert ein Log
|
||||
* @param tourname Name der Tour
|
||||
* @param log Neues Log
|
||||
* @return false bei error
|
||||
*/
|
||||
public static boolean editLog(String tourname, Log log){
|
||||
if(Double.isInfinite(log.getAvgspeed())) log.setAvgspeed(-1.0);
|
||||
return new DbConnect().editLog(tourname, log);
|
||||
}
|
||||
|
||||
|
||||
public static String getMapJson(String start, String ziel){
|
||||
// TODO: 14.04.2021 Map Quest
|
||||
return start + " " + ziel;
|
||||
/**
|
||||
* Exportiert die Daten
|
||||
* @param path Path zu den Daten
|
||||
* @throws IOException Fehler beim schreiben der Daten
|
||||
*/
|
||||
public static void exportData(String path) throws IOException {
|
||||
Exporter exporter = new Exporter(path);
|
||||
exporter.doExport();
|
||||
FileHelper.openDefault(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sucht alle touren die den gegebenen tournamen enthalten
|
||||
* @param tourname Name der zu suchen ist
|
||||
* @return Alle touren die auf den Suchterm passen
|
||||
*/
|
||||
public static ArrayList<Tour> sucheTour(String tourname){
|
||||
ArrayList<Tour> touren = new ArrayList<>();
|
||||
getAllTours().forEach(t ->{
|
||||
if(t.getName().contains(tourname)){
|
||||
touren.add(t);
|
||||
}
|
||||
});
|
||||
return touren;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,6 +84,21 @@ public class DbConnect {
|
||||
return !result.contains(false);
|
||||
}
|
||||
|
||||
public boolean delAllData(){
|
||||
ArrayList<Boolean> result = new ArrayList<>();
|
||||
result.add(delAllLog());
|
||||
result.add(delAllTour());
|
||||
return !result.contains(false);
|
||||
}
|
||||
|
||||
private boolean delAllTour(){
|
||||
return PostgresHelper.executeUpdate("DELETE FROM public.tour");
|
||||
}
|
||||
|
||||
private boolean delAllLog(){
|
||||
return PostgresHelper.executeUpdate("DELETE FROM public.log");
|
||||
}
|
||||
|
||||
public ArrayList<Log> getLogs(String tourname){
|
||||
|
||||
this.c = PostgresHelper.con();
|
||||
@ -165,7 +180,7 @@ public class DbConnect {
|
||||
dauer = rs.getDouble("dauer");
|
||||
strecke = rs.getDouble("strecke");
|
||||
if (!tourname.isEmpty()) {
|
||||
touren.add(new Tour(tourname, dauer + "", mapjson, strecke, start, ziel));
|
||||
touren.add(new Tour(tourname, dauer + "", mapjson, strecke, start, ziel, getLogs(tourname)));
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package tourplaner.object;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Data {
|
||||
private ArrayList<Log> logs;
|
||||
private ArrayList<Tour> touren;
|
||||
|
||||
public Data(ArrayList<Log> logs, ArrayList<Tour> touren){
|
||||
this.logs = logs;
|
||||
this.touren = touren;
|
||||
}
|
||||
|
||||
public ArrayList<Log> getLogs() {
|
||||
return logs;
|
||||
}
|
||||
|
||||
public ArrayList<Tour> getTouren() {
|
||||
return touren;
|
||||
}
|
||||
}
|
@ -21,6 +21,16 @@ public class Tour {
|
||||
this.log = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Tour(String name, String dauer, String mapJson, double strecke, String start, String ziel, ArrayList<Log> logs) {
|
||||
this.dauer = dauer;
|
||||
this.mapJson = mapJson;
|
||||
this.strecke = strecke;
|
||||
this.name = name;
|
||||
this.start = start;
|
||||
this.ziel = ziel;
|
||||
this.log = logs;
|
||||
}
|
||||
|
||||
public void setTour(Tour tour){
|
||||
this.dauer = tour.getDauer();
|
||||
this.mapJson = tour.getMapJson();
|
||||
|
@ -46,17 +46,27 @@
|
||||
<Menu fx:id="menueFile" mnemonicParsing="false" text="Datei">
|
||||
<items>
|
||||
<MenuItem fx:id="beendenButton" mnemonicParsing="false" onAction="#quitApp" text="Beenden" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#reportSum" text="Report alles" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#tourReport" text="Tour Report erstellen" />
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Bearbeiten">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#importBtn" text="Import" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#exportBtn" text="Export" />
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Optionen">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" onAction="#tourReport" text="Tour Report erstellen" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" />
|
||||
<CheckMenuItem mnemonicParsing="false" text="Map automatisch öffnen" />
|
||||
<CheckMenuItem mnemonicParsing="false" text="Report automatisch öffnen" />
|
||||
<Menu mnemonicParsing="false" text="Sprache">
|
||||
<items>
|
||||
<RadioMenuItem mnemonicParsing="false" text="Deutsch" />
|
||||
<RadioMenuItem mnemonicParsing="false" text="Englisch" />
|
||||
</items>
|
||||
</Menu>
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Hilfe">
|
||||
|
@ -11,6 +11,11 @@ import javafx.stage.Stage;
|
||||
import javafx.stage.WindowEvent;
|
||||
import tourplaner.business.ConfigHelper;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.time.LocalDate;
|
||||
@ -229,4 +234,24 @@ public class AlertHelper {
|
||||
stage.showAndWait();
|
||||
return selectedDate.get();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* File Auswahl
|
||||
* @param btn Text des Speichern/Öffnen Btn
|
||||
* @return String des Files, bei error null
|
||||
*/
|
||||
public static String fileChooser(String btn){
|
||||
// JFileChooser-Objekt erstellen
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
// Dialog zum Oeffnen von Dateien anzeigen
|
||||
int rueckgabeWert = chooser.showDialog(null, btn);
|
||||
|
||||
/* Abfrage, ob auf "Öffnen" geklickt wurde */
|
||||
if(rueckgabeWert == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
return chooser.getSelectedFile().getAbsolutePath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
45
src/tourplaner/ui/ProgressBar.java
Normal file
45
src/tourplaner/ui/ProgressBar.java
Normal file
@ -0,0 +1,45 @@
|
||||
package tourplaner.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import java.awt.*;
|
||||
|
||||
public class ProgressBar {
|
||||
private int status;
|
||||
private JFrame frame;
|
||||
private JProgressBar progressBar;
|
||||
|
||||
public ProgressBar(String title){
|
||||
this.frame = new JFrame(title);
|
||||
this.frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
Container content = this.frame.getContentPane();
|
||||
this.progressBar = new JProgressBar();
|
||||
this.progressBar.setValue(0);
|
||||
this.progressBar.setStringPainted(true);
|
||||
TitledBorder border = BorderFactory.createTitledBorder("Laden....");
|
||||
this.progressBar.setBorder(border);
|
||||
content.add(this.progressBar, BorderLayout.NORTH);
|
||||
this.frame.setSize(300, 100);
|
||||
this.frame.setVisible(true);
|
||||
}
|
||||
|
||||
public void addProgress(int add){
|
||||
this.status += add;
|
||||
System.out.println("PROGRESS: " + this.status);
|
||||
this.progressBar.setValue(this.status);
|
||||
if(this.status == 100){
|
||||
frame.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void closeProgress(){
|
||||
this.frame.setVisible(false);
|
||||
}
|
||||
|
||||
public int getProgressSize(int todo, int maxLevel){
|
||||
int steps = (progressBar.getValue() - maxLevel) / todo;
|
||||
if(steps < 0) steps = steps*-1;
|
||||
System.out.println("STEPS: " + steps);
|
||||
return steps;
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
import tourplaner.viewmodels.ViewModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -92,17 +93,18 @@ public class TourplanerController implements Initializable {
|
||||
}
|
||||
|
||||
private void syncTour(String selectedItem){
|
||||
beschreibungTableView.getItems().removeIf(s -> true); //Leert die Table View komplett
|
||||
beschreibungTableView.getItems().clear(); //Leert die Table View komplett
|
||||
beschreibungTableView.getItems().add(this.viewModel.getTour(selectedItem));
|
||||
mapImageView.setImage(this.viewModel.getImage(selectedItem));
|
||||
}
|
||||
|
||||
private void syncTourNamen(){
|
||||
TourListView.getItems().clear();
|
||||
TourListView.setItems(this.viewModel.getTourNamen());
|
||||
}
|
||||
|
||||
private void syncLogs(){
|
||||
logTableView.getItems().removeIf(s -> true);
|
||||
logTableView.getItems().clear();
|
||||
logTableView.setItems(this.viewModel.getLogData());
|
||||
}
|
||||
|
||||
@ -113,10 +115,13 @@ public class TourplanerController implements Initializable {
|
||||
*/
|
||||
@FXML
|
||||
private void tourListSelectedItem(MouseEvent mouseEvent){
|
||||
ProgressBar progressBar = new ProgressBar("Tour auswählen...");
|
||||
String selectedItem = TourListView.getSelectionModel().getSelectedItem();
|
||||
this.viewModel.selectTour(selectedItem);
|
||||
titleTextView.setText(selectedItem);
|
||||
progressBar.addProgress(10);
|
||||
syncTour(selectedItem);
|
||||
progressBar.addProgress(10);
|
||||
startCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("start"));
|
||||
zielCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("ziel"));
|
||||
dauerCol.setCellValueFactory(new PropertyValueFactory<Tour, String>("dauer"));
|
||||
@ -125,8 +130,10 @@ public class TourplanerController implements Initializable {
|
||||
|
||||
//Log anzeigen
|
||||
logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinelogsvorhanden")));
|
||||
logTableView.getItems().removeIf(s -> true);
|
||||
logTableView.getItems().clear();
|
||||
progressBar.addProgress(10);
|
||||
logTableView.setItems(this.viewModel.getLogData());
|
||||
progressBar.addProgress(10);
|
||||
logDauerCol.setCellValueFactory(new PropertyValueFactory<Log, String>("dauer"));
|
||||
logStreckeCol.setCellValueFactory(new PropertyValueFactory<Log, String>("strecke"));
|
||||
logDatumCol.setCellValueFactory(new PropertyValueFactory<Log, String>("datum"));
|
||||
@ -135,8 +142,16 @@ public class TourplanerController implements Initializable {
|
||||
logPauseCol.setCellValueFactory(new PropertyValueFactory<Log, String>("pause"));
|
||||
logGegangenCol.setCellValueFactory(new PropertyValueFactory<Log, String>("gegangen"));
|
||||
logBemerkungCol.setCellValueFactory(new PropertyValueFactory<Log, String>("bemerkung"));
|
||||
|
||||
progressBar.addProgress(10);
|
||||
mapImageView.setImage(this.viewModel.getImage(this.viewModel.getSelectedTour().getName()));
|
||||
if(this.viewModel.isSucheAktiv()){
|
||||
this.viewModel.setSucheAktiv(false);
|
||||
progressBar.addProgress(10);
|
||||
syncTourNamen();
|
||||
progressBar.addProgress(40);
|
||||
this.sucheInput.setText("");
|
||||
}
|
||||
progressBar.addProgress(50);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,7 +179,7 @@ public class TourplanerController implements Initializable {
|
||||
*/
|
||||
@FXML
|
||||
private void delTour(){
|
||||
this.beschreibungTableView.getItems().removeIf(s -> true); //löscht alles aus der tabelle
|
||||
this.beschreibungTableView.getItems().clear(); //löscht alles aus der tabelle
|
||||
this.titleTextView.setText(ConfigHelper.getLangIniString("keinetourselected"));
|
||||
this.viewModel.delTour();
|
||||
logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected")));
|
||||
@ -177,7 +192,10 @@ public class TourplanerController implements Initializable {
|
||||
*/
|
||||
@FXML
|
||||
private void suche(){
|
||||
ProgressBar progressBar = new ProgressBar("Suche");
|
||||
this.viewModel.suche(this.sucheInput.getText());
|
||||
progressBar.addProgress(100);
|
||||
progressBar.closeProgress();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,12 +234,33 @@ public class TourplanerController implements Initializable {
|
||||
TourListView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
|
||||
TourListView.setOrientation(Orientation.VERTICAL);
|
||||
syncTourNamen();
|
||||
deselectAll();
|
||||
|
||||
}
|
||||
|
||||
private void deselectAll(){
|
||||
//Tabs zu Tour -> rechts oben
|
||||
beschreibungTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected")));
|
||||
titleTextView.setText( ConfigHelper.getLangIniString("keinetourselected"));
|
||||
//Log -> rechts unten
|
||||
logTableView.setPlaceholder(new Label( ConfigHelper.getLangIniString("keinetourselected")));
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void exportBtn(){
|
||||
this.viewModel.exportData();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void importBtn(){
|
||||
deselectAll();
|
||||
this.viewModel.importData();
|
||||
syncTourNamen();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void reportSum(){
|
||||
this.viewModel.sumReport();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,14 +3,14 @@ package tourplaner.viewmodels;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.image.Image;
|
||||
import tourplaner.business.TourPlaner;
|
||||
import tourplaner.business.*;
|
||||
import tourplaner.ui.AlertHelper;
|
||||
import tourplaner.business.ConfigHelper;
|
||||
import tourplaner.business.LogHelper;
|
||||
import tourplaner.object.Log;
|
||||
import tourplaner.object.Tour;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@ -23,13 +23,14 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
public class ViewModel {
|
||||
//Tour
|
||||
private final ObservableList<Tour> tourData = FXCollections.observableArrayList();
|
||||
private final ObservableList<String> tourNamen = FXCollections.observableArrayList();
|
||||
private ObservableList<String> tourNamen = FXCollections.observableArrayList();
|
||||
private Tour selectedTour;
|
||||
private String neueTourName, neueTourStart, neueTourZiel, neueBemerkung;
|
||||
//Log
|
||||
private final ObservableList<Log> logData = FXCollections.observableArrayList();
|
||||
private Log selectedLog;
|
||||
|
||||
// Suche
|
||||
private boolean sucheAktiv;
|
||||
|
||||
|
||||
public Image getImage(String tourname){
|
||||
@ -458,7 +459,7 @@ public class ViewModel {
|
||||
getTourData().forEach(s -> {
|
||||
namen.add(s.getName());
|
||||
});
|
||||
tourNamen.removeAll();
|
||||
tourNamen.clear();
|
||||
tourNamen.addAll(namen);
|
||||
return tourNamen;
|
||||
}
|
||||
@ -480,7 +481,7 @@ public class ViewModel {
|
||||
}
|
||||
|
||||
public ObservableList<Tour> getTourData() {
|
||||
tourData.removeAll();
|
||||
tourData.clear();
|
||||
tourData.addAll(TourPlaner.getAllTours());
|
||||
return tourData;
|
||||
}
|
||||
@ -515,7 +516,20 @@ public class ViewModel {
|
||||
ConfigHelper.getLangIniString("suchfeldleer"),
|
||||
ConfigHelper.getLangIniString("suchtextzuerst"));
|
||||
}
|
||||
// TODO: 19.03.2021 Suchlogik
|
||||
ArrayList<Tour> result = TourPlaner.sucheTour(sucheInput);
|
||||
tourNamen.clear();
|
||||
for (Tour tour:result) {
|
||||
tourNamen.add(tour.getName());
|
||||
}
|
||||
this.sucheAktiv = true;
|
||||
}
|
||||
|
||||
public boolean isSucheAktiv() {
|
||||
return sucheAktiv;
|
||||
}
|
||||
|
||||
public void setSucheAktiv(boolean sucheAktiv) {
|
||||
this.sucheAktiv = sucheAktiv;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -582,4 +596,43 @@ public class ViewModel {
|
||||
TourPlaner.doReport(this.selectedTour.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exportiert alle daten in ein File das hier gewählt wird
|
||||
*/
|
||||
public void exportData(){
|
||||
String file = AlertHelper.fileChooser("Exportiere");
|
||||
System.out.println("EXPORT: " + file);
|
||||
if(file != null){
|
||||
try {
|
||||
new Exporter(file).doExport();
|
||||
} catch (IOException e) {
|
||||
AlertHelper.error("Error", "Export Error", "Fehler beim Exportieren");
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Importiert alle daten von einem File das hier gewählt wird
|
||||
*/
|
||||
public void importData() {
|
||||
String file = AlertHelper.fileChooser("Importiere");
|
||||
if (file != null){
|
||||
try {
|
||||
this.tourNamen = FXCollections.observableArrayList();
|
||||
new Exporter(file).doImport();
|
||||
} catch (IOException e) {
|
||||
AlertHelper.error("Error", "Import Error", "Fehler beim Importieren");
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen Summary Report
|
||||
*/
|
||||
public void sumReport(){
|
||||
Reporter.sumReport();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user