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

Loading…
Cancel
Save