Close chat #169
@@ -83,8 +83,9 @@ public class AdoptionController {
|
||||
|
||||
tvAdoptions.getSelectionModel().selectedItemProperty().addListener(
|
||||
(observable, oldValue, newValue) -> {
|
||||
btnEdit.setDisable(false);
|
||||
btnDelete.setDisable(false);
|
||||
boolean hasSelection = newValue != null;
|
||||
btnEdit.setDisable(!hasSelection);
|
||||
btnDelete.setDisable(!hasSelection);
|
||||
});
|
||||
|
||||
txtSearch.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
|
||||
@@ -47,7 +47,8 @@ public class AppointmentController {
|
||||
|
||||
@FXML
|
||||
public void initialize(){
|
||||
|
||||
btnEdit.setDisable(true);
|
||||
btnDelete.setDisable(true);
|
||||
tvAppointments.getSelectionModel().setSelectionMode(javafx.scene.control.SelectionMode.MULTIPLE);
|
||||
|
||||
colAppointmentId.setCellValueFactory(new PropertyValueFactory<>("appointmentId"));
|
||||
@@ -66,6 +67,12 @@ public class AppointmentController {
|
||||
txtSearch.textProperty().addListener((obs, o, n) -> applyFilter(n));
|
||||
}
|
||||
|
||||
tvAppointments.getSelectionModel().selectedItemProperty().addListener((obs, oldValue, newValue) -> {
|
||||
boolean hasSelection = newValue != null;
|
||||
btnEdit.setDisable(!hasSelection);
|
||||
btnDelete.setDisable(!hasSelection);
|
||||
});
|
||||
|
||||
tvAppointments.setOnKeyPressed(event -> {
|
||||
if (event.getCode() == javafx.scene.input.KeyCode.DELETE) {
|
||||
if (tvAppointments.getSelectionModel().getSelectedItem() != null) {
|
||||
|
||||
@@ -73,8 +73,9 @@ public class InventoryController {
|
||||
|
||||
tvInventory.getSelectionModel().selectedItemProperty().addListener(
|
||||
(observable, oldValue, newValue) -> {
|
||||
btnEdit.setDisable(false);
|
||||
btnDelete.setDisable(false);
|
||||
boolean hasSelection = newValue != null;
|
||||
btnEdit.setDisable(!hasSelection);
|
||||
btnDelete.setDisable(!hasSelection);
|
||||
});
|
||||
|
||||
txtSearch.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
|
||||
@@ -175,8 +175,9 @@ public class PetController {
|
||||
|
||||
tvPets.getSelectionModel().selectedItemProperty().addListener(
|
||||
(observable, oldValue, newValue) -> {
|
||||
btnEdit.setDisable(false);
|
||||
btnDelete.setDisable(false);
|
||||
boolean hasSelection = newValue != null;
|
||||
btnEdit.setDisable(!hasSelection);
|
||||
btnDelete.setDisable(!hasSelection);
|
||||
});
|
||||
|
||||
txtSearch.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
|
||||
@@ -99,8 +99,9 @@ public class ProductController {
|
||||
//EventListener to Enable buttons when a row is selected
|
||||
tvProducts.getSelectionModel().selectedItemProperty().addListener(
|
||||
(observable, oldValue, newValue) -> {
|
||||
btnEdit.setDisable(false);
|
||||
btnDelete.setDisable(false);
|
||||
boolean hasSelection = newValue != null;
|
||||
btnEdit.setDisable(!hasSelection);
|
||||
btnDelete.setDisable(!hasSelection);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -80,8 +80,9 @@ public class ProductSupplierController {
|
||||
//EventListener to Enable buttons when a row is selected
|
||||
tvProductSuppliers.getSelectionModel().selectedItemProperty().addListener(
|
||||
(observable, oldValue, newValue) -> {
|
||||
btnEdit.setDisable(false);
|
||||
btnDelete.setDisable(false);
|
||||
boolean hasSelection = newValue != null;
|
||||
btnEdit.setDisable(!hasSelection);
|
||||
btnDelete.setDisable(!hasSelection);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ public class SaleController {
|
||||
spQuantity.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 999, 1));
|
||||
spQuantity.setEditable(true);
|
||||
|
||||
cbPaymentMethod.setItems(FXCollections.observableArrayList("Cash", "Card"));
|
||||
cbPaymentMethod.setItems(FXCollections.observableArrayList("Cash", "Card", "Debit"));
|
||||
cbPaymentMethod.getSelectionModel().selectFirst();
|
||||
|
||||
updateCartTotal();
|
||||
|
||||
@@ -57,8 +57,9 @@ public class ServiceController {
|
||||
|
||||
tvServices.getSelectionModel().selectedItemProperty().addListener(
|
||||
(observable, oldValue, newValue) -> {
|
||||
btnEdit.setDisable(false);
|
||||
btnDelete.setDisable(false);
|
||||
boolean hasSelection = newValue != null;
|
||||
btnEdit.setDisable(!hasSelection);
|
||||
btnDelete.setDisable(!hasSelection);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -230,4 +231,4 @@ public class ServiceController {
|
||||
response.getServicePrice().doubleValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +82,9 @@ public class SupplierController {
|
||||
//EventListener to Enable buttons when a row is selected
|
||||
tvSuppliers.getSelectionModel().selectedItemProperty().addListener(
|
||||
(observable, oldValue, newValue) -> {
|
||||
btnEdit.setDisable(false);
|
||||
btnDelete.setDisable(false);
|
||||
boolean hasSelection = newValue != null;
|
||||
btnEdit.setDisable(!hasSelection);
|
||||
btnDelete.setDisable(!hasSelection);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -285,19 +286,21 @@ public class SupplierController {
|
||||
}
|
||||
|
||||
private Supplier mapToSupplier(SupplierResponse response) {
|
||||
String contactPerson = response.getSupContactFirstName() + " " + response.getSupContactLastName() != null ? response.getSupContactFirstName() + " " + response.getSupContactLastName() : "";
|
||||
String firstName = response.getSupContactFirstName() != null ? response.getSupContactFirstName().trim() : "";
|
||||
String lastName = response.getSupContactLastName() != null ? response.getSupContactLastName().trim() : "";
|
||||
String contactPerson = (firstName + " " + lastName).trim();
|
||||
String[] nameParts = contactPerson.split(" ", 2);
|
||||
String firstName = nameParts.length > 0 ? nameParts[0] : "";
|
||||
String lastName = nameParts.length > 1 ? nameParts[1] : "";
|
||||
String mappedFirstName = nameParts.length > 0 ? nameParts[0] : "";
|
||||
String mappedLastName = nameParts.length > 1 ? nameParts[1] : "";
|
||||
|
||||
return new Supplier(
|
||||
response.getSupId().intValue(),
|
||||
response.getSupCompany(),
|
||||
firstName,
|
||||
lastName,
|
||||
mappedFirstName,
|
||||
mappedLastName,
|
||||
response.getSupEmail(),
|
||||
response.getSupPhone()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import org.example.petshopdesktop.Validator;
|
||||
import org.example.petshopdesktop.api.dto.common.DropdownOption;
|
||||
@@ -48,6 +49,12 @@ public class PetDialogController {
|
||||
@FXML
|
||||
private ComboBox<DropdownOption> cbStore;
|
||||
|
||||
@FXML
|
||||
private VBox vbCustomerField;
|
||||
|
||||
@FXML
|
||||
private VBox vbStoreField;
|
||||
|
||||
@FXML
|
||||
private Label lblMode;
|
||||
|
||||
@@ -84,7 +91,7 @@ public class PetDialogController {
|
||||
private Long pendingStoreId = null;
|
||||
|
||||
private ObservableList<String> statusList = FXCollections.observableArrayList(
|
||||
"Available", "Adopted", "Owned"
|
||||
"Available", "Adopted", "Owned", "Pending"
|
||||
);
|
||||
|
||||
@FXML
|
||||
@@ -118,14 +125,11 @@ public class PetDialogController {
|
||||
}
|
||||
});
|
||||
|
||||
cbCustomer.setVisible(false);
|
||||
cbStore.setVisible(false);
|
||||
setFieldVisibility(vbCustomerField, false);
|
||||
setFieldVisibility(vbStoreField, false);
|
||||
|
||||
cbPetStatus.valueProperty().addListener((obs, oldVal, newVal) -> {
|
||||
boolean isOwned = "Owned".equalsIgnoreCase(newVal);
|
||||
boolean isAvailable = "Available".equalsIgnoreCase(newVal) || "Unadopted".equalsIgnoreCase(newVal);
|
||||
cbCustomer.setVisible(isOwned);
|
||||
cbStore.setVisible(isAvailable);
|
||||
updateStatusFieldVisibility(newVal);
|
||||
});
|
||||
|
||||
btnSave.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||
@@ -166,6 +170,9 @@ public class PetDialogController {
|
||||
if ("Owned".equalsIgnoreCase(selectedStatus) && cbCustomer.getValue() == null) {
|
||||
errorMsg += "Customer is required for Owned status\n";
|
||||
}
|
||||
if (requiresStore(selectedStatus) && cbStore.getValue() == null) {
|
||||
errorMsg += "Store is required for " + selectedStatus + " status\n";
|
||||
}
|
||||
|
||||
//Check validation (length size)
|
||||
errorMsg += Validator.isLessThanVarChars(txtPetName.getText(), "Pet Name", 50);
|
||||
@@ -243,7 +250,7 @@ public class PetDialogController {
|
||||
if ("Owned".equalsIgnoreCase(status) && cbCustomer.getValue() != null) {
|
||||
request.setCustomerId(cbCustomer.getValue().getId());
|
||||
}
|
||||
if (("Available".equalsIgnoreCase(status) || "Unadopted".equalsIgnoreCase(status)) && cbStore.getValue() != null) {
|
||||
if (requiresStore(status) && cbStore.getValue() != null) {
|
||||
request.setStoreId(cbStore.getValue().getId());
|
||||
}
|
||||
|
||||
@@ -339,8 +346,10 @@ public class PetDialogController {
|
||||
for (String status : cbPetStatus.getItems()) {
|
||||
if(status.equals(pet.getPetStatus())){
|
||||
cbPetStatus.getSelectionModel().select(status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
updateStatusFieldVisibility(cbPetStatus.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,6 +367,7 @@ public class PetDialogController {
|
||||
lblPetId.setVisible(true);
|
||||
refreshImagePreview();
|
||||
}
|
||||
updateStatusFieldVisibility(cbPetStatus.getValue());
|
||||
}
|
||||
|
||||
private void handleChangeImage() {
|
||||
@@ -421,4 +431,25 @@ public class PetDialogController {
|
||||
btnRemoveImage.setDisable(true);
|
||||
}
|
||||
|
||||
private void updateStatusFieldVisibility(String status) {
|
||||
boolean owned = "Owned".equalsIgnoreCase(status);
|
||||
boolean storeBased = requiresStore(status);
|
||||
setFieldVisibility(vbCustomerField, owned);
|
||||
setFieldVisibility(vbStoreField, storeBased);
|
||||
}
|
||||
|
||||
private boolean requiresStore(String status) {
|
||||
return "Available".equalsIgnoreCase(status)
|
||||
|| "Pending".equalsIgnoreCase(status)
|
||||
|| "Unadopted".equalsIgnoreCase(status);
|
||||
}
|
||||
|
||||
private void setFieldVisibility(VBox field, boolean visible) {
|
||||
if (field == null) {
|
||||
return;
|
||||
}
|
||||
field.setVisible(visible);
|
||||
field.setManaged(visible);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.example.petshopdesktop.api.endpoints.ProductSupplierApi;
|
||||
import org.example.petshopdesktop.util.ActivityLogger;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public class ProductSupplierDialogController {
|
||||
|
||||
@@ -46,6 +47,8 @@ public class ProductSupplierDialogController {
|
||||
private String mode = null;
|
||||
private int selectedSupId = -1;
|
||||
private int selectedProdId = -1;
|
||||
private Long pendingSupplierId = null;
|
||||
private Long pendingProductId = null;
|
||||
|
||||
/**
|
||||
* add event listeners to buttons and set up combobox
|
||||
@@ -120,9 +123,11 @@ public class ProductSupplierDialogController {
|
||||
Platform.runLater(() -> {
|
||||
if (suppliers != null) {
|
||||
cbSupplier.setItems(FXCollections.observableArrayList(suppliers));
|
||||
applyPendingSupplierSelection();
|
||||
}
|
||||
if (products != null) {
|
||||
cbProduct.setItems(FXCollections.observableArrayList(products));
|
||||
applyPendingProductSelection();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
@@ -220,21 +225,14 @@ public class ProductSupplierDialogController {
|
||||
* @param productSupplier
|
||||
*/
|
||||
public void displayProductSupplierDetails(ProductSupplierDTO productSupplier){
|
||||
if(productSupplier != null){
|
||||
txtCost.setText(productSupplier.getCost() + "");
|
||||
}
|
||||
|
||||
for (DropdownOption product : cbProduct.getItems()) {
|
||||
if(product.getId() == productSupplier.getProdId()){
|
||||
cbProduct.getSelectionModel().select(product);
|
||||
}
|
||||
}
|
||||
|
||||
for (DropdownOption supplier : cbSupplier.getItems()) {
|
||||
if (supplier.getId() == productSupplier.getSupId()) {
|
||||
cbSupplier.getSelectionModel().select(supplier);
|
||||
}
|
||||
if (productSupplier == null) {
|
||||
return;
|
||||
}
|
||||
txtCost.setText(productSupplier.getCost() + "");
|
||||
pendingProductId = (long) productSupplier.getProdId();
|
||||
pendingSupplierId = (long) productSupplier.getSupId();
|
||||
applyPendingProductSelection();
|
||||
applyPendingSupplierSelection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +251,7 @@ public class ProductSupplierDialogController {
|
||||
*/
|
||||
public void setMode(String mode) {
|
||||
this.mode = mode;
|
||||
lblMode.setText(mode + " Product");
|
||||
lblMode.setText(mode + " Product-Supplier");
|
||||
lblProductSupplierId.setVisible(false);
|
||||
}
|
||||
|
||||
@@ -267,4 +265,38 @@ public class ProductSupplierDialogController {
|
||||
this.selectedProdId = prodId;
|
||||
}
|
||||
|
||||
private void applyPendingProductSelection() {
|
||||
if (pendingProductId == null) {
|
||||
return;
|
||||
}
|
||||
DropdownOption product = findOptionById(cbProduct.getItems(), pendingProductId);
|
||||
if (product != null) {
|
||||
cbProduct.getSelectionModel().select(product);
|
||||
pendingProductId = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void applyPendingSupplierSelection() {
|
||||
if (pendingSupplierId == null) {
|
||||
return;
|
||||
}
|
||||
DropdownOption supplier = findOptionById(cbSupplier.getItems(), pendingSupplierId);
|
||||
if (supplier != null) {
|
||||
cbSupplier.getSelectionModel().select(supplier);
|
||||
pendingSupplierId = null;
|
||||
}
|
||||
}
|
||||
|
||||
private DropdownOption findOptionById(List<DropdownOption> options, Long id) {
|
||||
if (options == null || id == null) {
|
||||
return null;
|
||||
}
|
||||
for (DropdownOption option : options) {
|
||||
if (option.getId() != null && option.getId().equals(id)) {
|
||||
return option;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@
|
||||
</TextField>
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.rowIndex="3">
|
||||
<VBox fx:id="vbCustomerField" prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.rowIndex="3">
|
||||
<children>
|
||||
<Label text="Customer:" textFill="#2c3e50">
|
||||
<font>
|
||||
@@ -167,7 +167,7 @@
|
||||
</ComboBox>
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.columnIndex="1" GridPane.rowIndex="3">
|
||||
<VBox fx:id="vbStoreField" prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.columnIndex="1" GridPane.rowIndex="3">
|
||||
<children>
|
||||
<Label text="Store:" textFill="#2c3e50">
|
||||
<font>
|
||||
|
||||
Reference in New Issue
Block a user