#53 fixed bug get sow date from harvest date + javadoc Plant and SelectSowDayController
This commit is contained in:
@@ -31,31 +31,50 @@ public class SelectSowDayController implements Initializable {
|
||||
@FXML
|
||||
private RadioButton sow_radio;
|
||||
|
||||
/**
|
||||
* close the date selector window
|
||||
* @param event event
|
||||
*/
|
||||
@FXML
|
||||
void cancel(ActionEvent event) {
|
||||
closeWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* get sow date from datePicker or calculate sow date from harvest date
|
||||
* save selected plant and sow date
|
||||
* @param event event
|
||||
*/
|
||||
@FXML
|
||||
void save(ActionEvent event) {
|
||||
//ToDo save plant and sow date to crop/gardenplan model
|
||||
System.out.println(selectedPlant);
|
||||
LocalDate sowDate;
|
||||
if (sow_radio.isSelected()) {
|
||||
System.out.println(datepicker.getValue());
|
||||
sowDate = datepicker.getValue();
|
||||
} else {
|
||||
//ToDo method to get current lifecycle group in plant
|
||||
//ToDo error when
|
||||
//what's up with that group thing in life_cycle we have hardiness zone for that
|
||||
System.out.println(selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0));
|
||||
sowDate = selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0);
|
||||
}
|
||||
System.out.println(sowDate);
|
||||
System.out.println(selectedPlant);
|
||||
closeWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* save the plant which will be planted and update label
|
||||
* @param plant Plant
|
||||
*/
|
||||
public void getSelectedPlant(Plant plant) {
|
||||
selectedPlant = plant;
|
||||
popup_label.setText("Select Harvest/Sow Date for" + selectedPlant.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* add listener and set default values
|
||||
* {@inheritDoc}
|
||||
* @param location location
|
||||
* @param resources resources
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
clearDatePickerEntries();
|
||||
@@ -67,6 +86,9 @@ public class SelectSowDayController implements Initializable {
|
||||
enableDisableSaveButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* clear date picker editor when radio button is changed
|
||||
*/
|
||||
private void clearDatePickerEntries() {
|
||||
sow_radio.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
@Override
|
||||
@@ -76,6 +98,10 @@ public class SelectSowDayController implements Initializable {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* date picker disable/enable dates according to selected plant: sow or harvest day
|
||||
* @return cellFactory of datePicker
|
||||
*/
|
||||
private Callback<DatePicker, DateCell> getDayCellFactory() {
|
||||
|
||||
final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
|
||||
@@ -103,6 +129,10 @@ public class SelectSowDayController implements Initializable {
|
||||
setStyle("-fx-background-color: #32CD32;");
|
||||
}
|
||||
}
|
||||
if ((!sow_radio.isSelected() && selectedPlant.sowDateFromHarvestDate(item, 0).compareTo(today) < 0)) {
|
||||
setDisable(true);
|
||||
setStyle("-fx-background-color: #ffc0cb;");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -110,11 +140,17 @@ public class SelectSowDayController implements Initializable {
|
||||
return dayCellFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* close date picker window
|
||||
*/
|
||||
private void closeWindow() {
|
||||
Stage stage = (Stage) save_button.getScene().getWindow();
|
||||
stage.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* disable save button, when there is no date selected in date picker
|
||||
*/
|
||||
private void enableDisableSaveButton() {
|
||||
save_button.setDisable(true);
|
||||
datepicker.getEditor().textProperty().addListener(new ChangeListener<String>() {
|
||||
|
||||
Reference in New Issue
Block a user