move items between lists

main
Thomas Battermann 10 years ago committed by Thomas Ba
parent e640baf5aa
commit 5e4ead4985

@ -373,12 +373,20 @@ public class Controller {
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#menuChangeEmail'");
}
// log out
n = primaryStage.getScene().lookup("#menuLogout");
if ( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showLoginDialog());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#menuLogout'");
}
// move todo item
n = primaryStage.getScene().lookup("#todoMove");
if ( n != null && n instanceof Button) {
((Button) n).setOnAction(event -> showMoveTodoItem());
}else{
ErrorPrinter.printWarning("showMainWindow > Couldnt find element '#todoMove'");
}
}
private void updateSelectedTodoList() {
@ -879,7 +887,6 @@ public class Controller {
Node n = change.getScene().lookup("#status");
if ( n == null || !(n instanceof Label)) {
ErrorPrinter.printWarning("showChangeEmail > Didnt find element #status!");
return;
}
Label status = (Label) n;
@ -975,6 +982,82 @@ public class Controller {
((Button) n).setOnAction(event -> Platform.exit());
}
private void showMoveTodoItem() {
Stage move = new Stage();
try {
move.setScene(new Scene(FXMLLoader.load(getClass().getResource("moveTodoItem.fxml"))));
} catch (IOException e) {
ErrorPrinter.printError("showMoveTodoItem > Failed to open window 'moveTodoItem'! Goodbye!");
e.printStackTrace();
Platform.exit();
}
move.setTitle("Move item '" + this.currentTodo.getTitle() + "'");
move.show();
// fill in the gaps :)
Node n = move.getScene().lookup("#title");
if ( n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("showMoveTodoItem > Didnt find element #title");
return;
}
((TextField) n).setText(this.currentTodo.getTitle());
// get current TodoList
n = primaryStage.getScene().lookup("#todoLists");
if (n == null || !(n instanceof ListView)) {
ErrorPrinter.printWarning("showDeleteList > Didnt find element #todoLists!");
return;
}
ListView l = (ListView) n;
TodoList t;
if (l.getSelectionModel().getSelectedItem() != null && l.getSelectionModel().getSelectedItem() instanceof TodoList) {
t = (TodoList) l.getSelectionModel().getSelectedItem();
}else {
ErrorPrinter.printWarning("showDeleteList > Didnt find selected item!");
return;
}
n = move.getScene().lookup("#source");
if ( n == null || !(n instanceof TextField)) {
ErrorPrinter.printWarning("showDeleteList > Didnt find element #source");
return;
}
((TextField) n).setText(t.getName());
// populate dropdown
n = move.getScene().lookup("#destination");
if ( n == null || !(n instanceof ChoiceBox)) {
ErrorPrinter.printWarning("showDeleteList > Didnt find element #destination");
return;
}
ChoiceBox<TodoList> c = (ChoiceBox) n;
c.setItems(this.todoLists);
// event handlers
n = move.getScene().lookup("#abort");
if ( n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showDeleteList > Didnt find element #abort");
move.close();
return;
}
((Button) n).setOnAction(event -> move.close());
n = move.getScene().lookup("#move");
if ( n == null || !(n instanceof Button)) {
ErrorPrinter.printWarning("showDeleteList > Didnt find element #move");
move.close();
return;
}
((Button) n).setOnAction(event -> {
// first add the item to the destination
TodoList list = c.getSelectionModel().getSelectedItem();
if ( list == null ) {
ErrorPrinter.printWarning("showDeleteList > Invalid selection!");
this.updateStatusLine("Invalid selection!");
return;
}
list.addTodo(this.currentTodo);
// then delete the item in the source list
todos.remove(this.currentTodo);
// update current list
move.close();
});
}
/**
* Notify a list about a changed item
* Taken from: http://stackoverflow.com/a/21435063

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<TitledPane animated="false" collapsible="false" maxHeight="-Infinity" maxWidth="-Infinity" text="Move todo item" xmlns="http://javafx.com/javafx/8.0.45" xmlns:fx="http://javafx.com/fxml/1">
<font>
<Font name="System Bold" size="13.0" />
</font>
<content>
<VBox>
<children>
<Label text="Title:" />
<TextField id="title" editable="false">
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
</TextField>
<Label text="Source:" />
<TextField id="source" editable="false">
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
</TextField>
<Label text="Destination:" />
<ChoiceBox id="destination" minWidth="305.0">
<VBox.margin>
<Insets bottom="15.0" />
</VBox.margin>
</ChoiceBox>
<HBox>
<children>
<Button id="move" minWidth="150.0" mnemonicParsing="false" text="Move">
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
</Button>
<Button id="abort" minWidth="150.0" mnemonicParsing="false" text="Abort" />
</children>
</HBox>
</children>
</VBox>
</content>
</TitledPane>
Loading…
Cancel
Save