Refine Desktop Pricing
This commit is contained in:
@@ -85,6 +85,7 @@ public class AdoptionController {
|
||||
colAdoptionDate.setCellValueFactory(new PropertyValueFactory<>("adoptionDate"));
|
||||
colAdoptionFee.setCellValueFactory(new PropertyValueFactory<>("adoptionFee"));
|
||||
colAdoptionStatus.setCellValueFactory(new PropertyValueFactory<>("adoptionStatus"));
|
||||
TableViewSupport.applyCurrencyColumn(colAdoptionFee);
|
||||
|
||||
displayAdoptions();
|
||||
TableViewSupport.installDoubleClickAction(tvAdoptions, selected -> openDialog(selected, "Edit"));
|
||||
|
||||
@@ -183,6 +183,7 @@ public class PetController {
|
||||
colPetAge.setCellValueFactory(new PropertyValueFactory<Pet,Integer>("petAge"));
|
||||
colPetStatus.setCellValueFactory(new PropertyValueFactory<Pet,String>("petStatus"));
|
||||
colPetPrice.setCellValueFactory(new PropertyValueFactory<Pet,Double>("petPrice"));
|
||||
TableViewSupport.applyCurrencyColumn(colPetPrice);
|
||||
colCustomerName.setCellValueFactory(new PropertyValueFactory<Pet,String>("customerName"));
|
||||
colStoreName.setCellValueFactory(new PropertyValueFactory<Pet,String>("storeName"));
|
||||
configureImageColumn(colPetImage);
|
||||
|
||||
@@ -98,6 +98,7 @@ public class ProductController {
|
||||
colProductPrice.setCellValueFactory(new PropertyValueFactory<ProductDTO,Double>("prodPrice"));
|
||||
colProductCategory.setCellValueFactory(new PropertyValueFactory<ProductDTO,String>("categoryName"));
|
||||
colProductDesc.setCellValueFactory(new PropertyValueFactory<ProductDTO,String>("prodDesc"));
|
||||
TableViewSupport.applyCurrencyColumn(colProductPrice);
|
||||
configureImageColumn(colProductImage);
|
||||
loadCategoryFilter();
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import javafx.scene.Scene;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.TableCell;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.SelectionMode;
|
||||
import javafx.scene.control.Spinner;
|
||||
@@ -157,8 +156,8 @@ public class SaleController {
|
||||
colCartQty.setCellValueFactory(new PropertyValueFactory<>("quantity"));
|
||||
colCartUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
|
||||
colCartTotal.setCellValueFactory(new PropertyValueFactory<>("total"));
|
||||
colCartUnitPrice.setCellFactory(column -> currencyCell());
|
||||
colCartTotal.setCellFactory(column -> currencyCell());
|
||||
TableViewSupport.applyCurrencyColumn(colCartUnitPrice);
|
||||
TableViewSupport.applyCurrencyColumn(colCartTotal);
|
||||
tvCart.setItems(cartItems);
|
||||
tvCart.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
|
||||
|
||||
@@ -172,8 +171,8 @@ public class SaleController {
|
||||
colSaleUnitPrice.setCellValueFactory(new PropertyValueFactory<>("unitPrice"));
|
||||
colSaleTotal.setCellValueFactory(new PropertyValueFactory<>("total"));
|
||||
colSalePaymentType.setCellValueFactory(new PropertyValueFactory<>("paymentMethod"));
|
||||
colSaleUnitPrice.setCellFactory(column -> currencyCell());
|
||||
colSaleTotal.setCellFactory(column -> currencyCell());
|
||||
TableViewSupport.applyCurrencyColumn(colSaleUnitPrice);
|
||||
TableViewSupport.applyCurrencyColumn(colSaleTotal);
|
||||
|
||||
filteredSales = new FilteredList<>(saleItems, s -> true);
|
||||
TableViewSupport.bindSortedItems(tvSales, filteredSales);
|
||||
@@ -544,20 +543,6 @@ public class SaleController {
|
||||
lblCartTotal.setText(currency.format(total));
|
||||
}
|
||||
|
||||
private <S> TableCell<S, Double> currencyCell() {
|
||||
return new TableCell<>() {
|
||||
@Override
|
||||
protected void updateItem(Double value, boolean empty) {
|
||||
super.updateItem(value, empty);
|
||||
if (empty || value == null) {
|
||||
setText(null);
|
||||
} else {
|
||||
setText(currency.format(value));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setCreateSaleControlsDisabled(boolean disabled) {
|
||||
cbProduct.setDisable(disabled);
|
||||
spQuantity.setDisable(disabled);
|
||||
|
||||
@@ -56,6 +56,7 @@ public class ServiceController {
|
||||
colServiceDesc.setCellValueFactory(new PropertyValueFactory<>("serviceDesc"));
|
||||
colServiceDuration.setCellValueFactory(new PropertyValueFactory<>("serviceDuration"));
|
||||
colServicePrice.setCellValueFactory(new PropertyValueFactory<>("servicePrice"));
|
||||
TableViewSupport.applyCurrencyColumn(colServicePrice);
|
||||
|
||||
displayServices();
|
||||
TableViewSupport.installDoubleClickAction(tvServices, selected -> openDialog(selected, "Edit"));
|
||||
|
||||
@@ -3,12 +3,16 @@ package org.example.petshopdesktop.util;
|
||||
import javafx.collections.transformation.FilteredList;
|
||||
import javafx.collections.transformation.SortedList;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.scene.control.TableCell;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableRow;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class TableViewSupport {
|
||||
@@ -39,6 +43,21 @@ public final class TableViewSupport {
|
||||
delay.playFromStart();
|
||||
}
|
||||
|
||||
public static <S, T extends Number> void applyCurrencyColumn(TableColumn<S, T> column) {
|
||||
if (column == null) {
|
||||
return;
|
||||
}
|
||||
column.setCellFactory(col -> new TableCell<>() {
|
||||
private final NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.CANADA);
|
||||
|
||||
@Override
|
||||
protected void updateItem(T value, boolean empty) {
|
||||
super.updateItem(value, empty);
|
||||
setText(empty || value == null ? null : currency.format(value.doubleValue()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> void installDoubleClickAction(TableView<T> tableView, Consumer<T> action) {
|
||||
tableView.setRowFactory(tv -> {
|
||||
TableRow<T> row = new TableRow<>();
|
||||
|
||||
Reference in New Issue
Block a user