fixed merge conflict PlantsController

This commit is contained in:
giavaphi 2022-10-31 12:52:27 +01:00
parent 5b039eb762
commit 5f35d99839
1 changed files with 17 additions and 18 deletions

View File

@ -5,8 +5,11 @@ import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
import ch.zhaw.gartenverwaltung.types.HardinessZone;
import ch.zhaw.gartenverwaltung.types.Plant;
import ch.zhaw.gartenverwaltung.types.Seasons;
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.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
@ -18,7 +21,6 @@ import javafx.scene.layout.VBox;
import java.io.IOException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.ResourceBundle;
@ -27,6 +29,8 @@ public class PlantsController implements Initializable {
private Plant selectedPlant = null;
private final HardinessZone DEFAULT_HARDINESS_ZONE = HardinessZone.ZONE_8A;
private final ListProperty<Plant> plantListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
@FXML
private VBox seasons;
@ -66,7 +70,9 @@ public class PlantsController implements Initializable {
*/
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
setListCellFactory();
fillPlantListWithHardinessZone();
list_plants.itemsProperty().bind(plantListProperty);
description_plant.setText("");
saveToMyPlant_button.setDisable(true);
@ -82,15 +88,9 @@ public class PlantsController implements Initializable {
}
/**
* update the ListView according to the plant list provided
* Entry in ListView is plant name
* @param list plantList which fill the ListView
* set text of list view to plant name
*/
private void fillListViewWithData(List<Plant> list) {
clearListView();
for (Plant plant : list) {
list_plants.getItems().add(plant);
}
private void setListCellFactory() {
list_plants.setCellFactory(param -> new ListCell<Plant>() {
@Override
protected void updateItem(Plant plant, boolean empty) {
@ -113,8 +113,8 @@ public class PlantsController implements Initializable {
* @throws IOException throws exception
*/
private void viewFilteredListBySeason(Seasons season) throws HardinessZoneNotSetException, IOException {
List<Plant> plantList = plantListModel.getFilteredPlantListBySaisonWithoutGrowthPhase(plantListModel.getCurrentZone(), season.getStartDate(), season.getEndDate());
fillListViewWithData(plantList);
clearListView();
plantListProperty.addAll(plantListModel.getFilteredPlantListBySaisonWithoutGrowthPhase(plantListModel.getCurrentZone(), season.getStartDate(), season.getEndDate()));
}
/**
@ -128,13 +128,13 @@ public class PlantsController implements Initializable {
if (newValue.isEmpty()) {
fillPlantListWithHardinessZone();
}else {
List<Plant> plantList = new LinkedList<>();
try {
plantList = plantListModel.getFilteredPlantListByString(plantListModel.getCurrentZone(), newValue);
List<Plant> filteredPlants = plantListModel.getFilteredPlantListByString(DEFAULT_HARDINESS_ZONE, newValue);
clearListView();
plantListProperty.addAll(filteredPlants);
} catch (HardinessZoneNotSetException | IOException e) {
e.printStackTrace();
}
fillListViewWithData(plantList);
}
});
}
@ -144,13 +144,12 @@ public class PlantsController implements Initializable {
* fill list view with plant list
*/
private void fillPlantListWithHardinessZone() {
List<Plant> plantList = new LinkedList<>();
try {
plantList = plantListModel.getPlantList(plantListModel.getCurrentZone());
clearListView();
plantListProperty.addAll(plantListModel.getPlantList(plantListModel.getCurrentZone()));
} catch (HardinessZoneNotSetException | IOException e) {
e.printStackTrace();
}
fillListViewWithData(plantList);
}
/**
@ -249,6 +248,6 @@ public class PlantsController implements Initializable {
* clears the ListView of entries
*/
private void clearListView() {
list_plants.getItems().clear();
plantListProperty.clear();
}
}