delete tasks

This commit is contained in:
giavaphi 2022-11-24 23:55:54 +01:00
parent 6b7a6f095d
commit df19edb25a
2 changed files with 30 additions and 0 deletions

View File

@ -218,6 +218,7 @@ public class CropDetailController {
setIconToButton(edit, "editIcon.png"); setIconToButton(edit, "editIcon.png");
setIconToButton(delete, "deleteIcon.png"); setIconToButton(delete, "deleteIcon.png");
edit.setOnAction(getEditTaskEvent(task)); edit.setOnAction(getEditTaskEvent(task));
delete.setOnAction(deleteTask(task));
hBox.getChildren().addAll(taskName, taskDescription, edit, delete); hBox.getChildren().addAll(taskName, taskDescription, edit, delete);
return hBox; return hBox;
@ -260,6 +261,12 @@ public class CropDetailController {
}; };
} }
private EventHandler<ActionEvent> deleteTask(Task task) {
return (event) -> {
showDeleteTask(task);
};
}
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException { private void createTaskDialog(boolean newTask, Task givenTask) throws IOException {
Dialog<Task> dialog = new Dialog<>(); Dialog<Task> dialog = new Dialog<>();
dialog.setTitle("Set Task"); dialog.setTitle("Set Task");
@ -332,4 +339,23 @@ public class CropDetailController {
}); });
} }
} }
private void showDeleteTask(Task task) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Delete " + task.getName());
alert.setHeaderText("Are you sure want to delete this Task?");
alert.showAndWait()
.ifPresent(buttonType -> {
if (buttonType == ButtonType.OK) {
try {
gardenSchedule.removeTask(task);
setTaskListProperty(this.crop);
} catch (IOException e) {
// TODO: Show error alert
LOG.log(Level.SEVERE, "Could not remove crop.", e);
}
}
});
}
} }

View File

@ -48,6 +48,10 @@ public class TaskTemplate {
public Task generateTask(LocalDate realStartDate, long cropId) { public Task generateTask(LocalDate realStartDate, long cropId) {
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null; LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null;
if (interval == null) {
this.interval = 0;
}
return new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId) return new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId)
.withInterval(interval) .withInterval(interval)
.withEndDate(endDate); .withEndDate(endDate);