delete tasks
This commit is contained in:
parent
6b7a6f095d
commit
df19edb25a
|
@ -218,6 +218,7 @@ public class CropDetailController {
|
|||
setIconToButton(edit, "editIcon.png");
|
||||
setIconToButton(delete, "deleteIcon.png");
|
||||
edit.setOnAction(getEditTaskEvent(task));
|
||||
delete.setOnAction(deleteTask(task));
|
||||
|
||||
hBox.getChildren().addAll(taskName, taskDescription, edit, delete);
|
||||
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 {
|
||||
Dialog<Task> dialog = new Dialog<>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,10 @@ public class TaskTemplate {
|
|||
public Task generateTask(LocalDate realStartDate, long cropId) {
|
||||
LocalDate endDate = relativeEndDate != null ? realStartDate.plusDays(relativeEndDate) : null;
|
||||
|
||||
if (interval == null) {
|
||||
this.interval = 0;
|
||||
}
|
||||
|
||||
return new Task(name, description, realStartDate.plusDays(relativeStartDate), cropId)
|
||||
.withInterval(interval)
|
||||
.withEndDate(endDate);
|
||||
|
|
Loading…
Reference in New Issue