Added a lot of debug output :-)

main
Thomas Battermann 10 years ago committed by Thomas Ba
parent 0b04a58058
commit bb55aef369

@ -12,7 +12,6 @@ import javafx.stage.Stage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
@ -37,6 +36,7 @@ public class Controller {
* Initialize new empty * Initialize new empty
*/ */
public void initEmpty() { public void initEmpty() {
ErrorPrinter.printInfo("initEmpty > Initialized empty database");
this.users = new TreeMap<>(); this.users = new TreeMap<>();
} }
@ -60,6 +60,7 @@ public class Controller {
File f = new File(filename); File f = new File(filename);
if ( f.isDirectory() ) { if ( f.isDirectory() ) {
this.updateStatusLine("Couldnt write to file '" + filename + "'"); this.updateStatusLine("Couldnt write to file '" + filename + "'");
ErrorPrinter.printError("export > Couldnt write to file '" + filename + "'");
return false; return false;
} }
ExportHandler e; ExportHandler e;
@ -71,11 +72,13 @@ public class Controller {
try { try {
e.exportToFile(this.users, f); e.exportToFile(this.users, f);
} catch (IOException e1) { } catch (IOException e1) {
this.updateStatusLine("Couldt write to file!"); this.updateStatusLine("Couldnt write to file '" + filename + "'");
ErrorPrinter.printError("export > Couldt write to file '" + filename + "'");
e1.printStackTrace(); e1.printStackTrace();
return false; return false;
} }
this.updateStatusLine("Saved data to'"+filename+"'"); this.updateStatusLine("Saved data to'"+filename+"'");
ErrorPrinter.printInfo("export > Saved data to'"+filename+"'");
return true; return true;
} }
this.updateStatusLine("No filename given. Please choose one!"); this.updateStatusLine("No filename given. Please choose one!");
@ -95,8 +98,9 @@ public class Controller {
try { try {
primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("openFile.fxml")),500,150)); primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("openFile.fxml")),500,150));
} catch (IOException e) { } catch (IOException e) {
this.printError("Couldnt open file open window!"); ErrorPrinter.printError("showLoadFileDialog > Couldt open window 'openFile'! Goodbye!");
e.printStackTrace(); e.printStackTrace();
Platform.exit();
return; return;
} }
primaryStage.show(); primaryStage.show();
@ -109,11 +113,11 @@ public class Controller {
this.initFromFile(((TextField) n).getText()); this.initFromFile(((TextField) n).getText());
this.showLoginDialog(); this.showLoginDialog();
} catch (InvalidDataException | IOException e1) { } catch (InvalidDataException | IOException e1) {
this.printError("Cant read file '" + this.filename + "'"); ErrorPrinter.printError("showLoadFileDialog > Cant read file '" + this.filename + "'");
e1.printStackTrace(); e1.printStackTrace();
} }
}else{ }else{
this.printError("Didnt find #openFilePath!"); ErrorPrinter.printWarning("showLoadFileDialog > Didnt find element #openFilePath!");
} }
}); });
b = (Button) primaryStage.getScene().lookup("#openFileNew"); b = (Button) primaryStage.getScene().lookup("#openFileNew");
@ -132,8 +136,9 @@ public class Controller {
try { try {
primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("login.fxml")),500,350)); primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("login.fxml")),500,350));
} catch (IOException e) { } catch (IOException e) {
this.printError("Failed to open login window!"); ErrorPrinter.printError("showLoginDialog > Failed to open window 'login'! Goodbye!");
e.printStackTrace(); e.printStackTrace();
Platform.exit();
return; return;
} }
TitledPane a = (TitledPane) primaryStage.getScene().lookup(users.isEmpty() ? "#createNewUserPane" : "#loginPane"); TitledPane a = (TitledPane) primaryStage.getScene().lookup(users.isEmpty() ? "#createNewUserPane" : "#loginPane");
@ -151,7 +156,7 @@ public class Controller {
if (m != null && m instanceof TextField) { if (m != null && m instanceof TextField) {
name = ((TextField) m).getText(); name = ((TextField) m).getText();
} else { } else {
this.printError("'#loginUsername' not found!"); ErrorPrinter.printWarning("showLoginDialog > Didnt find element #loginUsername!");
return; return;
} }
m = primaryStage.getScene().lookup("#loginPassword"); m = primaryStage.getScene().lookup("#loginPassword");
@ -168,11 +173,11 @@ public class Controller {
l.setText("Invalid credentials!"); l.setText("Invalid credentials!");
} }
} else { } else {
l.setText("Invalid credentials! 1"); l.setText("Invalid credentials!");
} }
}); });
}else{ }else{
this.printError("'#loginButton' not found!"); ErrorPrinter.printWarning("showLoginDialog > Didnt find element #loginButton!");
} }
n = primaryStage.getScene().lookup("#registerButton"); n = primaryStage.getScene().lookup("#registerButton");
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
@ -226,7 +231,7 @@ public class Controller {
this.showMainWindow(); this.showMainWindow();
}); });
}else{ }else{
this.printError("'#registerButton' not found!"); ErrorPrinter.printWarning("showLoginDialog > Didnt find element #registerButton!");
} }
} }
@ -235,8 +240,9 @@ public class Controller {
try { try {
primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("main.fxml")),600,500)); primaryStage.setScene(new Scene(FXMLLoader.load(getClass().getResource("main.fxml")),600,500));
} catch (IOException e) { } catch (IOException e) {
this.printError("Failed to open window!"); ErrorPrinter.printError("showMainWindow > Failed to open window 'main'! Goodbye!");
e.printStackTrace(); e.printStackTrace();
Platform.exit();
return; return;
} }
Node n = primaryStage.getScene().lookup("#todoLists"); Node n = primaryStage.getScene().lookup("#todoLists");
@ -247,6 +253,8 @@ public class Controller {
lv.getSelectionModel().selectedIndexProperty().addListener(event -> { lv.getSelectionModel().selectedIndexProperty().addListener(event -> {
this.updateSelectedTodoList(); this.updateSelectedTodoList();
}); });
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoLists'");
} }
this.todos = new ObservableListWrapper<>(currentUser.getTodoList("Default").getTodos()); this.todos = new ObservableListWrapper<>(currentUser.getTodoList("Default").getTodos());
n = primaryStage.getScene().lookup("#todos"); n = primaryStage.getScene().lookup("#todos");
@ -256,6 +264,8 @@ public class Controller {
lv.getSelectionModel().selectedIndexProperty().addListener(event -> { lv.getSelectionModel().selectedIndexProperty().addListener(event -> {
this.updateSelectedTodo(); this.updateSelectedTodo();
}); });
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todos'");
} }
n = primaryStage.getScene().lookup("#menuSave"); n = primaryStage.getScene().lookup("#menuSave");
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
@ -266,23 +276,33 @@ public class Controller {
this.showSaveAs(); this.showSaveAs();
} }
}); });
}else{
ErrorPrinter.printWarning("showMainWindow > Coulnt find element '#menuSave'");
} }
n = primaryStage.getScene().lookup("#menuSaveAs"); n = primaryStage.getScene().lookup("#menuSaveAs");
if ( n != null && n instanceof Button ) { if ( n != null && n instanceof Button ) {
((Button) n).setOnAction(event -> this.showSaveAs()); ((Button) n).setOnAction(event -> this.showSaveAs());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#menuSaveAs'");
} }
n = primaryStage.getScene().lookup("#menuClose"); n = primaryStage.getScene().lookup("#menuClose");
if ( n != null && n instanceof Button ) { if ( n != null && n instanceof Button ) {
((Button) n).setOnAction(event -> Platform.exit()); ((Button) n).setOnAction(event -> Platform.exit());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#menuClose'");
} }
this.primaryStage.setOnCloseRequest(event -> Platform.exit()); this.primaryStage.setOnCloseRequest(event -> Platform.exit());
n = primaryStage.getScene().lookup("#todoDetailSave"); n = primaryStage.getScene().lookup("#todoDetailSave");
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> this.saveTodoEntry()); ((Button) n).setOnAction(event -> this.saveTodoEntry());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoDetailSave'");
} }
n = primaryStage.getScene().lookup("#todoDetailDueDate"); n = primaryStage.getScene().lookup("#todoDetailDueDate");
if (n != null && n instanceof CheckBox) { if (n != null && n instanceof CheckBox) {
((CheckBox) n).setOnAction(event -> this.detailUpdateDueDatePicker()); ((CheckBox) n).setOnAction(event -> this.detailUpdateDueDatePicker());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoDetailDueDate'");
} }
// handle new TodoList // handle new TodoList
n = primaryStage.getScene().lookup("#todoListNew"); n = primaryStage.getScene().lookup("#todoListNew");
@ -291,6 +311,8 @@ public class Controller {
this.buttonAction = "new"; this.buttonAction = "new";
this.showTodoListEdit(); this.showTodoListEdit();
}); });
}else{
ErrorPrinter.printWarning("showMainWindow > Coulnt find element '#todoListNew'");
} }
// handle edit TodoList // handle edit TodoList
n = primaryStage.getScene().lookup("#todoListEdit"); n = primaryStage.getScene().lookup("#todoListEdit");
@ -299,61 +321,82 @@ public class Controller {
this.buttonAction = "edit"; this.buttonAction = "edit";
this.showTodoListEdit(); this.showTodoListEdit();
}); });
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoListEdit'");
} }
// handle delete TodoList // handle delete TodoList
n = primaryStage.getScene().lookup("#todoListDelete"); n = primaryStage.getScene().lookup("#todoListDelete");
if( n != null && n instanceof Button) { if( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showDeleteList()); ((Button) n).setOnAction(event -> showDeleteList());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoListDelete'");
} }
// toggle todo // toggle todo
n = primaryStage.getScene().lookup("#todoToggleDone"); n = primaryStage.getScene().lookup("#todoToggleDone");
if ( n!= null && n instanceof ToggleButton) { if ( n!= null && n instanceof ToggleButton) {
((ToggleButton) n).setOnAction(event -> toggleDone()); ((ToggleButton) n).setOnAction(event -> toggleDone());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoToggleDone'");
} }
// toggle star // toggle star
n = primaryStage.getScene().lookup("#todoToggleStar"); n = primaryStage.getScene().lookup("#todoToggleStar");
if ( n!= null && n instanceof ToggleButton) { if ( n!= null && n instanceof ToggleButton) {
((ToggleButton) n).setOnAction(event -> toggleStar()); ((ToggleButton) n).setOnAction(event -> toggleStar());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoToggleStar'");
} }
// add new todo item // add new todo item
n = primaryStage.getScene().lookup("#todoNew"); n = primaryStage.getScene().lookup("#todoNew");
if ( n!= null && n instanceof Button) { if ( n!= null && n instanceof Button) {
((Button) n).setOnAction(event -> newTodoItem()); ((Button) n).setOnAction(event -> newTodoItem());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoNew'");
} }
// delete todo item // delete todo item
n = primaryStage.getScene().lookup("#todoDelete"); n = primaryStage.getScene().lookup("#todoDelete");
if ( n != null && n instanceof Button ) { if ( n != null && n instanceof Button ) {
((Button) n).setOnAction(event -> showDeleteItem()); ((Button) n).setOnAction(event -> showDeleteItem());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoDelete'");
} }
// change password // change password
n = primaryStage.getScene().lookup("#menuChangePassword"); n = primaryStage.getScene().lookup("#menuChangePassword");
if ( n != null && n instanceof Button ) { if ( n != null && n instanceof Button ) {
((Button) n).setOnAction(event -> showChangePassword()); ((Button) n).setOnAction(event -> showChangePassword());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#menuChangePassword'");
} }
// change eMail // change eMail
n = primaryStage.getScene().lookup("#menuChangeEmail"); n = primaryStage.getScene().lookup("#menuChangeEmail");
if ( n != null && n instanceof Button ) { if ( n != null && n instanceof Button ) {
((Button) n).setOnAction(event -> showChangeEmail()); ((Button) n).setOnAction(event -> showChangeEmail());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#menuChangeEmail'");
} }
n = primaryStage.getScene().lookup("#menuLogout"); n = primaryStage.getScene().lookup("#menuLogout");
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showLoginDialog()); ((Button) n).setOnAction(event -> showLoginDialog());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#menuLogout'");
} }
} }
private void updateSelectedTodoList() { private void updateSelectedTodoList() {
Node n = primaryStage.getScene().lookup("#todoLists"); Node n = primaryStage.getScene().lookup("#todoLists");
if ( n == null || !(n instanceof ListView) ) { if ( n == null || !(n instanceof ListView) ) {
ErrorPrinter.printWarning("updateSelectedTodoList > updateSelectedTodoList > Couldnt find element '#todoLists'");
return; return;
} }
ListView l = (ListView) n; ListView l = (ListView) n;
n = primaryStage.getScene().lookup("#todos"); n = primaryStage.getScene().lookup("#todos");
if ( n == null || !(n instanceof ListView)) { if ( n == null || !(n instanceof ListView)) {
ErrorPrinter.printWarning("updateSelectedTodoList > updateSelectedTodoList > Couldnt find element '#todos'");
return; return;
} }
ListView<Todo> lt = (ListView) n; ListView<Todo> lt = (ListView) n;
if ( l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList ) { if ( l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList ) {
TodoList t = (TodoList) l.getSelectionModel().getSelectedItem(); TodoList t = (TodoList) l.getSelectionModel().getSelectedItem();
primaryStage.setTitle("TodoList :: " + currentUser.getUsername() + " > " + t.getName());
this.todos = new ObservableListWrapper<>(t.getTodos()); this.todos = new ObservableListWrapper<>(t.getTodos());
lt.setItems(this.todos); lt.setItems(this.todos);
lt.getSelectionModel().select(0); lt.getSelectionModel().select(0);
@ -382,24 +425,32 @@ public class Controller {
} }
// title // title
n = primaryStage.getScene().lookup("#todoDetailTitle"); n = primaryStage.getScene().lookup("#todoDetailTitle");
if ( n == null || !(n instanceof TextField)) if ( n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldnt find element '#todoDetailTitle'");
return; return;
}
((TextField) n).setText( this.currentTodo == null ? "" : this.currentTodo.getTitle() ); ((TextField) n).setText( this.currentTodo == null ? "" : this.currentTodo.getTitle() );
// comment // comment
n = primaryStage.getScene().lookup("#todoDetailDescription"); n = primaryStage.getScene().lookup("#todoDetailDescription");
if ( n == null || !(n instanceof TextArea) ) if ( n == null || !(n instanceof TextArea) ) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldnt find element '#todoDetailDescription'");
return; return;
}
((TextArea) n).setText( this.currentTodo == null ? "" : this.currentTodo.getComment() ); ((TextArea) n).setText( this.currentTodo == null ? "" : this.currentTodo.getComment() );
// if dueDate set: // if dueDate set:
n = primaryStage.getScene().lookup("#todoDetailDueDate"); n = primaryStage.getScene().lookup("#todoDetailDueDate");
if ( n == null || !(n instanceof CheckBox) ) if ( n == null || !(n instanceof CheckBox) ) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldnt find element '#todoDetailDueDate'");
return; return;
}
boolean dueDate = this.currentTodo != null && this.currentTodo.getDueDate() != null; boolean dueDate = this.currentTodo != null && this.currentTodo.getDueDate() != null;
((CheckBox) n).setSelected(dueDate); ((CheckBox) n).setSelected(dueDate);
// datePicker // datePicker
n = primaryStage.getScene().lookup("#todoDetailDate"); n = primaryStage.getScene().lookup("#todoDetailDate");
if( n == null || !(n instanceof DatePicker)) if( n == null || !(n instanceof DatePicker)) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldnt find element '#todoDetailDate'");
return; return;
}
if(dueDate) { if(dueDate) {
((DatePicker) n).setValue( LocalDateTime.ofInstant(this.currentTodo.getDueDate().getTime().toInstant(), ZoneId.systemDefault()).toLocalDate() ); ((DatePicker) n).setValue( LocalDateTime.ofInstant(this.currentTodo.getDueDate().getTime().toInstant(), ZoneId.systemDefault()).toLocalDate() );
n.setDisable(false); n.setDisable(false);
@ -409,8 +460,10 @@ public class Controller {
} }
// time // time
n = primaryStage.getScene().lookup("#todoDetailTime"); n = primaryStage.getScene().lookup("#todoDetailTime");
if ( n == null || !(n instanceof TextField)) if ( n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("updateSelectedTodo > Couldnt find element '#todoDetailTime'");
return; return;
}
if ( dueDate ) { if ( dueDate ) {
((TextField) n).setText(this.currentTodo.getTime() ); ((TextField) n).setText(this.currentTodo.getTime() );
n.setDisable(false); n.setDisable(false);
@ -422,11 +475,15 @@ public class Controller {
n = primaryStage.getScene().lookup("#todoToggleStar"); n = primaryStage.getScene().lookup("#todoToggleStar");
if ( n != null && n instanceof ToggleButton ) { if ( n != null && n instanceof ToggleButton ) {
((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isPrio()); ((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isPrio());
}else{
ErrorPrinter.printWarning("updateSelectedTodo > Couldnt find element '#todoToggleStar'");
} }
// done // done
n = primaryStage.getScene().lookup("#todoToggleDone"); n = primaryStage.getScene().lookup("#todoToggleDone");
if ( n != null && n instanceof ToggleButton) { if ( n != null && n instanceof ToggleButton) {
((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isDone()); ((ToggleButton) n).setSelected(currentTodo != null && currentTodo.isDone());
}else{
ErrorPrinter.printWarning("updateSelectedTodo > Couldnt find element '#todoToggleDone'");
} }
} }
@ -435,7 +492,7 @@ public class Controller {
if ( n != null && n instanceof Label) { if ( n != null && n instanceof Label) {
((Label) n).setText(text); ((Label) n).setText(text);
}else{ }else{
this.printError("Couldnt find status line!"); ErrorPrinter.printWarning("updateStatusLine > Couldnt find element '#statusLine'");
} }
} }
@ -445,6 +502,7 @@ public class Controller {
save.setScene(new Scene(FXMLLoader.load(getClass().getResource("saveAs.fxml")),500,150)); save.setScene(new Scene(FXMLLoader.load(getClass().getResource("saveAs.fxml")),500,150));
} catch (IOException e) { } catch (IOException e) {
this.updateStatusLine("Failed to open window!"); this.updateStatusLine("Failed to open window!");
ErrorPrinter.printError("showSaveAs > Failed to open window 'saveAs'");
e.printStackTrace(); e.printStackTrace();
return; return;
} }
@ -480,12 +538,14 @@ public class Controller {
Node lv = primaryStage.getScene().lookup("#todos"); Node lv = primaryStage.getScene().lookup("#todos");
if ( lv == null || !(lv instanceof ListView)) { if ( lv == null || !(lv instanceof ListView)) {
this.updateStatusLine("Couldt get todo-ListView!"); this.updateStatusLine("Couldt get todo-ListView!");
ErrorPrinter.printWarning("saveTodoEntry > Didnt find element #todos!");
return; return;
} }
// title // title
Node n = primaryStage.getScene().lookup("#todoDetailTitle"); Node n = primaryStage.getScene().lookup("#todoDetailTitle");
if ( n == null || !(n instanceof TextField)) { if ( n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldnt load data from todoDetailTitle"); this.updateStatusLine("Couldnt load data from todoDetailTitle");
ErrorPrinter.printWarning("saveTodoEntry > Didnt find element #todoDetailTitle!");
return; return;
} }
this.currentTodo.setTitle(((TextField) n).getText()); this.currentTodo.setTitle(((TextField) n).getText());
@ -493,6 +553,7 @@ public class Controller {
n = primaryStage.getScene().lookup("#todoDetailDescription"); n = primaryStage.getScene().lookup("#todoDetailDescription");
if ( n == null || !(n instanceof TextArea)) { if ( n == null || !(n instanceof TextArea)) {
this.updateStatusLine("Couldnt load data from todoDetailDescription"); this.updateStatusLine("Couldnt load data from todoDetailDescription");
ErrorPrinter.printWarning("saveTodoEntry > Didnt find element #statusLine!");
return; return;
} }
this.currentTodo.setComment(((TextArea) n).getText()); this.currentTodo.setComment(((TextArea) n).getText());
@ -500,6 +561,7 @@ public class Controller {
n = primaryStage.getScene().lookup("#todoDetailDueDate"); n = primaryStage.getScene().lookup("#todoDetailDueDate");
if ( n == null || !(n instanceof CheckBox)) { if ( n == null || !(n instanceof CheckBox)) {
this.updateStatusLine("Couldnt load data from todoDetailDueDate"); this.updateStatusLine("Couldnt load data from todoDetailDueDate");
ErrorPrinter.printWarning("saveTodoEntry > Didnt find element #todoDetailDueDate!");
return; return;
} }
if ( !((CheckBox) n).isSelected() ) { if ( !((CheckBox) n).isSelected() ) {
@ -508,6 +570,7 @@ public class Controller {
n = primaryStage.getScene().lookup("#todoDetailDate"); n = primaryStage.getScene().lookup("#todoDetailDate");
if (n == null || !(n instanceof DatePicker)) { if (n == null || !(n instanceof DatePicker)) {
this.updateStatusLine("Couldnt load data from todoDetailDate"); this.updateStatusLine("Couldnt load data from todoDetailDate");
ErrorPrinter.printWarning("saveTodoEntry > Didnt find element #todoDetailDate!");
return; return;
} }
LocalDate dd = ((DatePicker) n).getValue(); LocalDate dd = ((DatePicker) n).getValue();
@ -515,6 +578,7 @@ public class Controller {
n = primaryStage.getScene().lookup("#todoDetailTime"); n = primaryStage.getScene().lookup("#todoDetailTime");
if (n == null || !(n instanceof TextField)) { if (n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldnt load data from todoDetailDate"); this.updateStatusLine("Couldnt load data from todoDetailDate");
ErrorPrinter.printWarning("saveTodoEntry > Didnt find element #todoDetailDate!");
return; return;
} }
if (!this.currentTodo.validateTime(((TextField) n).getText())) { if (!this.currentTodo.validateTime(((TextField) n).getText())) {
@ -526,22 +590,26 @@ public class Controller {
this.notifyList(this.todos, this.currentTodo); this.notifyList(this.todos, this.currentTodo);
this.updateStatusLine("Item updated!"); this.updateStatusLine("Item updated!");
} }
private void detailUpdateDueDatePicker() { private void detailUpdateDueDatePicker() {
Node n = primaryStage.getScene().lookup("#todoDetailDueDate"); Node n = primaryStage.getScene().lookup("#todoDetailDueDate");
if ( n == null || !(n instanceof CheckBox)) { if ( n == null || !(n instanceof CheckBox)) {
this.updateStatusLine("Couldnt load data from todoDetailDueDate"); this.updateStatusLine("Couldnt load data from todoDetailDueDate");
ErrorPrinter.printWarning("detailUpdateDueDatePicker > Didnt find element #todoDetailDueDate!");
return; return;
} }
boolean enable = ((CheckBox) n).isSelected(); boolean enable = ((CheckBox) n).isSelected();
n = primaryStage.getScene().lookup("#todoDetailDate"); n = primaryStage.getScene().lookup("#todoDetailDate");
if ( n == null || !(n instanceof DatePicker)) { if ( n == null || !(n instanceof DatePicker)) {
this.updateStatusLine("Couldnt load data from todoDetailDate"); this.updateStatusLine("Couldnt load data from todoDetailDate");
ErrorPrinter.printWarning("detailUpdateDueDatePicker > Didnt find element #todoDetailDue!");
return; return;
} }
n.setDisable(!enable); n.setDisable(!enable);
n = primaryStage.getScene().lookup("#todoDetailTime"); n = primaryStage.getScene().lookup("#todoDetailTime");
if ( n == null || !(n instanceof TextField)) { if ( n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldnt load data from todoDetailTime"); this.updateStatusLine("Couldnt load data from todoDetailTime");
ErrorPrinter.printWarning("detailUpdateDueDatePicker > Didnt find element #todoDetailTime!");
return; return;
} }
n.setDisable(!enable); n.setDisable(!enable);
@ -551,6 +619,7 @@ public class Controller {
Node n = this.primaryStage.getScene().lookup("#todoListToolBar"); Node n = this.primaryStage.getScene().lookup("#todoListToolBar");
if ( n == null || !(n instanceof ToolBar)) { if ( n == null || !(n instanceof ToolBar)) {
this.updateStatusLine("Couldnt get 'todoListToolBar'"); this.updateStatusLine("Couldnt get 'todoListToolBar'");
ErrorPrinter.printWarning("showTodoListEdit > Didnt find element #todoListToolBar!");
return; return;
} }
n.setDisable(false); n.setDisable(false);
@ -559,17 +628,19 @@ public class Controller {
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> this.saveTodoListEdit()); ((Button) n).setOnAction(event -> this.saveTodoListEdit());
}else{ }else{
this.printError("Couldnt read 'todoListNewNameSave'"); ErrorPrinter.printError("showTodoListEdit > Couldnt read 'todoListNewNameSave'");
} }
n = primaryStage.getScene().lookup("#todoListNewName"); n = primaryStage.getScene().lookup("#todoListNewName");
if ( n == null || !(n instanceof TextField)) { if ( n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldnt get 'todoListNewName'"); this.updateStatusLine("Couldnt get 'todoListNewName'");
ErrorPrinter.printWarning("showTodoListEdit > Didnt find element #todoListNewName!");
return; return;
} }
if ( this.buttonAction.equals("edit")) { if ( this.buttonAction.equals("edit")) {
Node l = primaryStage.getScene().lookup("#todoLists"); Node l = primaryStage.getScene().lookup("#todoLists");
if ( l == null || !(l instanceof ListView) ) { if ( l == null || !(l instanceof ListView) ) {
this.updateStatusLine("Couldnt get 'todoLists'"); this.updateStatusLine("Couldnt get 'todoLists'");
ErrorPrinter.printWarning("showTodoListEdit > Didnt find element #todoLists!");
return; return;
} }
ListView lv = (ListView) l; ListView lv = (ListView) l;
@ -582,10 +653,12 @@ public class Controller {
((TextField) n).setText("New TodoList"); ((TextField) n).setText("New TodoList");
} }
} }
private void saveTodoListEdit() { private void saveTodoListEdit() {
Node n = primaryStage.getScene().lookup("#todoListNewName"); Node n = primaryStage.getScene().lookup("#todoListNewName");
if ( n == null || !(n instanceof TextField)) { if ( n == null || !(n instanceof TextField)) {
this.updateStatusLine("Couldnt get 'todoListNewName'"); this.updateStatusLine("Couldnt get 'todoListNewName'");
ErrorPrinter.printWarning("saveTodoListEdit > Didnt find element #todoListNewName!");
return; return;
} }
String name = ((TextField) n).getText(); String name = ((TextField) n).getText();
@ -609,50 +682,57 @@ public class Controller {
} }
n = this.primaryStage.getScene().lookup("#todoListToolBar"); n = this.primaryStage.getScene().lookup("#todoListToolBar");
if ( n == null || !(n instanceof ToolBar)) { if ( n == null || !(n instanceof ToolBar)) {
ErrorPrinter.printWarning("saveTodoListEdit > Didnt find element #todoListToolBar!");
return; return;
} }
n.setDisable(true); n.setDisable(true);
n.setVisible(false); n.setVisible(false);
} }
private void toggleDone() { private void toggleDone() {
if(this.currentTodo == null) if(this.currentTodo == null)
return; return;
Node n = primaryStage.getScene().lookup("#todoToggleDone"); Node n = primaryStage.getScene().lookup("#todoToggleDone");
if ( n == null || !(n instanceof ToggleButton) ) { if ( n == null || !(n instanceof ToggleButton) ) {
this.printError("todoToggleDone not found."); ErrorPrinter.printWarning("toggleDone > Didnt find element #todoToggleDone!");
return; return;
} }
this.currentTodo.setDone(!this.currentTodo.isDone()); this.currentTodo.setDone(!this.currentTodo.isDone());
((ToggleButton) n).setSelected(this.currentTodo.isDone()); ((ToggleButton) n).setSelected(this.currentTodo.isDone());
} }
private void toggleStar() { private void toggleStar() {
if(this.currentTodo == null) if(this.currentTodo == null)
return; return;
Node n = primaryStage.getScene().lookup("#todoToggleStar"); Node n = primaryStage.getScene().lookup("#todoToggleStar");
if ( n == null || !(n instanceof ToggleButton) ) { if ( n == null || !(n instanceof ToggleButton) ) {
this.printError("todoToggleStar not found."); ErrorPrinter.printWarning("toggleStar > Didnt find element #todoToggleStar!");
return; return;
} }
this.currentTodo.setPrio(!this.currentTodo.isPrio()); this.currentTodo.setPrio(!this.currentTodo.isPrio());
((ToggleButton) n).setSelected(this.currentTodo.isPrio()); ((ToggleButton) n).setSelected(this.currentTodo.isPrio());
} }
private void newTodoItem() { private void newTodoItem() {
Todo t = new Todo("New Item", "Edit this item :-)"); Todo t = new Todo("New Item", "Edit this item :-)");
this.todos.add(t); this.todos.add(t);
this.updateStatusLine("Item added!"); this.updateStatusLine("Item added!");
Node n = primaryStage.getScene().lookup("#todos"); Node n = primaryStage.getScene().lookup("#todos");
if ( n == null || !(n instanceof ListView) ) { if ( n == null || !(n instanceof ListView) ) {
ErrorPrinter.printWarning("newTodoItem > Didnt find element #todos!");
return; return;
} }
((ListView) n).getSelectionModel().select(t); ((ListView) n).getSelectionModel().select(t);
((ListView) n).scrollTo(t); ((ListView) n).scrollTo(t);
} }
private void showDeleteItem() { private void showDeleteItem() {
Stage delete = new Stage(); Stage delete = new Stage();
try { try {
delete.setScene(new Scene(FXMLLoader.load(getClass().getResource("deleteTodoItem.fxml")))); delete.setScene(new Scene(FXMLLoader.load(getClass().getResource("deleteTodoItem.fxml"))));
} catch (IOException e) { } catch (IOException e) {
this.updateStatusLine("Failed to open window!"); this.updateStatusLine("Failed to open window!");
ErrorPrinter.printError("showDeleteItem > Failed to open window 'deleteTodoItem'!");
e.printStackTrace(); e.printStackTrace();
return; return;
} }
@ -669,17 +749,20 @@ public class Controller {
delete.close(); delete.close();
}); });
} }
private void showDeleteList() { private void showDeleteList() {
Stage delete = new Stage(); Stage delete = new Stage();
try { try {
delete.setScene(new Scene(FXMLLoader.load(getClass().getResource("deleteTodoItem.fxml")))); delete.setScene(new Scene(FXMLLoader.load(getClass().getResource("deleteTodoItem.fxml"))));
} catch (IOException e) { } catch (IOException e) {
this.updateStatusLine("Failed to open window!"); this.updateStatusLine("Failed to open window!");
ErrorPrinter.printError("showDeleteList > Failed to open window 'deleteList'!");
e.printStackTrace(); e.printStackTrace();
return; return;
} }
Node n = primaryStage.getScene().lookup("#todoLists"); Node n = primaryStage.getScene().lookup("#todoLists");
if (n == null || !(n instanceof ListView)) { if (n == null || !(n instanceof ListView)) {
ErrorPrinter.printWarning("showDeleteList > Didnt find element #todoLists!");
return; return;
} }
ListView l = (ListView) n; ListView l = (ListView) n;
@ -687,6 +770,7 @@ public class Controller {
if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) { if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) {
t = (TodoList) l.getSelectionModel().getSelectedItem(); t = (TodoList) l.getSelectionModel().getSelectedItem();
}else { }else {
ErrorPrinter.printWarning("showDeleteList > Didnt find selected item!");
return; return;
} }
delete.setTitle("Delete '"+t.getName()+"'"); delete.setTitle("Delete '"+t.getName()+"'");
@ -702,31 +786,33 @@ public class Controller {
delete.close(); delete.close();
}); });
} }
private void showChangePassword() { private void showChangePassword() {
Stage change = new Stage(); Stage change = new Stage();
try { try {
change.setScene(new Scene(FXMLLoader.load(getClass().getResource("changePassword.fxml")))); change.setScene(new Scene(FXMLLoader.load(getClass().getResource("changePassword.fxml"))));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
ErrorPrinter.printError("showChangePassword > Failed to open window 'changePassword'!");
return; return;
} }
change.setTitle("Change password"); change.setTitle("Change password");
change.show(); change.show();
Node n = change.getScene().lookup("#status"); Node n = change.getScene().lookup("#status");
if ( n == null || !(n instanceof Label)) { if ( n == null || !(n instanceof Label)) {
this.printError("Couldnt access status label"); ErrorPrinter.printWarning("showChangePassword > Didnt find element #status!");
return; return;
} }
Label status = (Label) n; Label status = (Label) n;
n = change.getScene().lookup("#abort"); n = change.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) { if ( n == null || !(n instanceof Button)) {
this.printError("Couldnt access abort button"); ErrorPrinter.printWarning("showChangePassword > Didnt find element #abort!");
return; return;
} }
((Button) n).setOnAction(event -> change.close()); ((Button) n).setOnAction(event -> change.close());
n = change.getScene().lookup("#save"); n = change.getScene().lookup("#save");
if ( n == null || !(n instanceof Button)) { if ( n == null || !(n instanceof Button)) {
this.printError("Couldnt access save button"); ErrorPrinter.printWarning("showChangePassword > Didnt find element #save!");
return; return;
} }
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
@ -734,7 +820,7 @@ public class Controller {
// validate passwords ... // validate passwords ...
Node l = change.getScene().lookup("#password"); Node l = change.getScene().lookup("#password");
if ( l == null || !(l instanceof PasswordField)) { if ( l == null || !(l instanceof PasswordField)) {
status.setText("Couldnt access password field!"); ErrorPrinter.printWarning("showChangePassword > Didnt find element #password!");
return; return;
} }
if (!currentUser.checkLoginData( ((PasswordField) l).getText() )) { if (!currentUser.checkLoginData( ((PasswordField) l).getText() )) {
@ -743,7 +829,7 @@ public class Controller {
} }
l = change.getScene().lookup("#newPassword"); l = change.getScene().lookup("#newPassword");
if ( l == null || !(l instanceof PasswordField)) { if ( l == null || !(l instanceof PasswordField)) {
status.setText("Couldnt access newPassword field!"); ErrorPrinter.printWarning("showChangePassword > Didnt find element #newPassword!");
return; return;
} }
pw = ((PasswordField)l).getText(); pw = ((PasswordField)l).getText();
@ -754,6 +840,7 @@ public class Controller {
l = change.getScene().lookup("#newPasswordRepeat"); l = change.getScene().lookup("#newPasswordRepeat");
if ( l == null || !(l instanceof PasswordField)) { if ( l == null || !(l instanceof PasswordField)) {
status.setText("Couldnt access newPasswordRepeat field!"); status.setText("Couldnt access newPasswordRepeat field!");
ErrorPrinter.printWarning("showChangePassword > Didnt find element #newPasswordRepeat!");
return; return;
} }
if ( !pw.equals( ((PasswordField) l).getText() )) { if ( !pw.equals( ((PasswordField) l).getText() )) {
@ -764,11 +851,13 @@ public class Controller {
change.close(); change.close();
}); });
} }
private void showChangeEmail() { private void showChangeEmail() {
Stage change = new Stage(); Stage change = new Stage();
try { try {
change.setScene(new Scene(FXMLLoader.load(getClass().getResource("changeEmail.fxml")))); change.setScene(new Scene(FXMLLoader.load(getClass().getResource("changeEmail.fxml"))));
} catch (IOException e) { } catch (IOException e) {
ErrorPrinter.printError("showChangeEmail > Failed to open window 'changePassword'!");
e.printStackTrace(); e.printStackTrace();
return; return;
} }
@ -776,33 +865,34 @@ public class Controller {
change.show(); change.show();
Node n = change.getScene().lookup("#status"); Node n = change.getScene().lookup("#status");
if ( n == null || !(n instanceof Label)) { if ( n == null || !(n instanceof Label)) {
this.printError("Couldnt access status label"); ErrorPrinter.printWarning("showChangeEmail > Didnt find element #status!");
return; return;
} }
Label status = (Label) n; Label status = (Label) n;
// load current email address // load current email address
n = change.getScene().lookup("#eMail"); n = change.getScene().lookup("#eMail");
if ( n == null || !(n instanceof TextField)) { if ( n == null || !(n instanceof TextField)) {
status.setText("Couldnt access eMail field!"); ErrorPrinter.printWarning("showChangeEmail > Didnt find element #eMail!");
return; return;
} }
((TextField) n).setText(this.currentUser.getEmail()); ((TextField) n).setText(this.currentUser.getEmail());
n = change.getScene().lookup("#eMailRepeat"); n = change.getScene().lookup("#eMailRepeat");
if ( n == null || !(n instanceof TextField)) { if ( n == null || !(n instanceof TextField)) {
status.setText("Couldnt access eMailRepeat field!"); ErrorPrinter.printWarning("showChangeEmail > Didnt find element #eMailRepeat!");
return; return;
} }
((TextField) n).setText(this.currentUser.getEmail()); ((TextField) n).setText(this.currentUser.getEmail());
// actions // actions
n = change.getScene().lookup("#abort"); n = change.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) { if ( n == null || !(n instanceof Button)) {
this.printError("Couldnt access abort button"); ErrorPrinter.printWarning("showChangeEmail > Didnt find element #abort!");
return; return;
} }
((Button) n).setOnAction(event -> change.close()); ((Button) n).setOnAction(event -> change.close());
n = change.getScene().lookup("#save"); n = change.getScene().lookup("#save");
if ( n == null || !(n instanceof Button)) { if ( n == null || !(n instanceof Button)) {
this.printError("Couldnt access save button"); ErrorPrinter.printWarning("showChangeEmail > Didnt find element #save!");
return; return;
} }
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
@ -811,6 +901,7 @@ public class Controller {
Node l = change.getScene().lookup("#eMail"); Node l = change.getScene().lookup("#eMail");
if ( l == null || !(l instanceof TextField)) { if ( l == null || !(l instanceof TextField)) {
status.setText("Couldnt access eMail field!"); status.setText("Couldnt access eMail field!");
ErrorPrinter.printWarning("showChangeEmail > Didnt find element #eMail!");
return; return;
} }
email = ((TextField) l).getText(); email = ((TextField) l).getText();
@ -821,6 +912,7 @@ public class Controller {
l = change.getScene().lookup("#eMailRepeat"); l = change.getScene().lookup("#eMailRepeat");
if ( l == null || !(l instanceof TextField)) { if ( l == null || !(l instanceof TextField)) {
status.setText("Couldnt access eMailRepeat field!"); status.setText("Couldnt access eMailRepeat field!");
ErrorPrinter.printWarning("showChangeEmail > Didnt find element #eMailRepeat!");
return; return;
} }
if ( !email.equals( ((TextField) l).getText() )) { if ( !email.equals( ((TextField) l).getText() )) {
@ -831,11 +923,6 @@ public class Controller {
change.close(); change.close();
}); });
} }
private void printError(String s) {
SimpleDateFormat format = new SimpleDateFormat();
format.applyPattern("yyyyMMdd'T'HH:mm:ssZ");
System.out.println("[" + format.format(GregorianCalendar.getInstance().getTime()) + "] " + s);
}
/** /**
* Notify a list about a changed item * Notify a list about a changed item
@ -853,4 +940,5 @@ public class Controller {
list.set(index, changedItem); list.set(index, changedItem);
} }
} }
} }

@ -0,0 +1,37 @@
package de.t_battermann.dhbw.todolist;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
/**
* Print error messages to the console
*/
public class ErrorPrinter {
public static void printError(String p, String s) {
SimpleDateFormat format = new SimpleDateFormat();
format.applyPattern("yyyyMMdd'T'HH:mm:ssZ");
System.err.println("[" + format.format(GregorianCalendar.getInstance().getTime()) + " " + p + "] " + s);
}
public static void printInfo(String p, String s) {
SimpleDateFormat format = new SimpleDateFormat();
format.applyPattern("yyyyMMdd'T'HH:mm:ssZ");
System.out.println("[" + format.format(GregorianCalendar.getInstance().getTime()) + " " + p + "] " + s);
}
public static void printInfo( String s) {
ErrorPrinter.printInfo("info", s);
}
public static void printError(String s) {
ErrorPrinter.printError("error", s);
}
public static void printDebug(String s) {
ErrorPrinter.printInfo("debug", s);
}
public static void printWarning(String s) {
ErrorPrinter.printError("warn", s);
}
}

@ -161,7 +161,6 @@ public class Todo {
} }
public boolean validateTime(String time) { 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})"); return time.matches("([0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2})?|[0-9]{1,4})");
} }

