mirror of
				https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
				synced 2025-10-31 17:13:10 +00:00 
			
		
		
		
	Module Client, packg GUI : ajout composants d'interface
This commit is contained in:
		| @@ -0,0 +1,113 @@ | ||||
| package com.pqt.client.module.gui.ressources.components; | ||||
|  | ||||
| import com.pqt.client.module.gui.ressources.generics.displayers.IFXDisplayerComponent; | ||||
| import com.pqt.client.module.gui.ressources.specifics.products.listeners.IStockComponentListener; | ||||
| import com.pqt.client.module.gui.ressources.specifics.products.listeners.SimpleStockComponentFirerer; | ||||
| import com.pqt.client.module.gui.ressources.strings.GUIStringTool; | ||||
| import com.pqt.client.module.gui.ressources.strings.IObjectStringRenderer; | ||||
| import com.pqt.core.entities.product.Product; | ||||
| import javafx.application.Platform; | ||||
| import javafx.collections.FXCollections; | ||||
| import javafx.collections.ObservableList; | ||||
| import javafx.scene.control.*; | ||||
| import javafx.scene.input.KeyCode; | ||||
| import javafx.scene.layout.BorderPane; | ||||
| import javafx.scene.layout.Pane; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| public class CategoryTabStockDisplayer implements IFXDisplayerComponent<Collection<Product>, IStockComponentListener>{ | ||||
|  | ||||
|     private SimpleStockComponentFirerer firerer; | ||||
|     private BorderPane mainPane; | ||||
|     private TabPane tabPane; | ||||
|  | ||||
|     public CategoryTabStockDisplayer() { | ||||
|         init(); | ||||
|         firerer = new SimpleStockComponentFirerer(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void display(Collection<Product> content) { | ||||
|         final ObservableList<Tab> tabs = FXCollections.emptyObservableList(); | ||||
|         if(content!=null){ | ||||
|             List<String> categories = content.stream().map(product->product.getCategory().getName()).distinct().collect(Collectors.toList()); | ||||
|  | ||||
|             for(String cat : categories){ | ||||
|                 tabs.add(createCategoryTab(cat, content.stream().filter(p->p.getCategory().getName().equals(cat)).collect(Collectors.toList()))); | ||||
|             } | ||||
|  | ||||
|         } | ||||
|  | ||||
|         Platform.runLater(()->{ | ||||
|             tabPane.getTabs().clear(); | ||||
|             tabPane.getTabs().addAll(tabs); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addListener(IStockComponentListener l) { | ||||
|         firerer.addListener(l); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void removeListener(IStockComponentListener l) { | ||||
|         firerer.removeListener(l); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Pane getPane() { | ||||
|         return mainPane; | ||||
|     } | ||||
|  | ||||
|     private void init(){ | ||||
|         mainPane = new BorderPane(); | ||||
|         Label title = new Label(GUIStringTool.getCategorytabStockDisplayerTitle()); | ||||
|         mainPane.setTop(title); | ||||
|  | ||||
|         tabPane = new TabPane(); | ||||
|         mainPane.setCenter(tabPane); | ||||
|     } | ||||
|  | ||||
|     private Tab createCategoryTab(String categoryName, Collection<Product> products){ | ||||
|         Tab tab = new Tab(categoryName); | ||||
|         tab.closableProperty().setValue(false); | ||||
|  | ||||
|         ListView<Product> listView = new ListView<>(); | ||||
|         listView.setCellFactory(list->new ListCell<Product>(){ | ||||
|  | ||||
|             @Override | ||||
|             protected void updateItem(Product item, boolean empty) { | ||||
|                 super.updateItem(item, empty); | ||||
|  | ||||
|                 if (empty || item == null) { | ||||
|                     setText(null); | ||||
|                     setGraphic(null); | ||||
|                 } else { | ||||
|                     setText(CategoryTabStockDisplayer.getProductRenderer().render(item)); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); | ||||
|         listView.setEditable(false); | ||||
|         listView.setOnMouseClicked(event->firerer.fireContentClickEvent(event, listView.getSelectionModel().getSelectedItem())); | ||||
|         listView.setOnKeyTyped(event -> { | ||||
|             if(event.getCode().equals(KeyCode.ENTER)){ | ||||
|                 firerer.fireContentClickEvent(event, listView.getSelectionModel().getSelectedItem()); | ||||
|                 event.consume(); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         listView.setItems(FXCollections.observableArrayList(products)); | ||||
|  | ||||
|         tab.setContent(listView); | ||||
|         return tab; | ||||
|     } | ||||
|  | ||||
|     private static IObjectStringRenderer<Product> getProductRenderer(){ | ||||
|         return GUIStringTool.getProductStringRenderer(); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,85 @@ | ||||
| package com.pqt.client.module.gui.ressources.components; | ||||
|  | ||||
| import com.pqt.client.module.gui.ressources.specifics.sale.IFXSaleDisplayerComponent; | ||||
| import com.pqt.client.module.gui.ressources.specifics.sale.listeners.ISaleComponentListener; | ||||
| import com.pqt.client.module.gui.ressources.specifics.sale.listeners.SimpleSaleComponentFirerer; | ||||
| import com.pqt.client.module.gui.ressources.strings.GUIStringTool; | ||||
| import com.pqt.core.entities.product.Product; | ||||
| import com.pqt.core.entities.sale.Sale; | ||||
| import javafx.application.Platform; | ||||
| import javafx.collections.FXCollections; | ||||
| import javafx.scene.control.*; | ||||
| import javafx.scene.input.KeyCode; | ||||
| import javafx.scene.layout.BorderPane; | ||||
| import javafx.scene.layout.Pane; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| public class CommandComposerSaleDisplayer implements IFXSaleDisplayerComponent { | ||||
|  | ||||
|     private SimpleSaleComponentFirerer firerer; | ||||
|     private BorderPane mainPane; | ||||
|     private ListView<Product> listView; | ||||
|  | ||||
|     private Sale sale; | ||||
|  | ||||
|     public CommandComposerSaleDisplayer() { | ||||
|         firerer = new SimpleSaleComponentFirerer(); | ||||
|         init(); | ||||
|     } | ||||
|  | ||||
|     private void init() { | ||||
|         mainPane = new BorderPane(); | ||||
|         Label title = new Label(GUIStringTool.getCommandComposerTitleTitle()); | ||||
|         mainPane.setTop(title); | ||||
|  | ||||
|         listView = new ListView<>(); | ||||
|         listView.setCellFactory(list->new ListCell<Product>(){ | ||||
|             @Override | ||||
|             protected void updateItem(Product item, boolean empty) { | ||||
|                 super.updateItem(item, empty); | ||||
|  | ||||
|                 if (empty || item == null) { | ||||
|                     setText(null); | ||||
|                     setGraphic(null); | ||||
|                 } else { | ||||
|                     setText(GUIStringTool.getSaleItemStringRenderer().render(item, sale.getProducts().get(item))); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|         listView.setEditable(false); | ||||
|         listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); | ||||
|         listView.setOnMouseClicked(event->firerer.fireComponentClickEvent(event, listView.getSelectionModel().getSelectedItem())); | ||||
|         listView.setOnKeyTyped(event -> { | ||||
|             if(event.getCode().equals(KeyCode.ENTER)){ | ||||
|                 firerer.fireComponentClickEvent(event, listView.getSelectionModel().getSelectedItem()); | ||||
|             } | ||||
|         }); | ||||
|         mainPane.setCenter(listView); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void display(Sale content) { | ||||
|         if(content ==null) | ||||
|             return; | ||||
|  | ||||
|         this.sale = content; | ||||
|         Platform.runLater(()->this.listView.setItems(FXCollections.observableList(new ArrayList<>(this.sale.getProducts().keySet())))); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addListener(ISaleComponentListener l) { | ||||
|         firerer.addListener(l); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void removeListener(ISaleComponentListener l) { | ||||
|         firerer.removeListener(l); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Pane getPane() { | ||||
|         return mainPane; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,99 @@ | ||||
| package com.pqt.client.module.gui.ressources.components; | ||||
|  | ||||
| import com.pqt.client.module.gui.ressources.generics.validators.IFXValidatorComponent; | ||||
| import com.pqt.client.module.gui.ressources.generics.validators.listeners.IValidatorComponentFirerer; | ||||
| import com.pqt.client.module.gui.ressources.generics.validators.listeners.IValidatorComponentListener; | ||||
| import com.pqt.client.module.gui.ressources.generics.validators.listeners.SimpleValidatorComponentFirerer; | ||||
| import com.pqt.client.module.gui.ressources.strings.GUIStringTool; | ||||
| import javafx.application.Platform; | ||||
| import javafx.scene.control.Button; | ||||
| import javafx.scene.layout.HBox; | ||||
| import javafx.scene.layout.Pane; | ||||
|  | ||||
| public class SimpleValidator implements IFXValidatorComponent{ | ||||
|  | ||||
|     private final IValidatorComponentFirerer firerer; | ||||
|     private Pane pane; | ||||
|     private boolean askConfirmation; | ||||
|     private Button validationButton, cancelButton; | ||||
|  | ||||
|     public SimpleValidator() { | ||||
|         this(false); | ||||
|     } | ||||
|  | ||||
|     public SimpleValidator(boolean askConfirmation) { | ||||
|         firerer = new SimpleValidatorComponentFirerer(); | ||||
|         this.askConfirmation = askConfirmation; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addListener(IValidatorComponentListener l) { | ||||
|         firerer.addListener(l); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void removeListener(IValidatorComponentListener l) { | ||||
|         firerer.removeListener(l); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Pane getPane() { | ||||
|         if(pane == null) | ||||
|             pane = createPane(); | ||||
|         return pane; | ||||
|     } | ||||
|  | ||||
|     private Pane createPane(){ | ||||
|         HBox hbox = new HBox(); | ||||
|  | ||||
|         validationButton = new Button(GUIStringTool.getValidationButtonLabel()); | ||||
|         validationButton.setOnMouseClicked(event->{ | ||||
|             getValidationButtonProcess().process(); | ||||
|         }); | ||||
|         hbox.getChildren().add(validationButton); | ||||
|  | ||||
|         cancelButton = new Button(GUIStringTool.getCancelButtonLabel()); | ||||
|         cancelButton.setOnMouseClicked(event->{ | ||||
|             getCancelButtonProcess().process(); | ||||
|         }); | ||||
|         hbox.getChildren().add(cancelButton); | ||||
|  | ||||
|         return hbox; | ||||
|     } | ||||
|  | ||||
|     private IButtonProcess getValidationButtonProcess(){ | ||||
|         return ()->{ | ||||
|             if(validationButton.getText().equals(GUIStringTool.getValidationButtonLabel())){ | ||||
|                 if(askConfirmation) | ||||
|                     Platform.runLater(()->validationButton.setText(GUIStringTool.getConfirmationValidationButtonLabel())); | ||||
|                 else | ||||
|                     firerer.fireValidationEvent(); | ||||
|             }else{ | ||||
|                 if(validationButton.getText().equals(GUIStringTool.getConfirmationValidationButtonLabel())) | ||||
|                     firerer.fireValidationEvent(); | ||||
|                 Platform.runLater(()->validationButton.setText(GUIStringTool.getValidationButtonLabel())); | ||||
|             } | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     private IButtonProcess getCancelButtonProcess(){ | ||||
|         return ()->{ | ||||
|             if(cancelButton.getText().equals(GUIStringTool.getCancelButtonLabel())){ | ||||
|                 if(askConfirmation) | ||||
|                     Platform.runLater(()->cancelButton.setText(GUIStringTool.getConfirmationCancelButtonLabel())); | ||||
|                 else | ||||
|                     firerer.fireCancelEvent(); | ||||
|             }else{ | ||||
|                 Platform.runLater(()->cancelButton.setText(GUIStringTool.getCancelButtonLabel())); | ||||
|                 firerer.fireCancelEvent(); | ||||
|             } | ||||
|         }; | ||||
|  | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private interface IButtonProcess{ | ||||
|         void process(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user