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

@ -24,7 +24,7 @@ public class TodoList {
/**
* Instantiates a new Todo list.
*
* @param name the name
* @param name the name
* @param changeable Can the name be changed?
*/
public TodoList(String name, boolean changeable) {
@ -36,8 +36,8 @@ public class TodoList {
/**
* Instantiates a new Todo list.
*
* @param uuid the uuid
* @param name the name
* @param uuid the uuid
* @param name the name
* @param changeable Can the name be changed?
*/
protected TodoList(String uuid, String name, boolean changeable) {

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

Loading…
Cancel
Save