@ -3,13 +3,12 @@ package de.t_battermann.dhbw.todolist;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.validator.routines.EmailValidator; import org.apache.commons.validator.routines.EmailValidator;
import java.io.Serializable;
import java.util.*; import java.util.*;
/** /**
* This class contains all the users data. * This class contains all the users data.
*/ */
public class User implements Serializable { public class User {
private String username; private String username;
private String email; private String email;
private String password; private String password;
@ -95,7 +94,7 @@ public class User implements Serializable {
for(TodoList l: todoLists) for(TodoList l: todoLists)
if(l.getName().equals(name)) if(l.getName().equals(name))
return l; return l;
System.out.println("TodoList not found: " + name); ErrorPrinter.printDebug("TodoList not found: " + name);
return null; return null;
} }
@ -115,8 +114,7 @@ public class User implements Serializable {
* @return the boolean * @return the boolean
*/ */
public boolean checkLoginData(String password) { public boolean checkLoginData(String password) {
System.out.println("pw: " + password + " -> " + this.hashPassword(password)); ErrorPrinter.printDebug("checkLoginData > " + this.password + " <> " + this.hashPassword(password));
System.out.println("stored: " + this.password);
return this.hashPassword(password).equals(this.password); return this.hashPassword(password).equals(this.password);
} }
@ -126,16 +124,6 @@ public class User implements Serializable {
+ "eMail: " + email + "\n"; + "eMail: " + email + "\n";
} }
/**
* Add a todo list.
*
* @param name the name for the new list
* @return false if a list with the given name already exists
*/
public boolean addTodoList(String name) {
return this.addTodoList(new TodoList(name));
}
/** /**
* Add todo list. * Add todo list.
* *
@ -147,7 +135,7 @@ public class User implements Serializable {
this.todoLists.add(todoList); this.todoLists.add(todoList);
return true; return true;
} }
System.out.println("A TodoList named '" + todoList.getName() + "' already exists!"); ErrorPrinter.printDebug("addTodoList > A TodoList named '" + todoList.getName() + "' already exists!");
return false; return false;
} }
@ -171,7 +159,7 @@ public class User implements Serializable {
this.email = email; this.email = email;
return true; return true;
} }
System.out.println("Invalid eMail: '" + email + "'"); ErrorPrinter.printDebug("setEmail > Invalid eMail: '" + email + "'");
return false; return false;
} }

Loading…
Cancel
Save