Edit and save existing todo entries

main
Thomas Battermann 10 years ago
parent d2bb4fb5e6
commit 29815455ce

@ -12,6 +12,7 @@ import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
@ -257,6 +258,16 @@ public class Controller {
n.setOnMouseReleased(event -> Platform.exit());
}
this.primaryStage.setOnCloseRequest(event -> Platform.exit());
n = primaryStage.getScene().lookup("#todoDetailSave");
if ( n != null && n instanceof Button) {
n.setOnMouseClicked(event -> this.saveTodoEntry());
n.setOnKeyPressed(event -> this.saveTodoEntry());
}
n = primaryStage.getScene().lookup("#todoDetailDueDate");
if (n != null && n instanceof CheckBox) {
((CheckBox) n).setOnAction(event -> this.detailUpdateDueDatePicker());
}
// TODO
}
private void updateSelectedTodoList() {
@ -309,12 +320,22 @@ public class Controller {
return;
if(dueDate) {
((DatePicker) n).setValue( LocalDateTime.ofInstant(this.currentTodo.getDueDate().getTime().toInstant(), ZoneId.systemDefault()).toLocalDate() );
n.setDisable(false);
}else{
((DatePicker) n).setValue(null);
n.setDisable(true);
}
// time
n = primaryStage.getScene().lookup("#todoDetailTime");
if ( n == null || !(n instanceof TextField))
return;
((TextField) n).setText(this.currentTodo.getTime());
if ( dueDate ) {
((TextField) n).setText(this.currentTodo.getTime() );
n.setDisable(false);
}else{
n.setDisable(true);
((TextField) n).setText("00:00");
}
}
private void updateStatusLine(String text) {
@ -327,7 +348,6 @@ public class Controller {
}
private void showSaveAs() {
// TODO
Stage save = new Stage();
save.setScene(scenes.get("saveAs"));
save.setTitle("Save as ...");
@ -349,4 +369,76 @@ public class Controller {
}
});
}
private void saveTodoEntry() {
Node lv = primaryStage.getScene().lookup("#todos");
if ( lv == null || !(lv instanceof ListView)) {
this.updateStatusLine("Couldt get todo-ListView!");
return;
}
// title
Node n = primaryStage.getScene().lookup("#todoDetailTitle");
if ( n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldnt load data from todoDetailTitle");
return;
}
this.currentTodo.setTitle(((TextField) n).getText());
// description
n = primaryStage.getScene().lookup("#todoDetailDescription");
if ( n == null || !(n instanceof TextArea)) {
this.updateStatusLine("Couldnt load data from todoDetailDescription");
return;
}
this.currentTodo.setComment(((TextArea) n).getText());
// date
n = primaryStage.getScene().lookup("#todoDetailDueDate");
if ( n == null || !(n instanceof CheckBox)) {
this.updateStatusLine("Couldnt load data from todoDetailDueDate");
return;
}
if ( !((CheckBox) n).isSelected() ) {
this.currentTodo.setDueDate(null);
this.updateStatusLine("Item updated!");
this.todos.add(this.currentTodo);
return;
}
n = primaryStage.getScene().lookup("#todoDetailDate");
if ( n == null || !(n instanceof DatePicker)) {
this.updateStatusLine("Couldnt load data from todoDetailDate");
return;
}
LocalDate dd = ((DatePicker) n).getValue();
// time
n = primaryStage.getScene().lookup("#todoDetailTime");
if ( n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldnt load data from todoDetailDate");
return;
}
if ( !this.currentTodo.validateTime(((TextField) n).getText())) {
this.updateStatusLine("Invalid time format, use HH:MM!");
return;
}
this.currentTodo.setDueDate(dd, ((TextField) n).getText());
this.updateStatusLine("Item updated!");
}
private void detailUpdateDueDatePicker() {
Node n = primaryStage.getScene().lookup("#todoDetailDueDate");
if ( n == null || !(n instanceof CheckBox)) {
this.updateStatusLine("Couldnt load data from todoDetailDueDate");
return;
}
boolean enable = ((CheckBox) n).isSelected();
n = primaryStage.getScene().lookup("#todoDetailDate");
if ( n == null || !(n instanceof DatePicker)) {
this.updateStatusLine("Couldnt load data from todoDetailDate");
return;
}
n.setDisable(!enable);
n = primaryStage.getScene().lookup("#todoDetailTime");
if ( n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldnt load data from todoDetailTime");
return;
}
n.setDisable(!enable);
}
}

@ -1,7 +1,9 @@
package de.t_battermann.dhbw.todolist;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.UUID;
/**
@ -154,10 +156,35 @@ public class Todo {
public String getTime() {
SimpleDateFormat format = new SimpleDateFormat();
format.applyPattern("yyyyMMdd'T'HH:mm:ssZ");
format.applyPattern("HH:mm");
return this.getDueDate() != null ? format.format(this.getDueDate().getTime()) : "00:00";
}
public boolean validateTime(String time) {
//return time.matches("((?<h>\\d{1,2}):(?<m>\\d{1,2})(:\\d{1,2})?|(?<h2>\\d{2})(?<m2>\\d{0,2})|(?<h3>)\\d)");
return time.matches("([0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2})?|[0-9]{1,4})");
}
public void setDueDate(LocalDate date, String time) {
Calendar nd = new GregorianCalendar();
int hour = 0;
int minute = 0;
if ( time.matches("\\d{1,2}:\\d{1,2}(:\\d{1,2})?") ) {
String t[] = time.split(":", 3);
hour = Integer.parseInt(t[0]);
minute = Integer.parseInt(t[1]);
}else if( time.matches("\\d{1,4}") ) {
if ( time.length() > 2 ) {
hour = Integer.parseInt(time.substring(0, 2));
minute = Integer.parseInt(time.substring(2, 2));
}else{
hour = Integer.parseInt( time );
}
}
nd.set(date.getYear(), date.getMonthValue(), date.getDayOfMonth(), hour<24?hour:0, minute<60?minute:0);
this.dueDate = nd;
}
@Override
public String toString() {
return this.getTitle();

@ -47,8 +47,6 @@ public class User implements Serializable {
this.password = hashedPassword;
this.email = email;
this.todoLists = new LinkedList<>();
TodoList tmp = new TodoList("Default", false);
todoLists.add(tmp);
}
/**

Loading…
Cancel
Save