add disable properties to dialog save buttons
This commit is contained in:
parent
df19edb25a
commit
1c83fc4694
|
@ -285,6 +285,7 @@ public class CropDetailController {
|
|||
|
||||
if (appLoader.loadPaneToDialog("TaskFormular.fxml", dialogPane) instanceof TaskFormularController controller) {
|
||||
controller.setCorp(this.crop);
|
||||
controller.initSaveButton((Button) dialogPane.lookupButton(saveTask));
|
||||
if (!newTask) {
|
||||
controller.setTaskValue(givenTask);
|
||||
}
|
||||
|
@ -322,6 +323,7 @@ public class CropDetailController {
|
|||
if (appLoader.loadPaneToDialog("TextFieldFormular.fxml", dialogPane) instanceof TextFieldFormularController controller) {
|
||||
controller.setDescription_label(labelDescription);
|
||||
controller.setValueTextArea(value);
|
||||
controller.initSaveButton((Button) dialogPane.lookupButton(save));
|
||||
|
||||
dialog.setResultConverter(button -> button.equals(save) ? controller.getValue() : null);
|
||||
|
||||
|
|
|
@ -2,12 +2,14 @@ package ch.zhaw.gartenverwaltung;
|
|||
|
||||
import ch.zhaw.gartenverwaltung.types.Crop;
|
||||
import ch.zhaw.gartenverwaltung.types.Task;
|
||||
import javafx.beans.binding.Binding;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.binding.BooleanBinding;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.DateCell;
|
||||
import javafx.scene.control.DatePicker;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.util.Callback;
|
||||
|
||||
import java.net.URL;
|
||||
|
@ -56,7 +58,7 @@ public class TaskFormularController implements Initializable {
|
|||
}
|
||||
}
|
||||
|
||||
private Callback<DatePicker, DateCell> getDayCellFactory() {
|
||||
private Callback<DatePicker, DateCell> getDayCellFactoryStartDate() {
|
||||
|
||||
return (datePicker) -> new DateCell() {
|
||||
private final LocalDate today = LocalDate.now();
|
||||
|
@ -71,16 +73,61 @@ public class TaskFormularController implements Initializable {
|
|||
setDisable(false);
|
||||
setStyle("-fx-background-color: #32CD32;");
|
||||
}
|
||||
|
||||
if (end_datePicker.getValue() != null && item.compareTo(end_datePicker.getValue()) > 0) {
|
||||
setDisable(true);
|
||||
setStyle("-fx-background-color: #ffc0cb;");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Callback<DatePicker, DateCell> getDayCellFactoryEndDate() {
|
||||
|
||||
return (datePicker) -> new DateCell() {
|
||||
private final LocalDate today = LocalDate.now();
|
||||
|
||||
@Override
|
||||
public void updateItem(LocalDate item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setDisable(true);
|
||||
setStyle("-fx-background-color: #ffc0cb;");
|
||||
|
||||
if (item.compareTo(today) > 0 && item.compareTo(crop.getStartDate()) > 0) {
|
||||
setDisable(false);
|
||||
setStyle("-fx-background-color: #32CD32;");
|
||||
}
|
||||
|
||||
if (start_datePicker.getValue() != null && item.compareTo(start_datePicker.getValue()) < 0) {
|
||||
setDisable(true);
|
||||
setStyle("-fx-background-color: #ffc0cb;");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void initSaveButton(Button button) {
|
||||
interval_field.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (!newValue.matches("\\d*")) {
|
||||
interval_field.setText(newValue.replaceAll("[^\\d]", ""));
|
||||
}
|
||||
});
|
||||
|
||||
button.disableProperty().bind(start_datePicker.valueProperty().isNull()
|
||||
.or(end_datePicker.valueProperty().isNull())
|
||||
.or(taskName_field.textProperty().isEmpty())
|
||||
.or(description_area.textProperty().isEmpty())
|
||||
.or(interval_field.textProperty().isEmpty()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
start_datePicker.setDayCellFactory(getDayCellFactory());
|
||||
start_datePicker.setDayCellFactory(getDayCellFactoryStartDate());
|
||||
start_datePicker.setEditable(false);
|
||||
|
||||
end_datePicker.setDayCellFactory(getDayCellFactory());
|
||||
end_datePicker.setDayCellFactory(getDayCellFactoryEndDate());
|
||||
end_datePicker.setEditable(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
|
||||
|
@ -24,4 +25,8 @@ public class TextFieldFormularController {
|
|||
public String getValue() {
|
||||
return text_area.getText();
|
||||
}
|
||||
|
||||
public void initSaveButton(Button button) {
|
||||
button.disableProperty().bind(text_area.textProperty().isEmpty());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue