Delete a TodoList

Handle empty TodoLists correctly
Use setOnAction for Buttons
Bug fix: Login after a user was created
main
Thomas Battermann 10 years ago committed by Thomas Ba
parent 6b95491141
commit e5f1a76dca

@ -8,6 +8,7 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.io.File; import java.io.File;
@ -86,8 +87,11 @@ public class Controller {
e1.printStackTrace(); e1.printStackTrace();
return false; return false;
} }
this.updateStatusLine("Saved data to'"+this.filename+"'");
return true; return true;
} }
this.updateStatusLine("No filename given. Please choose one!");
this.showSaveAs();
return false; return false;
} }
@ -135,7 +139,7 @@ public class Controller {
// Log in // Log in
Node n = primaryStage.getScene().lookup("#loginButton"); Node n = primaryStage.getScene().lookup("#loginButton");
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
n.setOnMouseReleased(event -> { ((Button) n).setOnAction(event -> {
Label l = (Label) primaryStage.getScene().lookup("#labelHints"); Label l = (Label) primaryStage.getScene().lookup("#labelHints");
String name = null; String name = null;
String pass = null; String pass = null;
@ -168,7 +172,7 @@ public class Controller {
} }
n = primaryStage.getScene().lookup("#registerButton"); n = primaryStage.getScene().lookup("#registerButton");
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
n.setOnMouseReleased(event -> { ((Button) n).setOnAction(event -> {
Label l = (Label) primaryStage.getScene().lookup("#labelHintsCreateNewUser"); Label l = (Label) primaryStage.getScene().lookup("#labelHintsCreateNewUser");
// username // username
String username; String username;
@ -214,6 +218,8 @@ public class Controller {
currentUser = nu; currentUser = nu;
users.put(username, nu); users.put(username, nu);
this.todoLists = new ObservableSequentialListWrapper<>(currentUser.getTodoLists()); this.todoLists = new ObservableSequentialListWrapper<>(currentUser.getTodoLists());
// log in
this.showMainWindow();
}); });
}else{ }else{
this.printError("'#registerButton' not found!"); this.printError("'#registerButton' not found!");
@ -243,7 +249,7 @@ public class Controller {
} }
n = primaryStage.getScene().lookup("#menuSave"); n = primaryStage.getScene().lookup("#menuSave");
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
n.setOnMouseReleased(event -> { ((Button) n).setOnAction(event -> {
if (this.filename != null) { if (this.filename != null) {
this.export(this.filename); this.export(this.filename);
} else { } else {
@ -253,23 +259,22 @@ public class Controller {
} }
n = primaryStage.getScene().lookup("#menuSaveAs"); n = primaryStage.getScene().lookup("#menuSaveAs");
if ( n != null && n instanceof Button ) { if ( n != null && n instanceof Button ) {
n.setOnMouseReleased(event -> this.showSaveAs()); ((Button) n).setOnAction(event -> this.showSaveAs());
} }
n = primaryStage.getScene().lookup("#menuClose"); n = primaryStage.getScene().lookup("#menuClose");
if ( n != null && n instanceof Button ) { if ( n != null && n instanceof Button ) {
n.setOnMouseReleased(event -> Platform.exit()); ((Button) n).setOnAction(event -> Platform.exit());
} }
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) {
n.setOnMouseClicked(event -> this.saveTodoEntry()); ((Button) n).setOnAction(event -> this.saveTodoEntry());
n.setOnKeyPressed(event -> this.saveTodoEntry());
} }
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());
} }
// TODO: handle new TodoList // handle new TodoList
n = primaryStage.getScene().lookup("#todoListNew"); n = primaryStage.getScene().lookup("#todoListNew");
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
@ -277,7 +282,7 @@ public class Controller {
this.showTodoListEdit(); this.showTodoListEdit();
}); });
} }
// TODO: handle edit TodoList // handle edit TodoList
n = primaryStage.getScene().lookup("#todoListEdit"); n = primaryStage.getScene().lookup("#todoListEdit");
if ( n != null && n instanceof Button) { if ( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> { ((Button) n).setOnAction(event -> {
@ -285,7 +290,11 @@ public class Controller {
this.showTodoListEdit(); this.showTodoListEdit();
}); });
} }
// TODO: handle delete TodoList // handle delete TodoList
n = primaryStage.getScene().lookup("#todoListDelete");
if( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> deleteTodoList());
}
// TODO // TODO
} }
@ -314,6 +323,8 @@ public class Controller {
if (n!=null && n instanceof Button) { if (n!=null && n instanceof Button) {
n.setDisable(!t.isChangeable()); n.setDisable(!t.isChangeable());
} }
// if there is no todo item, empty the currentTodo
this.currentTodo = null;
} }
updateSelectedTodo(); updateSelectedTodo();
} }
@ -330,17 +341,17 @@ public class Controller {
n = primaryStage.getScene().lookup("#todoDetailTitle"); n = primaryStage.getScene().lookup("#todoDetailTitle");
if ( n == null || !(n instanceof TextField)) if ( n == null || !(n instanceof TextField))
return; return;
((TextField) n).setText( 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) )
return; return;
((TextArea) n).setText( 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) )
return; return;
boolean dueDate = 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");
@ -382,7 +393,7 @@ public class Controller {
save.show(); save.show();
Button s = (Button) save.getScene().lookup("#save"); Button s = (Button) save.getScene().lookup("#save");
if ( s != null) if ( s != null)
s.setOnMouseReleased(event -> { s.setOnAction(event -> {
TextField f = (TextField) save.getScene().lookup("#filename"); TextField f = (TextField) save.getScene().lookup("#filename");
if (f != null) { if (f != null) {
File file = new File(f.getText()); File file = new File(f.getText());
@ -399,6 +410,10 @@ public class Controller {
} }
private void saveTodoEntry() { private void saveTodoEntry() {
if ( this.currentTodo == null ) {
this.updateStatusLine("No item selected!");
return;
}
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!");
@ -505,7 +520,6 @@ public class Controller {
} }
} }
private void saveTodoListEdit() { private void saveTodoListEdit() {
// TODO
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'");
@ -537,6 +551,23 @@ public class Controller {
n.setDisable(true); n.setDisable(true);
n.setVisible(false); n.setVisible(false);
} }
private void deleteTodoList() {
Node n = primaryStage.getScene().lookup("#todoLists");
if (n == null || !(n instanceof ListView)) {
return;
}
ListView l = (ListView) n;
if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) {
TodoList t = (TodoList) l.getSelectionModel().getSelectedItem();
if (!t.isChangeable() ) {
this.updateStatusLine("Cant delete the TodoList!");
return;
}
this.todoLists.remove(t);
//this.notifyList(this.todoLists, this.currentTodo);
this.updateStatusLine("TodoList removed!");
}
}
private void printError(String s) { private void printError(String s) {
SimpleDateFormat format = new SimpleDateFormat(); SimpleDateFormat format = new SimpleDateFormat();
format.applyPattern("yyyyMMdd'T'HH:mm:ssZ"); format.applyPattern("yyyyMMdd'T'HH:mm:ssZ");

Loading…
Cancel
Save