diff --git a/Boutique/ressources/fxml/Ajout_Habit.fxml b/Boutique/ressources/fxml/Ajout_Habit.fxml
new file mode 100644
index 0000000..b8c0336
--- /dev/null
+++ b/Boutique/ressources/fxml/Ajout_Habit.fxml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Boutique/ressources/fxml/Ajout_Parfum.fxml b/Boutique/ressources/fxml/Ajout_Parfum.fxml
new file mode 100644
index 0000000..38e8d4b
--- /dev/null
+++ b/Boutique/ressources/fxml/Ajout_Parfum.fxml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Boutique/ressources/fxml/MainWindow.fxml b/Boutique/ressources/fxml/MainWindow.fxml
index 0314b0b..4fce7e6 100644
--- a/Boutique/ressources/fxml/MainWindow.fxml
+++ b/Boutique/ressources/fxml/MainWindow.fxml
@@ -16,8 +16,8 @@
-
-
+
+
diff --git a/Boutique/src/Modele/metier/Boutique.java b/Boutique/src/Modele/metier/Boutique.java
index 06b32ba..49d7d6b 100644
--- a/Boutique/src/Modele/metier/Boutique.java
+++ b/Boutique/src/Modele/metier/Boutique.java
@@ -1,5 +1,7 @@
package Modele.metier;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -8,6 +10,10 @@ public class Boutique {
private List produits;
+ private PropertyChangeSupport support = new PropertyChangeSupport(this);
+
+ public static final String PROP_AJOUT = "AjoutProduit";
+
public Boutique(){
produits = new ArrayList<>();
}
@@ -16,12 +22,26 @@ public class Boutique {
this.produits = produits;
}
+ public void addListener(PropertyChangeListener listener){
+ support.addPropertyChangeListener(listener);
+ }
+
+ public void ajouterProduit(Produit produit){
+ produits.add(produit);
+ }
+
public void ajouterHabit(String nom, int prix){
- produits.add(new Habit(nom, prix));
+ Produit produit = new Habit(nom, prix);
+ produits.add(produit);
+ int index = produits.size() - 1;
+ support.fireIndexedPropertyChange(PROP_AJOUT, index, null, produit);
}
- public void ajouterParfum(String nom, int prix){
- produits.add(new Parfum(nom, prix));
+ public void ajouterParfum(String nom, int prix, List fragrances){
+ Produit produit = new Parfum(nom, prix, fragrances);
+ produits.add(produit);
+ int index = produits.size() - 1;
+ support.fireIndexedPropertyChange(PROP_AJOUT, index, null, produit);
}
public List getProduits() {
diff --git a/Boutique/src/Modele/metier/Parfum.java b/Boutique/src/Modele/metier/Parfum.java
index 7baae5d..3e91f7c 100644
--- a/Boutique/src/Modele/metier/Parfum.java
+++ b/Boutique/src/Modele/metier/Parfum.java
@@ -13,6 +13,11 @@ public class Parfum extends Produit{
fragrances = new ArrayList<>();
}
+ public Parfum(String nom, int prix, List fragrances) {
+ this(nom, prix);
+ this.fragrances = fragrances;
+ }
+
public void ajouterFragrance(String fragrance){
fragrances.add(fragrance);
}
diff --git a/Boutique/src/view/AjoutHabit.java b/Boutique/src/view/AjoutHabit.java
new file mode 100644
index 0000000..f96aca3
--- /dev/null
+++ b/Boutique/src/view/AjoutHabit.java
@@ -0,0 +1,51 @@
+package view;
+
+import javafx.beans.binding.Bindings;
+import javafx.fxml.FXML;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AjoutHabit {
+
+ @FXML
+ private TextField nomHabit;
+
+ @FXML
+ private TextField prixHabit;
+
+
+ private boolean isCanceled = false;
+
+ @FXML
+ private void ajouterHabit() {
+ fermerFenetre();
+ }
+
+ @FXML
+ private void annuler() {
+ isCanceled = true;
+ fermerFenetre();
+ }
+
+ private void fermerFenetre(){
+ nomHabit.getScene().getWindow().hide();
+ }
+
+
+ public String getNomHabit(){
+ return nomHabit.getText();
+ }
+
+ public int getPrixHabit(){
+ return Integer.parseInt(prixHabit.getText());
+ }
+
+
+ public boolean isCanceled() {
+ return isCanceled;
+ }
+
+}
diff --git a/Boutique/src/view/AjoutParfum.java b/Boutique/src/view/AjoutParfum.java
new file mode 100644
index 0000000..fd40599
--- /dev/null
+++ b/Boutique/src/view/AjoutParfum.java
@@ -0,0 +1,76 @@
+package view;
+
+import javafx.beans.binding.Bindings;
+import javafx.event.ActionEvent;
+import javafx.fxml.FXML;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+import view_modele.ProduitVM;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AjoutParfum {
+
+ @FXML
+ private Label fragrancesAjoutees;
+
+ @FXML
+ private TextField nomParfum;
+
+ @FXML
+ private TextField prixParfum;
+
+ @FXML
+ private TextField fragranceParfum;
+
+ private final List fragrances = new ArrayList<>();
+
+ private boolean isCanceled = false;
+
+ @FXML
+ private void ajouterParfum() {
+ fermerFenetre();
+ }
+
+ @FXML
+ private void annuler() {
+ isCanceled = true;
+ fermerFenetre();
+ }
+
+ private void fermerFenetre(){
+ fragranceParfum.getScene().getWindow().hide();
+ }
+
+ @FXML
+ private void ajouterFragrance() {
+ fragrances.add(fragranceParfum.getText());
+ fragrancesAjoutees.textProperty().bind(Bindings.concat("Fragrances ajoutées : ", fragrancesToString()));
+ fragranceParfum.setText("");
+; }
+
+ private String fragrancesToString(){
+ StringBuilder str = new StringBuilder();
+ for(String s : fragrances){
+ str.append(String.format("%s,",s));
+ }
+
+ return str.toString();
+ }
+ public String getNomParfum(){
+ return nomParfum.getText();
+ }
+
+ public int getPrixParfum(){
+ return Integer.parseInt(prixParfum.getText());
+ }
+
+ public List getFragrancesParfum(){
+ return fragrances;
+ }
+
+ public boolean isCanceled() {
+ return isCanceled;
+ }
+}
diff --git a/Boutique/src/view/MainWindow.java b/Boutique/src/view/MainWindow.java
index cda5684..cad96ee 100644
--- a/Boutique/src/view/MainWindow.java
+++ b/Boutique/src/view/MainWindow.java
@@ -1,13 +1,20 @@
package view;
+import javafx.event.ActionEvent;
import javafx.fxml.FXML;
-import javafx.scene.control.Label;
-import javafx.scene.control.ListView;
-import javafx.scene.control.TextField;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Scene;
+import javafx.scene.control.*;
+import javafx.stage.Modality;
+import javafx.stage.Stage;
+import javafx.util.StringConverter;
+import javafx.util.converter.IntegerStringConverter;
import view.cellules.CelluleProduit;
import view_modele.BoutiqueVM;
import view_modele.ProduitVM;
+import java.io.IOException;
+
public class MainWindow {
@FXML
@@ -30,10 +37,62 @@ public class MainWindow {
nomProduit.textProperty().unbindBidirectional(oldV.nomProperty());
prixProduit.textProperty().unbindBidirectional(oldV.nomProperty());
}
- if(newV != null){
+ if(newV != null) {
nomProduit.textProperty().bindBidirectional(newV.nomProperty());
prixProduit.textProperty().bindBidirectional(newV.nomProperty());
}
});
}
+
+ @FXML
+ private void lancerFenetreAjoutParfum(){
+ Stage secondStage = new Stage();
+ secondStage.initOwner(listeProduit.getScene().getWindow());
+ secondStage.initModality(Modality.WINDOW_MODAL);
+ AjoutParfum controlleur = initAjouterParfum(secondStage);
+ if(!controlleur.isCanceled()){
+ boutiqueVM.ajouterParfum(controlleur.getNomParfum(), controlleur.getPrixParfum(), controlleur.getFragrancesParfum());
+ }
+ }
+
+ private AjoutParfum initAjouterParfum(Stage stageAjoutParfum) {
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/Ajout_Parfum.fxml"));
+ AjoutParfum controlleur = new AjoutParfum();
+ loader.setController(controlleur);
+ try{
+ stageAjoutParfum.setScene(new Scene(loader.load()));
+ stageAjoutParfum.showAndWait();
+ } catch (IOException e) {
+ Alert alerte = new Alert(Alert.AlertType.ERROR, "Erreur lors du lancement de la fenêtre", ButtonType.OK);
+ alerte.show();
+ }
+
+ return controlleur;
+ }
+
+ @FXML
+ private void lancerFenetreAjoutHabit(){
+ Stage secondStage = new Stage();
+ secondStage.initOwner(listeProduit.getScene().getWindow());
+ secondStage.initModality(Modality.WINDOW_MODAL);
+ AjoutHabit controlleur = initAjouterHabit(secondStage);
+ if(!controlleur.isCanceled()){
+ boutiqueVM.ajouterHabit(controlleur.getNomHabit(), controlleur.getPrixHabit());
+ }
+ }
+
+ private AjoutHabit initAjouterHabit(Stage stageAjoutHabit) {
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/Ajout_Habit.fxml"));
+ AjoutHabit controlleur = new AjoutHabit();
+ loader.setController(controlleur);
+ try{
+ stageAjoutHabit.setScene(new Scene(loader.load()));
+ stageAjoutHabit.showAndWait();
+ } catch (IOException e) {
+ Alert alerte = new Alert(Alert.AlertType.ERROR, "Erreur lors du lancement de la fenêtre", ButtonType.OK);
+ alerte.show();
+ }
+
+ return controlleur;
+ }
}
diff --git a/Boutique/src/view_modele/BoutiqueVM.java b/Boutique/src/view_modele/BoutiqueVM.java
index fd9bcf5..c917c81 100644
--- a/Boutique/src/view_modele/BoutiqueVM.java
+++ b/Boutique/src/view_modele/BoutiqueVM.java
@@ -14,9 +14,13 @@ import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
+import java.beans.IndexedPropertyChangeEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.io.IOException;
+import java.util.List;
-public class BoutiqueVM {
+public class BoutiqueVM implements PropertyChangeListener {
private Boutique modele;
@@ -41,16 +45,41 @@ public class BoutiqueVM {
}
initialiserListe();
+ modele.addListener(this);
}
public void initialiserListe(){
for(Produit p : modele.getProduits()){
- if(p instanceof Habit){
- produitsObs.add(new HabitVM((Habit)p));
- }
- else if(p instanceof Parfum){
- produitsObs.add(new ParfumVM((Parfum)p));
- }
+ produitsObs.add(creerProduitVM(p));
+ }
+ }
+
+ private ProduitVM creerProduitVM(Produit p){
+ ProduitVM produit = null;
+
+ if(p instanceof Habit){
+ produit = new HabitVM((Habit)p);
+ }
+ else if(p instanceof Parfum){
+ produit = new ParfumVM((Parfum)p);
+ }
+
+ return produit;
+ }
+
+ public void ajouterParfum(String nom, int prix, List fragrances){
+ modele.ajouterParfum(nom, prix, fragrances);
+ }
+
+ public void ajouterHabit(String nom, int prix){
+ modele.ajouterHabit(nom, prix);
+ }
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ switch (evt.getPropertyName()){
+ case Boutique.PROP_AJOUT:
+ produitsObs.add(((IndexedPropertyChangeEvent)evt).getIndex(), creerProduitVM((Produit)evt.getNewValue()));
+ break;
}
}
}