From 289a404c0a75086963666dad7f0378210a53d4f9 Mon Sep 17 00:00:00 2001 From: Harkamal Randhawa Date: Fri, 10 Apr 2026 08:20:25 -0600 Subject: [PATCH] Fix sales UI --- .../controllers/SaleController.java | 72 +++- .../petshopdesktop/modelviews/sale-view.fxml | 324 +++++++++--------- 2 files changed, 240 insertions(+), 156 deletions(-) diff --git a/desktop/src/main/java/org/example/petshopdesktop/controllers/SaleController.java b/desktop/src/main/java/org/example/petshopdesktop/controllers/SaleController.java index 212b5762..7edc9c9a 100644 --- a/desktop/src/main/java/org/example/petshopdesktop/controllers/SaleController.java +++ b/desktop/src/main/java/org/example/petshopdesktop/controllers/SaleController.java @@ -150,12 +150,16 @@ public class SaleController { } private void setupTables() { - tvCart.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); + tvCart.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY); tvCart.setFixedCellSize(34); colCartProduct.setCellValueFactory(new PropertyValueFactory<>("prodName")); colCartQty.setCellValueFactory(new PropertyValueFactory<>("quantity")); colCartUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice")); colCartTotal.setCellValueFactory(new PropertyValueFactory<>("total")); + colCartProduct.setMinWidth(190); + colCartQty.setMinWidth(70); + colCartUnitPrice.setMinWidth(90); + colCartTotal.setMinWidth(90); TableViewSupport.applyCurrencyColumn(colCartUnitPrice); TableViewSupport.applyCurrencyColumn(colCartTotal); tvCart.setItems(cartItems); @@ -171,6 +175,14 @@ public class SaleController { colSaleUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice")); colSaleTotal.setCellValueFactory(new PropertyValueFactory<>("total")); colSalePaymentType.setCellValueFactory(new PropertyValueFactory<>("paymentMethod")); + colSaleId.setMinWidth(50); + colSaleDate.setMinWidth(150); + colEmployeeName.setMinWidth(150); + colServiceProduct.setMinWidth(260); + colSaleQuantity.setMinWidth(55); + colSaleUnitPrice.setMinWidth(100); + colSaleTotal.setMinWidth(100); + colSalePaymentType.setMinWidth(95); TableViewSupport.applyCurrencyColumn(colSaleUnitPrice); TableViewSupport.applyCurrencyColumn(colSaleTotal); @@ -179,6 +191,12 @@ public class SaleController { TableViewSupport.installDoubleClickAction(tvSales, selected -> openSaleDetailDialog(selected.getSaleId())); txtSearch.textProperty().addListener((obs, oldVal, newVal) -> applySalesFilter(newVal)); + tvSales.widthProperty().addListener((obs, oldWidth, newWidth) -> updateSalesColumnWidths(newWidth.doubleValue())); + tvCart.widthProperty().addListener((obs, oldWidth, newWidth) -> updateCartColumnWidths(newWidth.doubleValue())); + Platform.runLater(() -> { + updateSalesColumnWidths(tvSales.getWidth()); + updateCartColumnWidths(tvCart.getWidth()); + }); } private void setupCreateSale() { @@ -543,6 +561,58 @@ public class SaleController { lblCartTotal.setText(currency.format(total)); } + private void updateSalesColumnWidths(double tableWidth) { + double available = Math.max(tableWidth - 28.0, 0.0); + double baseWidth = 1125.0; + if (available <= 0) { + return; + } + + if (available <= baseWidth) { + colSaleId.setPrefWidth(60.0); + colSaleDate.setPrefWidth(170.0); + colEmployeeName.setPrefWidth(160.0); + colServiceProduct.setPrefWidth(320.0); + colSaleQuantity.setPrefWidth(70.0); + colSaleUnitPrice.setPrefWidth(115.0); + colSaleTotal.setPrefWidth(120.0); + colSalePaymentType.setPrefWidth(110.0); + return; + } + + double extra = available - baseWidth; + colSaleId.setPrefWidth(60.0); + colSaleDate.setPrefWidth(170.0 + extra * 0.18); + colEmployeeName.setPrefWidth(160.0 + extra * 0.18); + colServiceProduct.setPrefWidth(320.0 + extra * 0.42); + colSaleQuantity.setPrefWidth(70.0); + colSaleUnitPrice.setPrefWidth(115.0 + extra * 0.08); + colSaleTotal.setPrefWidth(120.0 + extra * 0.08); + colSalePaymentType.setPrefWidth(110.0 + extra * 0.06); + } + + private void updateCartColumnWidths(double tableWidth) { + double available = Math.max(tableWidth - 28.0, 0.0); + double baseWidth = 640.0; + if (available <= 0) { + return; + } + + if (available <= baseWidth) { + colCartProduct.setPrefWidth(310.0); + colCartQty.setPrefWidth(90.0); + colCartUnitPrice.setPrefWidth(120.0); + colCartTotal.setPrefWidth(120.0); + return; + } + + double extra = available - baseWidth; + colCartProduct.setPrefWidth(310.0 + extra * 0.55); + colCartQty.setPrefWidth(90.0); + colCartUnitPrice.setPrefWidth(120.0 + extra * 0.2); + colCartTotal.setPrefWidth(120.0 + extra * 0.25); + } + private void setCreateSaleControlsDisabled(boolean disabled) { cbProduct.setDisable(disabled); spQuantity.setDisable(disabled); diff --git a/desktop/src/main/resources/org/example/petshopdesktop/modelviews/sale-view.fxml b/desktop/src/main/resources/org/example/petshopdesktop/modelviews/sale-view.fxml index 947c1d42..c1c0c118 100644 --- a/desktop/src/main/resources/org/example/petshopdesktop/modelviews/sale-view.fxml +++ b/desktop/src/main/resources/org/example/petshopdesktop/modelviews/sale-view.fxml @@ -10,171 +10,185 @@ + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - -