From 5c1d71f733df117a29e3b331d9d86f59a32b0c70 Mon Sep 17 00:00:00 2001 From: Notmoo Date: Thu, 10 Aug 2017 20:23:10 +0200 Subject: [PATCH] Module Client, packg GUI : ajout composants d'interface --- .../components/CategoryTabStockDisplayer.java | 113 ++++++++++++++++++ .../CommandComposerSaleDisplayer.java | 85 +++++++++++++ .../components/SimpleValidator.java | 99 +++++++++++++++ 3 files changed, 297 insertions(+) create mode 100644 Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/CategoryTabStockDisplayer.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/CommandComposerSaleDisplayer.java create mode 100644 Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/SimpleValidator.java diff --git a/Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/CategoryTabStockDisplayer.java b/Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/CategoryTabStockDisplayer.java new file mode 100644 index 00000000..aa17ad38 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/CategoryTabStockDisplayer.java @@ -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, IStockComponentListener>{ + + private SimpleStockComponentFirerer firerer; + private BorderPane mainPane; + private TabPane tabPane; + + public CategoryTabStockDisplayer() { + init(); + firerer = new SimpleStockComponentFirerer(); + } + + @Override + public void display(Collection content) { + final ObservableList tabs = FXCollections.emptyObservableList(); + if(content!=null){ + List 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 products){ + Tab tab = new Tab(categoryName); + tab.closableProperty().setValue(false); + + ListView listView = new ListView<>(); + listView.setCellFactory(list->new ListCell(){ + + @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 getProductRenderer(){ + return GUIStringTool.getProductStringRenderer(); + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/CommandComposerSaleDisplayer.java b/Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/CommandComposerSaleDisplayer.java new file mode 100644 index 00000000..190aa7ac --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/CommandComposerSaleDisplayer.java @@ -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 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(){ + @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; + } +} diff --git a/Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/SimpleValidator.java b/Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/SimpleValidator.java new file mode 100644 index 00000000..1f6a9e35 --- /dev/null +++ b/Workspace/client/src/main/java/com/pqt/client/module/gui/ressources/components/SimpleValidator.java @@ -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(); + } +}