mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-12-22 15:31:08 +00:00
Module Client : ajout écran stock
This commit is contained in:
parent
f817ae6ab3
commit
eb594e0293
@ -2,6 +2,7 @@ package com.pqt.client;
|
||||
|
||||
import com.pqt.client.gui.main_frame.MainFrame;
|
||||
import com.pqt.client.gui.modules.sale_screen.SaleScreen;
|
||||
import com.pqt.client.gui.modules.stock_screen.StockScreen;
|
||||
import com.pqt.client.gui.ressources.components.generics.others.SideBar;
|
||||
import com.pqt.client.gui.ressources.components.generics.others.listeners.ISideBarListener;
|
||||
import com.pqt.client.gui.ressources.css.GUICssTool;
|
||||
@ -11,8 +12,6 @@ import com.pqt.client.module.sale.SaleService;
|
||||
import com.pqt.client.module.stock.StockService;
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class Main extends Application{
|
||||
@ -29,6 +28,7 @@ public class Main extends Application{
|
||||
|
||||
MainFrame mainFrame = new MainFrame(accountService);
|
||||
mainFrame.addModule(new SaleScreen(accountService, stockService, saleService));
|
||||
mainFrame.addModule(new StockScreen(stockService));
|
||||
|
||||
Scene scene = new Scene(mainFrame.getPane(), 800, 600);
|
||||
scene.getStylesheets().clear();
|
||||
|
@ -0,0 +1,28 @@
|
||||
package com.pqt.client.gui.modules.stock_screen;
|
||||
|
||||
import com.pqt.client.gui.modules.IGuiModule;
|
||||
import com.pqt.client.module.stock.StockService;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
||||
public class StockScreen implements IGuiModule {
|
||||
|
||||
private StockScreenView view;
|
||||
|
||||
public StockScreen(StockService stockService) {
|
||||
StockScreenModel model = new StockScreenModel(stockService);
|
||||
StockScreenController ctrl = new StockScreenController(model);
|
||||
view = new StockScreenView(ctrl);
|
||||
|
||||
ctrl.setView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
return "Stock";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pane getPane() {
|
||||
return view.getPane();
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.pqt.client.gui.modules.stock_screen;
|
||||
|
||||
|
||||
import com.pqt.client.gui.modules.stock_screen.listeners.IStockItemEventListener;
|
||||
import com.pqt.client.gui.modules.stock_screen.listeners.IStockScreenModelListener;
|
||||
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||
import com.pqt.core.entities.product.Product;
|
||||
|
||||
class StockScreenController implements IStockScreenModelListener{
|
||||
|
||||
private StockScreenModel model;
|
||||
private StockScreenView view;
|
||||
|
||||
StockScreenController(StockScreenModel model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
void setView(StockScreenView view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
void onAddProductRequest() {
|
||||
detailProduct(null);
|
||||
}
|
||||
|
||||
void onDetailProductRequest() {
|
||||
detailProduct(view.getSelectedProduct());
|
||||
}
|
||||
|
||||
private void detailProduct(Product product){
|
||||
//TODO à faire
|
||||
}
|
||||
|
||||
void onDeleteProductRequest() {
|
||||
deleteProduct(view.getSelectedProduct());
|
||||
}
|
||||
|
||||
private void addProduct(Product product){
|
||||
model.commitProductAddition(product);
|
||||
}
|
||||
|
||||
private void modifyProduct(Product oldProduct, Product newProduct){
|
||||
model.commitProductModification(oldProduct, newProduct);
|
||||
}
|
||||
|
||||
private void deleteProduct(Product product){
|
||||
model.commitProductDeletion(product);;
|
||||
}
|
||||
|
||||
void onRefreshProductsRequest() {
|
||||
refreshView();
|
||||
}
|
||||
|
||||
IStockItemEventListener getProductActivationListener() {
|
||||
return this::detailProduct;
|
||||
}
|
||||
|
||||
private void refreshView(){
|
||||
view.display(model.getProductCollection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStockUpdatedEvent() {
|
||||
refreshView();
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.pqt.client.gui.modules.stock_screen;
|
||||
|
||||
import com.pqt.client.gui.modules.stock_screen.listeners.IStockScreenModelListener;
|
||||
import com.pqt.client.module.stock.Listeners.StockListenerAdapter;
|
||||
import com.pqt.client.module.stock.StockService;
|
||||
import com.pqt.core.entities.product.Product;
|
||||
|
||||
import javax.swing.event.EventListenerList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
class StockScreenModel {
|
||||
|
||||
private StockService stockService;
|
||||
private EventListenerList listenerList;
|
||||
|
||||
StockScreenModel(StockService stockService) {
|
||||
listenerList = new EventListenerList();
|
||||
this.stockService = stockService;
|
||||
this.stockService.addListener(new StockListenerAdapter(){
|
||||
@Override
|
||||
public void onProductListChangedEvent() {
|
||||
StockScreenModel.this.fireProductCollectionChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void fireProductCollectionChanged() {
|
||||
Arrays.stream(listenerList.getListeners(IStockScreenModelListener.class))
|
||||
.forEach(IStockScreenModelListener::onStockUpdatedEvent);
|
||||
}
|
||||
|
||||
Collection<Product> getProductCollection() {
|
||||
return stockService.getProducts();
|
||||
}
|
||||
|
||||
void commitProductDeletion(Product product) {
|
||||
|
||||
}
|
||||
|
||||
void commitProductModification(Product oldProduct, Product newProduct) {
|
||||
|
||||
}
|
||||
|
||||
void commitProductAddition(Product product) {
|
||||
|
||||
}
|
||||
|
||||
void addListener(IStockScreenModelListener l){
|
||||
listenerList.add(IStockScreenModelListener.class, l);
|
||||
}
|
||||
|
||||
void removeListener(IStockScreenModelListener l){
|
||||
listenerList.remove(IStockScreenModelListener.class, l);
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package com.pqt.client.gui.modules.stock_screen;
|
||||
|
||||
import com.pqt.client.gui.ressources.components.generics.IFXComponent;
|
||||
import com.pqt.client.gui.ressources.strings.GUIStringTool;
|
||||
import com.pqt.client.gui.ressources.strings.IObjectStringRenderer;
|
||||
import com.pqt.core.entities.product.Product;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.util.Callback;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
class StockScreenView implements IFXComponent {
|
||||
|
||||
private StockScreenController ctrl;
|
||||
private Pane mainPane;
|
||||
private TableView<Product> stockTableView;
|
||||
|
||||
StockScreenView(StockScreenController ctrl) {
|
||||
this.ctrl = ctrl;
|
||||
initGui();
|
||||
}
|
||||
|
||||
private void initGui() {
|
||||
mainPane = new Pane();
|
||||
mainPane.getStyleClass().add("main-module-pane");
|
||||
BorderPane mainPaneContent = new BorderPane();
|
||||
mainPane.getChildren().add(mainPaneContent);
|
||||
mainPaneContent.prefWidthProperty().bind(mainPane.widthProperty());
|
||||
mainPaneContent.prefHeightProperty().bind(mainPane.heightProperty());
|
||||
|
||||
Button addProductButton = new Button(GUIStringTool.getAddButtonLabel());
|
||||
addProductButton.setOnMouseClicked(event -> ctrl.onAddProductRequest());
|
||||
Button detailProductButton = new Button(GUIStringTool.getDetailButtonLabel());
|
||||
detailProductButton.setOnMouseClicked(event -> ctrl.onDetailProductRequest());
|
||||
Button removeProductButton = new Button(GUIStringTool.getRemoveButtonLabel());
|
||||
removeProductButton.setOnMouseClicked(event -> ctrl.onDeleteProductRequest());
|
||||
Button refreshProductButton = new Button(GUIStringTool.getRefreshButtonLabel());
|
||||
refreshProductButton.setOnMouseClicked(event -> ctrl.onRefreshProductsRequest());
|
||||
|
||||
ToolBar actionToolbar = new ToolBar();
|
||||
actionToolbar.getItems().addAll(addProductButton, detailProductButton, removeProductButton, refreshProductButton);
|
||||
|
||||
HBox mainPaneTopContent = new HBox();
|
||||
HBox separator = new HBox();
|
||||
mainPaneTopContent.getChildren().addAll(separator, actionToolbar);
|
||||
HBox.setHgrow(separator, Priority.ALWAYS);
|
||||
mainPaneContent.setTop(mainPaneTopContent);
|
||||
|
||||
stockTableView = new TableView<>();
|
||||
stockTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
|
||||
stockTableView.setRowFactory(tableView->{
|
||||
TableRow<Product> row = new TableRow<>();
|
||||
row.setOnMouseClicked(event -> {
|
||||
if (event.getButton().equals(MouseButton.PRIMARY) && event.getClickCount() == 2)
|
||||
ctrl.getProductActivationListener().onProductActivated(row.getItem());
|
||||
});
|
||||
row.setOnKeyTyped(event -> {
|
||||
if (event.getCode().equals(KeyCode.ENTER))
|
||||
ctrl.getProductActivationListener().onProductActivated(row.getItem());
|
||||
});
|
||||
return row;
|
||||
});
|
||||
stockTableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
|
||||
List<TableColumn<Product, ?>> columns = new ArrayList<>();
|
||||
|
||||
columns.add(createNewTableColumn(String.class,
|
||||
GUIStringTool.getProductNameColumnHeader(),
|
||||
param -> new SimpleStringProperty(param.getValue().getName()),
|
||||
null
|
||||
));
|
||||
columns.add(createNewTableColumn(String.class,
|
||||
GUIStringTool.getProductCategoryColumnHeader(),
|
||||
param -> new SimpleStringProperty(param.getValue().getCategory().getName()),
|
||||
null
|
||||
));
|
||||
columns.add(createNewTableColumn(Integer.class,
|
||||
GUIStringTool.getProductAmountRemainingColumnHeader(),
|
||||
param -> new SimpleIntegerProperty(param.getValue().getAmountRemaining()).asObject(),
|
||||
null
|
||||
));
|
||||
columns.add(createNewTableColumn(Integer.class,
|
||||
GUIStringTool.getProductAmountSoldColumnHeader(),
|
||||
param -> new SimpleIntegerProperty(param.getValue().getAmountSold()).asObject(),
|
||||
null
|
||||
));
|
||||
columns.add(createNewTableColumn(Double.class,
|
||||
GUIStringTool.getProductPriceColumnHeader(),
|
||||
param -> new SimpleDoubleProperty(param.getValue().getAmountSold()).asObject(),
|
||||
GUIStringTool.getPriceRenderer()
|
||||
));
|
||||
columns.add(createNewTableColumn(Boolean.class,
|
||||
GUIStringTool.getProductIsSellableColumnHeader(),
|
||||
param -> new SimpleBooleanProperty(param.getValue().isSellable()),
|
||||
GUIStringTool.getBooleanRenderer()
|
||||
));
|
||||
|
||||
stockTableView.getColumns().addAll(columns);
|
||||
mainPaneContent.setCenter(stockTableView);
|
||||
}
|
||||
|
||||
private <T> TableColumn<Product, T> createNewTableColumn(Class<T> clazz,
|
||||
String header,
|
||||
Callback<TableColumn.CellDataFeatures<Product, T>, ObservableValue<T>> cellValueFactory,
|
||||
IObjectStringRenderer<T> renderer){
|
||||
TableColumn<Product, T> column = new TableColumn<>();
|
||||
if(header!=null)
|
||||
column.setText(header);
|
||||
if(cellValueFactory!=null)
|
||||
column.setCellValueFactory(cellValueFactory);
|
||||
if(renderer!=null)
|
||||
column.setCellFactory(table -> new TableCell<Product, T>() {
|
||||
@Override
|
||||
protected void updateItem(T item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item == null || empty) {
|
||||
setText(null);
|
||||
setStyle("");
|
||||
} else {
|
||||
setText(renderer.render(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
void display(Collection<Product> productCollection){
|
||||
Platform.runLater(()->{
|
||||
this.stockTableView.getItems().clear();
|
||||
this.stockTableView.getItems().addAll(productCollection);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pane getPane() {
|
||||
return mainPane;
|
||||
}
|
||||
|
||||
Product getSelectedProduct() {
|
||||
return stockTableView.getSelectionModel().getSelectedItem();
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.pqt.client.gui.modules.stock_screen.listeners;
|
||||
|
||||
import com.pqt.core.entities.product.Product;
|
||||
|
||||
public interface IStockItemEventListener {
|
||||
void onProductActivated(Product product);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.pqt.client.gui.modules.stock_screen.listeners;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface IStockScreenModelListener extends EventListener {
|
||||
void onStockUpdatedEvent();
|
||||
}
|
@ -34,7 +34,12 @@ public class GUIStringTool {
|
||||
}
|
||||
|
||||
public static IObjectStringRenderer<Product> getProductStringRenderer(){
|
||||
return product->String.format("%s - %.2f€ (%s)", product.getName(), product.getPrice(), (product.getAmountRemaining()>=30?"30+": Integer.toString(product.getAmountRemaining())));
|
||||
return product->{
|
||||
if(product!=null)
|
||||
return String.format("%s - %.2f€ (%s)", product.getName(), product.getPrice(), (product.getAmountRemaining()>=30?"30+": Integer.toString(product.getAmountRemaining())));
|
||||
else
|
||||
return "null";
|
||||
};
|
||||
}
|
||||
|
||||
public static String getCommandComposerTitleTitle() {
|
||||
@ -165,6 +170,50 @@ public class GUIStringTool {
|
||||
public static String getSaleGuiModuleName() {
|
||||
return "Vente";
|
||||
}
|
||||
|
||||
public static String getAddButtonLabel() {
|
||||
return "Ajouter";
|
||||
}
|
||||
|
||||
public static String getDetailButtonLabel() {
|
||||
return "Détail";
|
||||
}
|
||||
|
||||
public static String getRemoveButtonLabel() {
|
||||
return "Supprimer";
|
||||
}
|
||||
|
||||
public static String getRefreshButtonLabel() {
|
||||
return "Rafraichir";
|
||||
}
|
||||
|
||||
public static String getProductNameColumnHeader() {
|
||||
return "Nom";
|
||||
}
|
||||
|
||||
public static String getProductCategoryColumnHeader() {
|
||||
return "Catégorie";
|
||||
}
|
||||
|
||||
public static String getProductAmountRemainingColumnHeader() {
|
||||
return "Stock";
|
||||
}
|
||||
|
||||
public static String getProductAmountSoldColumnHeader() {
|
||||
return "Vendu";
|
||||
}
|
||||
|
||||
public static String getProductPriceColumnHeader() {
|
||||
return "Prix";
|
||||
}
|
||||
|
||||
public static String getProductIsSellableColumnHeader() {
|
||||
return "Vendable";
|
||||
}
|
||||
|
||||
public static IObjectStringRenderer<Boolean> getBooleanRenderer() {
|
||||
return bool->bool?"Oui":"Non";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user