fix show all tasks

This commit is contained in:
giavaphi 2022-12-09 19:38:22 +01:00
parent 4d2057d0df
commit 96dc0ad827
3 changed files with 31 additions and 21 deletions

View File

@ -3,15 +3,15 @@ package ch.zhaw.gartenverwaltung;
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
import ch.zhaw.gartenverwaltung.io.PlantList;
import ch.zhaw.gartenverwaltung.io.TaskList;
import ch.zhaw.gartenverwaltung.models.Garden;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.models.GardenSchedule;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Plant;
import ch.zhaw.gartenverwaltung.types.Task;
import javafx.application.Platform;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
@ -51,9 +51,15 @@ public class MyScheduleController {
@FXML
private ListView<Crop> scheduledPlants_listview;
@FXML
private void showAllTasks(ActionEvent actionEvent) throws IOException {
gardenSchedule.getTasksUpcomingWeek();
scheduledPlants_listview.getSelectionModel().clearSelection();
}
@AfterInject
@SuppressWarnings("unused")
public void init() {
public void init() throws IOException {
setCellFactoryCropListView();
setCellFactoryTaskListView();
scheduledPlants_listview.itemsProperty().bind(garden.getPlantedCrops());
@ -61,6 +67,19 @@ public class MyScheduleController {
week_listView.itemsProperty().bind(taskListProperty);
lookForSelectedListEntries();
information_label.setText("");
gardenSchedule.getTasksUpcomingWeek();
TaskList.TaskListObserver taskListObserver = newTaskList -> {
Platform.runLater(() -> {
try {
gardenSchedule.getTasksUpcomingWeek();
scheduledPlants_listview.getSelectionModel().clearSelection();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
};
gardenSchedule.setTaskListObserver(taskListObserver);
}
/**
@ -81,6 +100,8 @@ public class MyScheduleController {
* set cellFactory for the crops.
*/
private void setCellFactoryCropListView() {
MultipleSelectionModel<Crop> selectionModel = scheduledPlants_listview.getSelectionModel();
selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
scheduledPlants_listview.setCellFactory(param -> new ListCell<>() {
@Override
protected void updateItem(Crop crop, boolean empty) {
@ -133,8 +154,6 @@ public class MyScheduleController {
} else {
gardenSchedule.getTasksUpcomingWeek();
}
//taskListProperty.clear();
//taskListProperty.addAll(taskLists);
}
/**
@ -200,5 +219,4 @@ public class MyScheduleController {
});
}
}

View File

@ -32,16 +32,6 @@ public class GardenSchedule {
public GardenSchedule(TaskList taskList, PlantList plantList) throws IOException {
this.taskList = taskList;
this.plantList = plantList;
TaskList.TaskListObserver taskListObserver = newTaskList -> {
Platform.runLater(() -> {
try {
getTasksUpcomingWeek();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
};
setTaskListObserver(taskListObserver);
}
public ListProperty<List<Task>> getWeeklyTaskListProperty() {

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.AnchorPane?>
@ -19,11 +20,12 @@
</Label>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="541.0" prefWidth="867.0" spacing="10.0" VBox.vgrow="ALWAYS">
<children>
<ListView fx:id="scheduledPlants_listview" maxWidth="1.7976931348623157E308" prefHeight="522.0" prefWidth="271.0" HBox.hgrow="NEVER">
<HBox.margin>
<Insets />
</HBox.margin>
</ListView>
<VBox prefHeight="497.0" prefWidth="237.0" spacing="10.0" HBox.hgrow="NEVER">
<children>
<ListView fx:id="scheduledPlants_listview" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="522.0" prefWidth="271.0" VBox.vgrow="ALWAYS" />
<Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#showAllTasks" styleClass="button-class" text="Show All Tasks" VBox.vgrow="NEVER" />
</children>
</VBox>
<VBox maxWidth="1.7976931348623157E308" prefHeight="537.0" prefWidth="650.0" spacing="10.0" HBox.hgrow="ALWAYS">
<children>
<ListView fx:id="week_listView" maxWidth="1.7976931348623157E308" prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS">