package ch.makery.address; import java.io.File; import ch.makery.address.model.Abscence; import javafx.fxml.FXML; import javafx.scene.control.Dialogs; import javafx.stage.FileChooser; public class AbscenceListRoot { private AbscenceListController abscenceListController; public void setMainApp(MainApp mainApp){ } @FXML private void handleNouveau() { abscenceListController.getAbscenceData().clear(); abscenceListController.setAbscenceFilePath(null); } /** * Opens a FileChooser to let the user select an address book to load. */ @FXML private void handleOuvrir() { FileChooser fileChooser = new FileChooser(); // Set extension filter FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter( "XML files (*.xml)", "*.xml"); fileChooser.getExtensionFilters().add(extFilter); // Show save file dialog File file = fileChooser.showOpenDialog(null); if (file != null) { abscenceListController.loadAbscenceDataFromFile(file); } } /** * Saves the file to the abscence file that is currently open. If there is no * open file, the "save as" dialog is shown. */ @FXML private void handleEnregistrer() { File abscenceFile = abscenceListController.getAbscenceFilePath(); if (abscenceFile != null) { abscenceListController.saveAbscenceDataToFile(abscenceFile); } else { handleEnregistrerSous(); } } /** * Opens a FileChooser to let the user select a file to save to. */ @FXML private void handleEnregistrerSous() { FileChooser fileChooser = new FileChooser(); // Set extension filter FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter( "XML files (*.xml)", "*.xml"); fileChooser.getExtensionFilters().add(extFilter); // Show save file dialog File file = fileChooser.showSaveDialog(null); if (file != null) { // Make sure it has the correct extension if (!file.getPath().endsWith(".xml")) { file = new File(file.getPath() + ".xml"); } abscenceListController.saveAbscenceDataToFile(file); } } @FXML private void handleExit() { System.exit(0); } @FXML private void handleModifierAbscence() { Abscence selectedAbscence = abscenceListController.abscenceTable.getSelectionModel().getSelectedItem(); if (selectedAbscence != null) { boolean okClicked = abscenceListController.showAbscenceEdit(selectedAbscence); if (okClicked) { abscenceListController.refreshAbscenceTable(); abscenceListController.showAbscenceDetails(selectedAbscence); } } else { // Nothing selected Dialogs.showWarningDialog(null, "Veillez sélectionnez une personne dans la Table.", "Pas de Personne Sélectionnée", "Pas de Sélection"); } } /** * Called when the user clicks on the delete button. */ @FXML private void handleSupprimerAbscence() { int selectedIndex = abscenceListController.abscenceTable.getSelectionModel().getSelectedIndex(); if (selectedIndex >= 0) { abscenceListController.abscenceTable.getItems().remove(selectedIndex); } else { // Nothing selected Dialogs.showErrorDialog( null, "Please select a person in the table.", "No Person Selected", "No Selection"); } } }