diff --git a/src/main/java/com/example/vpr_javafx/Data.java b/src/main/java/com/example/vpr_javafx/Data.java index d7be404..b294616 100644 --- a/src/main/java/com/example/vpr_javafx/Data.java +++ b/src/main/java/com/example/vpr_javafx/Data.java @@ -1,6 +1,9 @@ package com.example.vpr_javafx; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.scene.control.Alert; +import javafx.scene.control.ListView; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import org.w3c.dom.Text; @@ -426,8 +429,9 @@ public class Data { * @author Felix Düsterhaus */ - public ArrayList changeOrder(String userLogin) { - + public ArrayList changeOrder(String userLogin, ListView ListViewDelete) { + ArrayList chosenMeals = new ArrayList<>(); + ObservableList chosenMealsObservable = FXCollections.observableList(chosenMeals); ArrayList changedOrderList = new ArrayList<>(); List rows = getRows(); int changedEntries = 0; @@ -436,7 +440,7 @@ public class Data { UIManager.put("OptionPane.noButtonText", "Nein"); UIManager.put("OptionPane.yesButtonText", "Ja"); int result = JOptionPane.showInternalConfirmDialog(null, "Bestellungen wirklich Löschen?", "Bestätigung", JOptionPane.YES_NO_OPTION); - + ListViewDelete.getSelectionModel().getSelectedItems(); if (result == JOptionPane.YES_OPTION) { for (String row : rows) { String[] parts = row.split(";"); @@ -451,20 +455,15 @@ public class Data { changedEntries++; } } - try { - FileWriter writer = new FileWriter("orders2.txt"); - for(com.example.vpr_javafx.Order str: changedOrderList) { - writer.write(str + System.lineSeparator()); + try { + FileWriter writer = new FileWriter("orders2.txt"); + for(com.example.vpr_javafx.Order str: changedOrderList) { + writer.write(str + System.lineSeparator()); + } + writer.close(); + } catch (IOException e) { + e.printStackTrace(); } - writer.close(); - - - - - - } catch (IOException e) { - e.printStackTrace(); - } JOptionPane.showMessageDialog(null, changedEntries + " Bestellungen Gelöscht, Sie können eine neue Bestellung aufgeben"); } else { JOptionPane.showMessageDialog(null, "Bestellung nicht gelöscht."); diff --git a/src/main/java/com/example/vpr_javafx/HelloApplication.java b/src/main/java/com/example/vpr_javafx/HelloApplication.java index a13f2b2..137b8bb 100644 --- a/src/main/java/com/example/vpr_javafx/HelloApplication.java +++ b/src/main/java/com/example/vpr_javafx/HelloApplication.java @@ -20,7 +20,5 @@ public class HelloApplication extends Application { controller.writeAllergene(); } - public static void main(String[] args) { - launch(); - } + public static void main(String[] args) {launch();} } \ No newline at end of file diff --git a/src/main/java/com/example/vpr_javafx/HelloController.java b/src/main/java/com/example/vpr_javafx/HelloController.java index bf5ad6a..fb9d979 100644 --- a/src/main/java/com/example/vpr_javafx/HelloController.java +++ b/src/main/java/com/example/vpr_javafx/HelloController.java @@ -1,5 +1,7 @@ package com.example.vpr_javafx; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; @@ -113,6 +115,12 @@ public class HelloController { @FXML private Button btToOrder; @FXML + private Button btToChangeOrder; + @FXML + private Button btDeleteSelection; + @FXML + private Button btToMenu; + @FXML private RadioButton rbMonH1; @FXML private RadioButton rbMonH2; @@ -145,7 +153,10 @@ public class HelloController { @FXML private String imageUrl; + @FXML private ArrayList chosenMeals; + @FXML + private ListView listViewDelete; @FXML protected void OnSignInButton(ActionEvent event) throws IOException @@ -365,7 +376,7 @@ public class HelloController { rbThurH2.setVisible(true); rbFriH1.setVisible(true); rbFriH2.setVisible(true); - + btToChangeOrder.setVisible(true); } @FXML @@ -384,6 +395,34 @@ public class HelloController { chosenMeals.clear(); } + @FXML + protected void ToChangeOrder(ActionEvent event) throws IOException + { + Parent root = FXMLLoader.load(getClass().getResource("ChangeOrder-view.fxml")); + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + Scene scene = new Scene(root); + stage.setScene(scene); + stage.show(); + } + + @FXML + protected void deleteSelection() { + final int selectedId = listViewDelete.getSelectionModel().getSelectedIndex(); + //String itemToRemove = listViewDelete.getSelectionModel().getSelectedItem(); + listViewDelete.getItems().remove(selectedId); + Data data = new Data("order.txt"); + data.changeOrder("12345", listViewDelete); + } + + @FXML + protected void ToMenu(ActionEvent event) throws IOException + { + Parent root = FXMLLoader.load(getClass().getResource("MenuOverview-view.fxml")); + Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); + Scene scene = new Scene(root); + stage.setScene(scene); + stage.show(); + } @FXML protected ArrayList getLabelValueWithRadio(ActionEvent event) diff --git a/target/classes/com/example/vpr_javafx/ChangeOrder-view.fxml b/target/classes/com/example/vpr_javafx/ChangeOrder-view.fxml new file mode 100644 index 0000000..0249d91 --- /dev/null +++ b/target/classes/com/example/vpr_javafx/ChangeOrder-view.fxml @@ -0,0 +1,12 @@ + + + + + + + +