parent
f6ec411b7a
commit
3077e02b32
|
@ -1,16 +1,23 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class MyPlantsController implements Initializable {
|
||||
|
@ -30,14 +37,14 @@ public class MyPlantsController implements Initializable {
|
|||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
//ToDo
|
||||
List<Plant> myPlants = getMyPlants();
|
||||
createPlantView(myPlants);
|
||||
List<Crop> cropList = getCropList();
|
||||
createPlantView(cropList);
|
||||
}
|
||||
|
||||
private void createPlantView(List<Plant> myPlants) {
|
||||
//ToDo
|
||||
for(Plant plant : myPlants) {
|
||||
createPlantView();
|
||||
private void createPlantView(List<Crop> crops) {
|
||||
for(Crop crop : crops) {
|
||||
HBox hBox = createPlantView(crop);
|
||||
myPlants_vbox.getChildren().add(hBox);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,14 +52,60 @@ public class MyPlantsController implements Initializable {
|
|||
mainController = controller;
|
||||
}
|
||||
|
||||
private List<Plant> getMyPlants() {
|
||||
//ToDo method to get myPlantList(scheduled)
|
||||
//Method to call all Plants saved
|
||||
List<Plant> myPlantList = new LinkedList<>();
|
||||
return myPlantList;
|
||||
private List<Crop> getCropList() {
|
||||
//ToDo method to get cropList
|
||||
//Method to get Crop List
|
||||
List<Crop> cropList = new LinkedList<>();
|
||||
return cropList;
|
||||
}
|
||||
|
||||
private void createPlantView() {
|
||||
//ToDo FXML Panel with Plant data
|
||||
private HBox createPlantView(Crop crop) {
|
||||
//ToDo add dynamic design
|
||||
HBox hBox = new HBox();
|
||||
Label label = new Label("Placeholder");
|
||||
Button details = new Button("Details");
|
||||
Button delete = new Button("delete");
|
||||
details.setOnAction(getGoToCropDetailEvent(crop));
|
||||
delete.setOnAction(getDeleteCropEvent(crop));
|
||||
hBox.getChildren().addAll(label, details, delete);
|
||||
return hBox;
|
||||
}
|
||||
|
||||
private EventHandler<ActionEvent> getGoToCropDetailEvent(Crop crop) {
|
||||
EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
//ToDo uncomment when new FXML exists
|
||||
/*try {
|
||||
mainController.loadPane("");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
};
|
||||
return event;
|
||||
}
|
||||
|
||||
private EventHandler<ActionEvent> getDeleteCropEvent(Crop crop) {
|
||||
EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
showConfirmation(crop);
|
||||
}
|
||||
};
|
||||
return event;
|
||||
}
|
||||
|
||||
private void showConfirmation(Crop crop) {
|
||||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||
alert.setTitle("Delete Crop");
|
||||
alert.setHeaderText("Are you sure want to delete this Crop?");
|
||||
alert.setContentText("placeholder");
|
||||
|
||||
Optional<ButtonType> option = alert.showAndWait();
|
||||
|
||||
if (option.get() == ButtonType.OK) {
|
||||
//ToDo Method to remove crop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import javafx.beans.property.ListProperty;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
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 javafx.scene.layout.VBox;
|
||||
|
||||
import java.net.URL;
|
||||
import java.time.LocalDate;
|
||||
|
@ -17,7 +22,9 @@ import java.util.List;
|
|||
import java.util.ResourceBundle;
|
||||
|
||||
public class MyScheduleController implements Initializable {
|
||||
private Plant selectedPlant = null;
|
||||
private Crop selectedCrop = null;
|
||||
|
||||
private final ListProperty<Crop> cropListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
||||
|
||||
@FXML
|
||||
private Label day1_label;
|
||||
|
@ -65,28 +72,26 @@ public class MyScheduleController implements Initializable {
|
|||
private Label information_label;
|
||||
|
||||
@FXML
|
||||
private ListView<Plant> scheduledPlants_listview;
|
||||
private ListView<Crop> scheduledPlants_listview;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
List<Plant> plantList = new LinkedList<>();
|
||||
fillListViewMyPlantsInSchedule(plantList);
|
||||
getSelectedPlantTask();
|
||||
//ToDo method to load crop list
|
||||
List<Crop> cropList = new LinkedList<>();
|
||||
setCellFactoryListView();
|
||||
scheduledPlants_listview.itemsProperty().bind(cropListProperty);
|
||||
lookForSelectedListEntries();
|
||||
setDayLabels();
|
||||
information_label.setText("");
|
||||
loadTaskList();
|
||||
}
|
||||
|
||||
private void getSelectedPlantTask() {
|
||||
scheduledPlants_listview.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Plant>() {
|
||||
private void lookForSelectedListEntries() {
|
||||
scheduledPlants_listview.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Crop>() {
|
||||
@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)
|
||||
}
|
||||
public void changed(ObservableValue<? extends Crop> observable, Crop oldValue, Crop newValue) {
|
||||
selectedCrop = newValue;
|
||||
loadTaskList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -102,23 +107,49 @@ public class MyScheduleController implements Initializable {
|
|||
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>() {
|
||||
private void setCellFactoryListView() {
|
||||
scheduledPlants_listview.setCellFactory(param -> new ListCell<Crop>() {
|
||||
@Override
|
||||
protected void updateItem(Plant plant, boolean empty) {
|
||||
super.updateItem(plant, empty);
|
||||
protected void updateItem(Crop crop, boolean empty) {
|
||||
super.updateItem(crop, empty);
|
||||
|
||||
if (empty || plant == null || plant.name() == null) {
|
||||
if (empty || crop == null) {
|
||||
setText(null);
|
||||
} else {
|
||||
setText(plant.name());
|
||||
setText("placeholder");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadTaskList() {
|
||||
//ToDo load task list according to selectedCrop
|
||||
List<List<Task>> taskLists = new LinkedList<>();
|
||||
if (selectedCrop != null) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
if (!taskLists.isEmpty()) {
|
||||
viewTaskListOfDay(day1_pane, taskLists.get(0));
|
||||
viewTaskListOfDay(day2_pane, taskLists.get(1));
|
||||
viewTaskListOfDay(day3_pane, taskLists.get(2));
|
||||
viewTaskListOfDay(day4_pane, taskLists.get(3));
|
||||
viewTaskListOfDay(day5_pane, taskLists.get(4));
|
||||
viewTaskListOfDay(day6_pane, taskLists.get(5));
|
||||
viewTaskListOfDay(day7_pane, taskLists.get(6));
|
||||
}
|
||||
}
|
||||
|
||||
private void viewTaskListOfDay(Pane pane, List<Task> tasks) {
|
||||
//ToDo update pane with task list
|
||||
VBox vBox = new VBox();
|
||||
for (Task task : tasks) {
|
||||
Label label = new Label("placeholder");
|
||||
vBox.getChildren().add(label);
|
||||
}
|
||||
pane.getChildren().add(vBox);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue