125 lines
3.3 KiB
Java
125 lines
3.3 KiB
Java
package ch.zhaw.gartenverwaltung;
|
|
|
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
|
import javafx.beans.value.ChangeListener;
|
|
import javafx.beans.value.ObservableValue;
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.Initializable;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.control.ListCell;
|
|
import javafx.scene.control.ListView;
|
|
import javafx.scene.layout.Pane;
|
|
|
|
import java.net.URL;
|
|
import java.time.LocalDate;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.ResourceBundle;
|
|
|
|
public class MyScheduleController implements Initializable {
|
|
private Plant selectedPlant = null;
|
|
|
|
@FXML
|
|
private Label day1_label;
|
|
|
|
@FXML
|
|
private Pane day1_pane;
|
|
|
|
@FXML
|
|
private Label day2_label;
|
|
|
|
@FXML
|
|
private Pane day2_pane;
|
|
|
|
@FXML
|
|
private Label day3_label;
|
|
|
|
@FXML
|
|
private Pane day3_pane;
|
|
|
|
@FXML
|
|
private Label day4_label;
|
|
|
|
@FXML
|
|
private Pane day4_pane;
|
|
|
|
@FXML
|
|
private Label day5_label;
|
|
|
|
@FXML
|
|
private Pane day5_pane;
|
|
|
|
@FXML
|
|
private Label day6_label;
|
|
|
|
@FXML
|
|
private Pane day6_pane;
|
|
|
|
@FXML
|
|
private Label day7_label;
|
|
|
|
@FXML
|
|
private Pane day7_pane;
|
|
|
|
@FXML
|
|
private Label information_label;
|
|
|
|
@FXML
|
|
private ListView<Plant> scheduledPlants_listview;
|
|
|
|
@Override
|
|
public void initialize(URL location, ResourceBundle resources) {
|
|
List<Plant> plantList = new LinkedList<>();
|
|
fillListViewMyPlantsInSchedule(plantList);
|
|
getSelectedPlantTask();
|
|
setDayLabels();
|
|
information_label.setText("");
|
|
}
|
|
|
|
private void getSelectedPlantTask() {
|
|
scheduledPlants_listview.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Plant>() {
|
|
@Override
|
|
public void changed(ObservableValue<? extends Plant> observable, Plant oldValue, Plant newValue) {
|
|
if(newValue != null) {
|
|
selectedPlant = newValue;
|
|
//ToDo update day<x>_panel with task for the day
|
|
} else {
|
|
selectedPlant = null;
|
|
//ToDo update day<x>_panel with task for the day (all plants)
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void setDayLabels() {
|
|
LocalDate today = LocalDate.now();
|
|
day1_label.setText(today.getDayOfWeek().toString());
|
|
day2_label.setText(today.plusDays(1).getDayOfWeek().toString());
|
|
day3_label.setText(today.plusDays(2).getDayOfWeek().toString());
|
|
day4_label.setText(today.plusDays(3).getDayOfWeek().toString());
|
|
day5_label.setText(today.plusDays(4).getDayOfWeek().toString());
|
|
day6_label.setText(today.plusDays(5).getDayOfWeek().toString());
|
|
day7_label.setText(today.plusDays(6).getDayOfWeek().toString());
|
|
}
|
|
|
|
private void fillListViewMyPlantsInSchedule(List<Plant> list) {
|
|
for (Plant plant : list) {
|
|
scheduledPlants_listview.getItems().add(plant);
|
|
}
|
|
scheduledPlants_listview.setCellFactory(param -> new ListCell<Plant>() {
|
|
@Override
|
|
protected void updateItem(Plant plant, boolean empty) {
|
|
super.updateItem(plant, empty);
|
|
|
|
if (empty || plant == null || plant.name() == null) {
|
|
setText(null);
|
|
} else {
|
|
setText(plant.name());
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
}
|