Update pet dialog
This commit is contained in:
@@ -55,6 +55,9 @@ public class PetDialogController {
|
|||||||
@FXML
|
@FXML
|
||||||
private VBox vbStoreField;
|
private VBox vbStoreField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private VBox vbPriceField;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label lblMode;
|
private Label lblMode;
|
||||||
|
|
||||||
@@ -80,7 +83,7 @@ public class PetDialogController {
|
|||||||
private TextField txtPetPrice;
|
private TextField txtPetPrice;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField txtPetSpecies;
|
private ComboBox<String> cbPetSpecies;
|
||||||
|
|
||||||
private String mode = null;
|
private String mode = null;
|
||||||
private File selectedImageFile;
|
private File selectedImageFile;
|
||||||
@@ -127,6 +130,9 @@ public class PetDialogController {
|
|||||||
|
|
||||||
setFieldVisibility(vbCustomerField, false);
|
setFieldVisibility(vbCustomerField, false);
|
||||||
setFieldVisibility(vbStoreField, false);
|
setFieldVisibility(vbStoreField, false);
|
||||||
|
setFieldVisibility(vbPriceField, true);
|
||||||
|
|
||||||
|
loadSpecies();
|
||||||
|
|
||||||
cbPetStatus.valueProperty().addListener((obs, oldVal, newVal) -> {
|
cbPetStatus.valueProperty().addListener((obs, oldVal, newVal) -> {
|
||||||
updateStatusFieldVisibility(newVal);
|
updateStatusFieldVisibility(newVal);
|
||||||
@@ -161,12 +167,16 @@ public class PetDialogController {
|
|||||||
errorMsg += Validator.isPresent(txtPetName.getText(), "Pet Name");
|
errorMsg += Validator.isPresent(txtPetName.getText(), "Pet Name");
|
||||||
errorMsg += Validator.isPresent(txtPetAge.getText(), "Age");
|
errorMsg += Validator.isPresent(txtPetAge.getText(), "Age");
|
||||||
errorMsg += Validator.isPresent(txtPetBreed.getText(), "Breed");
|
errorMsg += Validator.isPresent(txtPetBreed.getText(), "Breed");
|
||||||
errorMsg += Validator.isPresent(txtPetSpecies.getText(), "Species");
|
String speciesValue = cbPetSpecies.getValue() != null ? cbPetSpecies.getValue().trim() : "";
|
||||||
errorMsg += Validator.isPresent(txtPetPrice.getText(), "Price");
|
if (speciesValue.isEmpty()) errorMsg += "Species is required\n";
|
||||||
|
String selectedStatus = cbPetStatus.getValue();
|
||||||
|
boolean needsPrice = !("Owned".equalsIgnoreCase(selectedStatus) || "Adopted".equalsIgnoreCase(selectedStatus));
|
||||||
|
if (needsPrice) {
|
||||||
|
errorMsg += Validator.isPresent(txtPetPrice.getText(), "Price");
|
||||||
|
}
|
||||||
if (cbPetStatus.getSelectionModel().getSelectedItem() == null){
|
if (cbPetStatus.getSelectionModel().getSelectedItem() == null){
|
||||||
errorMsg += "Status is required";
|
errorMsg += "Status is required";
|
||||||
}
|
}
|
||||||
String selectedStatus = cbPetStatus.getValue();
|
|
||||||
if ("Owned".equalsIgnoreCase(selectedStatus) && cbCustomer.getValue() == null) {
|
if ("Owned".equalsIgnoreCase(selectedStatus) && cbCustomer.getValue() == null) {
|
||||||
errorMsg += "Customer is required for Owned status\n";
|
errorMsg += "Customer is required for Owned status\n";
|
||||||
}
|
}
|
||||||
@@ -176,13 +186,17 @@ public class PetDialogController {
|
|||||||
|
|
||||||
//Check validation (length size)
|
//Check validation (length size)
|
||||||
errorMsg += Validator.isLessThanVarChars(txtPetName.getText(), "Pet Name", 50);
|
errorMsg += Validator.isLessThanVarChars(txtPetName.getText(), "Pet Name", 50);
|
||||||
errorMsg += Validator.isLessThanVarChars(txtPetSpecies.getText(), "Species", 50);
|
errorMsg += Validator.isLessThanVarChars(speciesValue, "Species", 50);
|
||||||
errorMsg += Validator.isLessThanVarChars(txtPetBreed.getText(), "Breed", 50);
|
errorMsg += Validator.isLessThanVarChars(txtPetBreed.getText(), "Breed", 50);
|
||||||
errorMsg += Validator.isLessThanVarChars(txtPetPrice.getText(), "Price", 12);
|
if (needsPrice) {
|
||||||
|
errorMsg += Validator.isLessThanVarChars(txtPetPrice.getText(), "Price", 12);
|
||||||
|
}
|
||||||
errorMsg += Validator.isLessThanVarChars(txtPetAge.getText(), "Age", 11);
|
errorMsg += Validator.isLessThanVarChars(txtPetAge.getText(), "Age", 11);
|
||||||
|
|
||||||
//Check validation (format)
|
//Check validation (format)
|
||||||
errorMsg += Validator.isNonNegativeDouble(txtPetPrice.getText(), "Price");
|
if (needsPrice) {
|
||||||
|
errorMsg += Validator.isNonNegativeDouble(txtPetPrice.getText(), "Price");
|
||||||
|
}
|
||||||
errorMsg += Validator.isPositiveInteger(txtPetAge.getText(), "Age");
|
errorMsg += Validator.isPositiveInteger(txtPetAge.getText(), "Age");
|
||||||
|
|
||||||
if(errorMsg.isEmpty()){
|
if(errorMsg.isEmpty()){
|
||||||
@@ -229,13 +243,17 @@ public class PetDialogController {
|
|||||||
private PetRequest buildPetRequest() {
|
private PetRequest buildPetRequest() {
|
||||||
PetRequest request = new PetRequest();
|
PetRequest request = new PetRequest();
|
||||||
request.setPetName(txtPetName.getText());
|
request.setPetName(txtPetName.getText());
|
||||||
request.setPetSpecies(txtPetSpecies.getText());
|
request.setPetSpecies(cbPetSpecies.getValue() != null ? cbPetSpecies.getValue().trim() : "");
|
||||||
request.setPetBreed(txtPetBreed.getText());
|
request.setPetBreed(txtPetBreed.getText());
|
||||||
request.setPetStatus(cbPetStatus.getValue());
|
request.setPetStatus(cbPetStatus.getValue());
|
||||||
try {
|
String buildStatus = cbPetStatus.getValue();
|
||||||
request.setPetPrice(new BigDecimal(txtPetPrice.getText()));
|
boolean buildNeedsPrice = !("Owned".equalsIgnoreCase(buildStatus) || "Adopted".equalsIgnoreCase(buildStatus));
|
||||||
} catch (NumberFormatException e) {
|
if (buildNeedsPrice && txtPetPrice.getText() != null && !txtPetPrice.getText().isBlank()) {
|
||||||
throw new IllegalArgumentException("Invalid price format");
|
try {
|
||||||
|
request.setPetPrice(new BigDecimal(txtPetPrice.getText()));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new IllegalArgumentException("Invalid price format");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int age;
|
int age;
|
||||||
@@ -257,6 +275,27 @@ public class PetDialogController {
|
|||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadSpecies() {
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
List<DropdownOption> options = DropdownApi.getInstance().getPetSpecies();
|
||||||
|
List<String> species = options.stream()
|
||||||
|
.map(DropdownOption::getLabel)
|
||||||
|
.collect(java.util.stream.Collectors.toList());
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
String current = cbPetSpecies.getValue();
|
||||||
|
cbPetSpecies.setItems(FXCollections.observableArrayList(species));
|
||||||
|
if (current != null && !current.isBlank()) {
|
||||||
|
cbPetSpecies.setValue(current);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
Platform.runLater(() -> ActivityLogger.getInstance().logException(
|
||||||
|
"PetDialogController.loadSpecies", e, "Loading species dropdown"));
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
private void loadCustomers() {
|
private void loadCustomers() {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@@ -331,7 +370,7 @@ public class PetDialogController {
|
|||||||
if (pet!=null){
|
if (pet!=null){
|
||||||
lblPetId.setText("ID: " + pet.getPetId());
|
lblPetId.setText("ID: " + pet.getPetId());
|
||||||
txtPetName.setText(pet.getPetName());
|
txtPetName.setText(pet.getPetName());
|
||||||
txtPetSpecies.setText(pet.getPetSpecies());
|
cbPetSpecies.setValue(pet.getPetSpecies());
|
||||||
txtPetBreed.setText(pet.getPetBreed());
|
txtPetBreed.setText(pet.getPetBreed());
|
||||||
txtPetAge.setText(pet.getPetAge() + "");
|
txtPetAge.setText(pet.getPetAge() + "");
|
||||||
txtPetPrice.setText(pet.getPetPrice() + "");
|
txtPetPrice.setText(pet.getPetPrice() + "");
|
||||||
@@ -434,8 +473,10 @@ public class PetDialogController {
|
|||||||
private void updateStatusFieldVisibility(String status) {
|
private void updateStatusFieldVisibility(String status) {
|
||||||
boolean needsCustomer = "Owned".equalsIgnoreCase(status) || "Adopted".equalsIgnoreCase(status);
|
boolean needsCustomer = "Owned".equalsIgnoreCase(status) || "Adopted".equalsIgnoreCase(status);
|
||||||
boolean storeBased = requiresStore(status);
|
boolean storeBased = requiresStore(status);
|
||||||
|
boolean needsPrice = !needsCustomer;
|
||||||
setFieldVisibility(vbCustomerField, needsCustomer);
|
setFieldVisibility(vbCustomerField, needsCustomer);
|
||||||
setFieldVisibility(vbStoreField, storeBased);
|
setFieldVisibility(vbStoreField, storeBased);
|
||||||
|
setFieldVisibility(vbPriceField, needsPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean requiresStore(String status) {
|
private boolean requiresStore(String status) {
|
||||||
|
|||||||
@@ -91,11 +91,11 @@
|
|||||||
<Font name="System Bold" size="16.0" />
|
<Font name="System Bold" size="16.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<TextField fx:id="txtPetSpecies" style="-fx-border-color: #E8EBED; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-radius: 10;">
|
<ComboBox fx:id="cbPetSpecies" editable="true" prefHeight="29.0" prefWidth="336.0" promptText="Select or enter species" style="-fx-border-color: #E8EBED; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-radius: 10; -fx-background-color: white;">
|
||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="7.0" left="10.0" right="10.0" top="7.0" />
|
<Insets bottom="3.0" left="10.0" right="10.0" top="3.0" />
|
||||||
</padding>
|
</padding>
|
||||||
</TextField>
|
</ComboBox>
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.rowIndex="1">
|
<VBox prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.rowIndex="1">
|
||||||
@@ -139,7 +139,7 @@
|
|||||||
</padding>
|
</padding>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
</children></VBox>
|
</children></VBox>
|
||||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
<VBox fx:id="vbPriceField" prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
|
||||||
<children>
|
<children>
|
||||||
<Label text="Price:" textFill="#2c3e50">
|
<Label text="Price:" textFill="#2c3e50">
|
||||||
<font>
|
<font>
|
||||||
|
|||||||
Reference in New Issue
Block a user