Add Tour -> unique Name + no empty imput
AlertHelper -> warn, info, error, exception
This commit is contained in:
		| @@ -95,3 +95,45 @@ App started | |||||||
| 2021-03-17 15:20:09 INFO  PostgresHelper:15 - User Table created | 2021-03-17 15:20:09 INFO  PostgresHelper:15 - User Table created | ||||||
| 2021-03-17 15:20:11 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | 2021-03-17 15:20:11 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
| 2021-03-17 15:20:11 ERROR NullPointerException:33 -  | 2021-03-17 15:20:11 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 15:36:24 ERROR ViewModel -> DelTour:33 - Keine Tour ausgewählt! | ||||||
|  | 2021-03-17 15:38:41 ERROR ViewModel -> DelTour:33 - Keine Tour ausgewählt! | ||||||
|  | 2021-03-17 16:02:24 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 16:02:24 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 16:02:26 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 16:02:26 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 16:03:16 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 16:03:16 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 16:03:18 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 16:03:18 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 16:04:18 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 16:04:18 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 16:04:20 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 16:04:20 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 16:04:26 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 16:04:26 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 16:04:28 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 16:04:28 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 16:06:47 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 16:06:47 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 16:06:49 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 16:06:49 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 16:06:55 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 16:06:55 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 16:06:57 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 16:06:57 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 17:02:33 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 17:02:33 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 17:02:35 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 17:02:35 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 17:02:38 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 17:02:38 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 17:02:40 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 17:02:40 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 17:08:23 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 17:08:23 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 17:08:25 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 17:08:25 ERROR NullPointerException:33 -  | ||||||
|  | 2021-03-17 17:08:31 INFO  TourPlaner:15 - Tour Planer App gestartet | ||||||
|  | 2021-03-17 17:08:31 INFO  PostgresHelper:15 - User Table created | ||||||
|  | 2021-03-17 17:08:33 ERROR PSQLException:33 - Connection to 192.168.1.116:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. | ||||||
|  | 2021-03-17 17:08:33 ERROR NullPointerException:33 -  | ||||||
|   | |||||||
							
								
								
									
										79
									
								
								src/tourplaner/business/AlertHelper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								src/tourplaner/business/AlertHelper.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | |||||||
|  | package tourplaner.business; | ||||||
|  |  | ||||||
|  | import javafx.scene.control.Alert; | ||||||
|  | import javafx.scene.control.Label; | ||||||
|  | import javafx.scene.control.TextArea; | ||||||
|  | import javafx.scene.control.TextInputDialog; | ||||||
|  | import javafx.scene.layout.GridPane; | ||||||
|  | import javafx.scene.layout.Priority; | ||||||
|  |  | ||||||
|  | import java.io.PrintWriter; | ||||||
|  | import java.io.StringWriter; | ||||||
|  | import java.util.Optional; | ||||||
|  | import java.util.concurrent.atomic.AtomicReference; | ||||||
|  |  | ||||||
|  | public class AlertHelper { | ||||||
|  |     public static void warn(String title, String header, String msg){ | ||||||
|  |         alertType(Alert.AlertType.WARNING, title, header, msg); | ||||||
|  |     } | ||||||
|  |     public static void inform(String title, String header, String msg){ | ||||||
|  |         alertType(Alert.AlertType.INFORMATION, title, header, msg); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static void informNoHeader(String title, String msg){ | ||||||
|  |         inform(title, null, msg); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static void error(String title, String header, String msg){ | ||||||
|  |         alertType(Alert.AlertType.ERROR, title, header, msg); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static void exerror(String title, String header, String msg, Exception ex){ | ||||||
|  |         Alert alert = new Alert(Alert.AlertType.ERROR); | ||||||
|  |         alert.setTitle(title); | ||||||
|  |         alert.setHeaderText(header); | ||||||
|  |         alert.setContentText(msg); | ||||||
|  |         StringWriter sw = new StringWriter(); | ||||||
|  |         PrintWriter pw = new PrintWriter(sw); | ||||||
|  |         ex.printStackTrace(pw); | ||||||
|  |         String exceptionText = sw.toString(); | ||||||
|  |         Label label = new Label("Exception stacktrace:"); | ||||||
|  |         TextArea textArea = new TextArea(exceptionText); | ||||||
|  |         textArea.setEditable(false); | ||||||
|  |         textArea.setWrapText(true); | ||||||
|  |         textArea.setMaxWidth(Double.MAX_VALUE); | ||||||
|  |         textArea.setMaxHeight(Double.MAX_VALUE); | ||||||
|  |         GridPane.setVgrow(textArea, Priority.ALWAYS); | ||||||
|  |         GridPane.setHgrow(textArea, Priority.ALWAYS); | ||||||
|  |         GridPane expContent = new GridPane(); | ||||||
|  |         expContent.setMaxWidth(Double.MAX_VALUE); | ||||||
|  |         expContent.add(label, 0, 0); | ||||||
|  |         expContent.add(textArea, 0, 1); | ||||||
|  |         alert.getDialogPane().setExpandableContent(expContent); | ||||||
|  |         alert.showAndWait(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private static void alertType(Alert.AlertType alertly, String title, String header, String msg){ | ||||||
|  |         Alert alert = new Alert(alertly); | ||||||
|  |         alert.setTitle(title); | ||||||
|  |         alert.setHeaderText(header); | ||||||
|  |         alert.setContentText(msg); | ||||||
|  |  | ||||||
|  |         alert.showAndWait(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String inputText(String title, String header, String msg) { | ||||||
|  |         TextInputDialog dialog = new TextInputDialog(); | ||||||
|  |         dialog.setTitle(title); | ||||||
|  |         dialog.setHeaderText(header); | ||||||
|  |         dialog.setContentText(msg); | ||||||
|  |         Optional<String> result = dialog.showAndWait(); | ||||||
|  |         AtomicReference<String> returnText = new AtomicReference<>(""); | ||||||
|  |         result.ifPresent(returnText::set); | ||||||
|  |         if(!returnText.get().isEmpty()){ | ||||||
|  |             return returnText.get(); | ||||||
|  |         }else{ | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -10,6 +10,7 @@ import javafx.scene.control.cell.PropertyValueFactory; | |||||||
| import javafx.scene.input.MouseEvent; | import javafx.scene.input.MouseEvent; | ||||||
| import javafx.scene.layout.Pane; | import javafx.scene.layout.Pane; | ||||||
| import javafx.scene.web.WebView; | import javafx.scene.web.WebView; | ||||||
|  | import tourplaner.business.AlertHelper; | ||||||
| import tourplaner.object.Tour; | import tourplaner.object.Tour; | ||||||
| import tourplaner.viewmodels.ViewModel; | import tourplaner.viewmodels.ViewModel; | ||||||
|  |  | ||||||
| @@ -24,7 +25,7 @@ public class TourplanerController implements Initializable { | |||||||
|     public Tab kartenTab, beschreibungTab; |     public Tab kartenTab, beschreibungTab; | ||||||
|     public TableView<Tour> beschreibungTableView; |     public TableView<Tour> beschreibungTableView; | ||||||
|     public TableColumn<Tour, String> startCol, zielCol, dauerCol, streckeCol, nameCol; |     public TableColumn<Tour, String> startCol, zielCol, dauerCol, streckeCol, nameCol; | ||||||
|     public TextField titleTextView; |     public TextField titleTextView, sucheInput; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Wird gestartet wenn eine Tour in der Tour listView ausgewählt wird |      * Wird gestartet wenn eine Tour in der Tour listView ausgewählt wird | ||||||
| @@ -79,7 +80,12 @@ public class TourplanerController implements Initializable { | |||||||
|      */ |      */ | ||||||
|     @FXML |     @FXML | ||||||
|     private void suche(){ |     private void suche(){ | ||||||
|         this.viewModel.suche(); |         String sucheInput = this.sucheInput.getText(); | ||||||
|  |         if(sucheInput.isEmpty()){ | ||||||
|  |             AlertHelper.warn("ACHTUNG", "Suchfeld ist leer!", "Bitte zuerst den Suchtext in das Suchfeld eingeben!"); | ||||||
|  |         }else { | ||||||
|  |             this.viewModel.suche(sucheInput); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -2,7 +2,10 @@ package tourplaner.viewmodels; | |||||||
|  |  | ||||||
| import javafx.collections.FXCollections; | import javafx.collections.FXCollections; | ||||||
| import javafx.collections.ObservableList; | import javafx.collections.ObservableList; | ||||||
|  | import javafx.scene.control.Alert; | ||||||
| import javafx.scene.control.TextInputDialog; | import javafx.scene.control.TextInputDialog; | ||||||
|  | import tourplaner.business.AlertHelper; | ||||||
|  | import tourplaner.business.LogHelper; | ||||||
| import tourplaner.business.TourPlaner; | import tourplaner.business.TourPlaner; | ||||||
| import tourplaner.object.Tour; | import tourplaner.object.Tour; | ||||||
| import java.util.Optional; | import java.util.Optional; | ||||||
| @@ -15,37 +18,30 @@ public class ViewModel { | |||||||
|     private Tour selectedTour; |     private Tour selectedTour; | ||||||
|     private String neueTourName, neueTourStart, neueTourZiel; |     private String neueTourName, neueTourStart, neueTourZiel; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Fügt eine neue Tour hinzu | ||||||
|  |      */ | ||||||
|     public void addTour(){ |     public void addTour(){ | ||||||
|         TextInputDialog dialogName = new TextInputDialog(""); |         while(this.neueTourName == null) { | ||||||
|         dialogName.setTitle("Tour Name"); |             this.neueTourName = AlertHelper.inputText("Tourname", "Bitte geben Sie den Namen der Tour an!", "Name:"); | ||||||
|         dialogName.setHeaderText("Bitte geben Sie den Namen der Tour an!"); |             if (getTour(this.neueTourName) != null) { | ||||||
|         dialogName.setContentText("Name: "); |                 AlertHelper.warn("ACHTUNG", "Name bereits vergeben!", "Der Name '"+ this.neueTourName +"' ist bereits vergeben, bitte verwenden Sie einen andern!"); | ||||||
|         Optional<String> resultName = dialogName.showAndWait(); |                 this.neueTourName = null; | ||||||
|         resultName.ifPresent(sname ->  { |             } | ||||||
|             this.neueTourName = resultName.get(); |         } | ||||||
|             TextInputDialog dialogStart = new TextInputDialog(""); |         while(this.neueTourStart == null){ | ||||||
|             dialogStart.setTitle("Tour Startpunkt"); |             this.neueTourStart = AlertHelper.inputText("Tour Startpunkt", "Bitte geben Sie den Startpunkt der Tour an!", "Startpunkt: "); | ||||||
|             dialogStart.setHeaderText("Bitte geben Sie den Startpunkt der Tour an!"); |         } | ||||||
|             dialogStart.setContentText("Startpunkt: "); |         while(this.neueTourZiel == null){ | ||||||
|             Optional<String> resultStart = dialogStart.showAndWait(); |             this.neueTourZiel = AlertHelper.inputText("Tour zielpunkt", "Bitte geben Sie den Zielpunkt der Tour an!", "Zielpunkt: "); | ||||||
|             resultStart.ifPresent(sstart -> { |         } | ||||||
|                 this.neueTourStart = resultStart.get(); |         if (getTour(this.neueTourName) == null) { | ||||||
|                 TextInputDialog dialogZiel = new TextInputDialog(""); |             tourData.add(new Tour(this.neueTourName, "TBD", "TBD", 0, this.neueTourStart, this.neueTourZiel)); | ||||||
|                 dialogZiel.setTitle("Tour Zielpunkt"); |             tourNamen.add(this.neueTourName); | ||||||
|                 dialogZiel.setHeaderText("Bitte geben Sie den Zielpunkt der Tour an!"); |         } | ||||||
|                 dialogZiel.setContentText("Zielpunkt: "); |         this.neueTourStart = null; | ||||||
|                 Optional<String> resultZiel = dialogZiel.showAndWait(); |         this.neueTourZiel = null; | ||||||
|                 resultZiel.ifPresent(sziel -> { |         this.neueTourName = null; | ||||||
|                     this.neueTourZiel = resultZiel.get(); |  | ||||||
|                     if (getTour(this.neueTourName) == null) { |  | ||||||
|                         tourData.add(new Tour(this.neueTourName, "120", new TourPlaner().getMapJson(this.neueTourStart, this.neueTourZiel), 22.3, this.neueTourStart, this.neueTourZiel)); |  | ||||||
|                         tourNamen.add(this.neueTourName); |  | ||||||
|                     }else{ |  | ||||||
|                         // TODO: 17.03.2021 Warning das dieser Tourname bereits vergeben ist |  | ||||||
|                     } |  | ||||||
|                 }); |  | ||||||
|             }); |  | ||||||
|         }); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -109,12 +105,20 @@ public class ViewModel { | |||||||
|      * Entfernt eine Tour anhand der ausgewählten Tour |      * Entfernt eine Tour anhand der ausgewählten Tour | ||||||
|      */ |      */ | ||||||
|     public void delTour(){ |     public void delTour(){ | ||||||
|         String tourname = this.selectedTour.getName(); |         try { | ||||||
|         tourData.removeIf(s ->  s.getName().equals(tourname)); |             String tourname = this.selectedTour.getName(); | ||||||
|         tourNamen.removeIf(s -> s.equals(tourname)); |             tourData.removeIf(s -> s.getName().equals(tourname)); | ||||||
|  |             tourNamen.removeIf(s -> s.equals(tourname)); | ||||||
|  |         }catch (NullPointerException e){ | ||||||
|  |             LogHelper.error("Keine Tour ausgewählt!", "ViewModel -> DelTour"); | ||||||
|  |             AlertHelper.warn("ACHTUNG", "Keine Tour ausgewählt!", "Bitte wählen Sie zuerst eine Tour aus, bevor Sie auf löschen klicken!"); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void suche(){ |     /** | ||||||
|  |      * Sucht eine Tour | ||||||
|  |      */ | ||||||
|  |     public void suche(String suchString){ | ||||||
|  |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user