diff --git a/Boutique/ressources/fxml/MainWindow.fxml b/Boutique/ressources/fxml/MainWindow.fxml
index 4fce7e6..d849fd9 100644
--- a/Boutique/ressources/fxml/MainWindow.fxml
+++ b/Boutique/ressources/fxml/MainWindow.fxml
@@ -23,15 +23,6 @@
-
-
-
-
-
-
-
-
-
-
+
diff --git a/Boutique/ressources/fxml/uc/UC_Commun.fxml b/Boutique/ressources/fxml/uc/UC_Commun.fxml
new file mode 100644
index 0000000..6675eac
--- /dev/null
+++ b/Boutique/ressources/fxml/uc/UC_Commun.fxml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Boutique/ressources/fxml/uc/UC_DetailHabit.fxml b/Boutique/ressources/fxml/uc/UC_DetailHabit.fxml
index e04eeea..408c5e7 100644
--- a/Boutique/ressources/fxml/uc/UC_DetailHabit.fxml
+++ b/Boutique/ressources/fxml/uc/UC_DetailHabit.fxml
@@ -6,9 +6,12 @@
-
-
+
+
+
+
+
diff --git a/Boutique/ressources/fxml/uc/UC_DetailParfum.fxml b/Boutique/ressources/fxml/uc/UC_DetailParfum.fxml
new file mode 100644
index 0000000..9b8f2fd
--- /dev/null
+++ b/Boutique/ressources/fxml/uc/UC_DetailParfum.fxml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Boutique/src/Modele/metier/Parfum.java b/Boutique/src/Modele/metier/Parfum.java
index 3e91f7c..c99f170 100644
--- a/Boutique/src/Modele/metier/Parfum.java
+++ b/Boutique/src/Modele/metier/Parfum.java
@@ -8,6 +8,10 @@ public class Parfum extends Produit{
private List fragrances;
+ public static final String PROP_AJOUT_FRAGRANCE = "ajout_fragrance";
+
+ public static final String PROP_SUPPRESSION_FRAGRANCE = "suppression_fragrance";
+
public Parfum(String nom, int prix) {
super(nom, prix);
fragrances = new ArrayList<>();
@@ -20,10 +24,13 @@ public class Parfum extends Produit{
public void ajouterFragrance(String fragrance){
fragrances.add(fragrance);
+ int index = fragrances.size() - 1;
+ support.fireIndexedPropertyChange(PROP_AJOUT_FRAGRANCE, index, null, fragrance);
}
public void supprimerFragrance(String fragrance){
fragrances.remove(fragrance);
+ support.firePropertyChange(PROP_SUPPRESSION_FRAGRANCE, fragrance, null);
}
public List getFragrances(){
diff --git a/Boutique/src/Modele/metier/Produit.java b/Boutique/src/Modele/metier/Produit.java
index a1124d9..717810f 100644
--- a/Boutique/src/Modele/metier/Produit.java
+++ b/Boutique/src/Modele/metier/Produit.java
@@ -1,16 +1,25 @@
package Modele.metier;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
public abstract class Produit {
private String nom;
private int prix;
+ protected PropertyChangeSupport support = new PropertyChangeSupport(this);
+
protected Produit(String nom, int prix){
this.nom = nom;
this.prix = prix;
}
+ public void addListener(PropertyChangeListener listener){
+ this.support.addPropertyChangeListener(listener);
+ }
+
public String getNom() {
return nom;
}
diff --git a/Boutique/src/data/chargement/Stub.java b/Boutique/src/data/chargement/Stub.java
index 7b3b35a..d2def8b 100644
--- a/Boutique/src/data/chargement/Stub.java
+++ b/Boutique/src/data/chargement/Stub.java
@@ -39,13 +39,13 @@ public class Stub implements Chargeur{
p7.ajouterFragrance("Peche");
Parfum p8 = new Parfum("Scorpion", 120);
- p6.ajouterFragrance("Marron");
+ p8.ajouterFragrance("Marron");
Parfum p9 = new Parfum("La petire robe noire", 75);
- p6.ajouterFragrance("Paille");
+ p9.ajouterFragrance("Paille");
Parfum p10 = new Parfum("Scandal", 99);
- p6.ajouterFragrance("Vache");
+ p10.ajouterFragrance("Vache");
produits.add(p1);
produits.add(p2);
diff --git a/Boutique/src/view/MainWindow.java b/Boutique/src/view/MainWindow.java
index cad96ee..3d8fbbf 100644
--- a/Boutique/src/view/MainWindow.java
+++ b/Boutique/src/view/MainWindow.java
@@ -5,12 +5,17 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.*;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.util.StringConverter;
import javafx.util.converter.IntegerStringConverter;
+import javafx.util.converter.NumberStringConverter;
import view.cellules.CelluleProduit;
+import view.uc.UCDetailParfum;
import view_modele.BoutiqueVM;
+import view_modele.ParfumVM;
import view_modele.ProduitVM;
import java.io.IOException;
@@ -18,28 +23,37 @@ import java.io.IOException;
public class MainWindow {
@FXML
- private TextField prixProduit;
-
- @FXML
- private TextField nomProduit;
+ public VBox layoutDetail;
@FXML
private ListView listeProduit;
private BoutiqueVM boutiqueVM;
+ private UCDetailParfum detailParfum;
+
public void initialize(){
boutiqueVM = new BoutiqueVM();
+ try {
+ detailParfum = new UCDetailParfum();
+ detailParfum.setVisibiliy(false);
+ layoutDetail.getChildren().add(detailParfum);
+ } catch (IOException e) {
+ new Alert(Alert.AlertType.ERROR, "Erreur lors de la sélection du parfum", ButtonType.OK);
+ }
listeProduit.setItems(boutiqueVM.getListeProduits());
listeProduit.setCellFactory((__) -> new CelluleProduit());
listeProduit.getSelectionModel().selectedItemProperty().addListener((__, oldV, newV) -> {
if(oldV != null){
- nomProduit.textProperty().unbindBidirectional(oldV.nomProperty());
- prixProduit.textProperty().unbindBidirectional(oldV.nomProperty());
+ if(oldV instanceof ParfumVM){
+ detailParfum.setVisibiliy(false);
+ }
}
if(newV != null) {
- nomProduit.textProperty().bindBidirectional(newV.nomProperty());
- prixProduit.textProperty().bindBidirectional(newV.nomProperty());
+ if(newV instanceof ParfumVM parfumVM){
+ detailParfum.setVisibiliy(true);
+ detailParfum.setProduit(parfumVM);
+ }
}
});
}
diff --git a/Boutique/src/view/uc/UCCommun.java b/Boutique/src/view/uc/UCCommun.java
new file mode 100644
index 0000000..076994e
--- /dev/null
+++ b/Boutique/src/view/uc/UCCommun.java
@@ -0,0 +1,36 @@
+package view.uc;
+
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.VBox;
+import javafx.util.converter.NumberStringConverter;
+import view_modele.ProduitVM;
+
+import java.io.IOException;
+
+public class UCCommun extends VBox {
+
+ @FXML
+ private TextField nomProduit;
+
+ @FXML
+ private TextField prixProduit;
+
+ public UCCommun() throws IOException {
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/uc/UC_Commun.fxml"));
+ loader.setController(this);
+ loader.setRoot(this);
+ loader.load();
+ }
+
+ public void bind(ProduitVM produit){
+ nomProduit.textProperty().bindBidirectional(produit.nomProperty());
+ prixProduit.textProperty().bindBidirectional(produit.prixProperty(), new NumberStringConverter());
+ }
+
+ public void unbind(ProduitVM produit){
+ nomProduit.textProperty().unbindBidirectional(produit.nomProperty());
+ prixProduit.textProperty().unbindBidirectional(produit.prixProperty());
+ }
+}
diff --git a/Boutique/src/view/uc/UCDetailHabit.java b/Boutique/src/view/uc/UCDetailHabit.java
index 5137c2b..2735aec 100644
--- a/Boutique/src/view/uc/UCDetailHabit.java
+++ b/Boutique/src/view/uc/UCDetailHabit.java
@@ -1,4 +1,28 @@
package view.uc;
-public class UCDetailHabit {
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.control.ListView;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.VBox;
+import view_modele.CouleurVM;
+
+import java.io.IOException;
+
+public class UCDetailHabit extends VBox {
+
+ @FXML
+ private ListView listeCouleurs;
+
+ private UCCommun ucCommun;
+
+ public UCDetailHabit() throws IOException {
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/uc/UC_DetailHabit.fxml"));
+ loader.setController(this);
+ loader.setRoot(this);
+ loader.load();
+
+ ucCommun = new UCCommun();
+ getChildren().add(ucCommun);
+ }
}
diff --git a/Boutique/src/view/uc/UCDetailParfum.java b/Boutique/src/view/uc/UCDetailParfum.java
new file mode 100644
index 0000000..78016b0
--- /dev/null
+++ b/Boutique/src/view/uc/UCDetailParfum.java
@@ -0,0 +1,77 @@
+package view.uc;
+
+import javafx.fxml.FXML;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.control.ListView;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.VBox;
+import view_modele.ParfumVM;
+
+import java.io.IOException;
+
+public class UCDetailParfum extends VBox {
+
+ private ParfumVM parfumVM;
+
+ @FXML
+ private ListView listeFragrances;
+
+ @FXML
+ private TextField nouvelleFragrance;
+
+ private UCCommun ucCommun;
+
+ public UCDetailParfum() throws IOException {
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/uc/UC_DetailParfum.fxml"));
+ loader.setRoot(this);
+ loader.setController(this);
+ loader.load();
+
+ ucCommun = new UCCommun();
+ getChildren().add(ucCommun);
+ }
+
+ public void setProduit(ParfumVM parfum){
+ this.parfumVM = parfum;
+ bind(parfum);
+ }
+
+ private void bind(ParfumVM parfum){
+ unbind();
+ ucCommun.bind(parfum);
+ listeFragrances.itemsProperty().bind(parfum.listeFragrancesProperty());
+ }
+
+ private void unbind(){
+ if(this.parfumVM != null){
+ ucCommun.unbind(parfumVM);
+ listeFragrances.itemsProperty().unbind();
+ nouvelleFragrance.setText("");
+ }
+ }
+
+ public void setVisibiliy(boolean visible){
+ if(!visible){
+ unbind();
+ }
+ super.setVisible(visible);
+ }
+
+ @FXML
+ private void ajouterFragrance(){
+ parfumVM.addFragrance(nouvelleFragrance.getText());
+ nouvelleFragrance.setText("");
+ }
+
+ @FXML
+ private void supprimerFragrance(){
+ parfumVM.removeFragrance(listeFragrances.getSelectionModel().getSelectedItem());
+ }
+
+ @FXML
+ private void deselectionner(){
+ //parfum.addFragrance(nouvelleFragrance.getText());
+ }
+
+
+}
diff --git a/Boutique/src/view_modele/BoutiqueVM.java b/Boutique/src/view_modele/BoutiqueVM.java
index c917c81..51709e9 100644
--- a/Boutique/src/view_modele/BoutiqueVM.java
+++ b/Boutique/src/view_modele/BoutiqueVM.java
@@ -57,11 +57,11 @@ public class BoutiqueVM implements PropertyChangeListener {
private ProduitVM creerProduitVM(Produit p){
ProduitVM produit = null;
- if(p instanceof Habit){
- produit = new HabitVM((Habit)p);
+ if(p instanceof Habit habit){
+ produit = new HabitVM(habit);
}
- else if(p instanceof Parfum){
- produit = new ParfumVM((Parfum)p);
+ else if(p instanceof Parfum parfum){
+ produit = new ParfumVM(parfum);
}
return produit;
diff --git a/Boutique/src/view_modele/HabitVM.java b/Boutique/src/view_modele/HabitVM.java
index 241b220..b038fdf 100644
--- a/Boutique/src/view_modele/HabitVM.java
+++ b/Boutique/src/view_modele/HabitVM.java
@@ -3,15 +3,23 @@ package view_modele;
import Modele.metier.Habit;
import Modele.metier.Produit;
+import java.beans.PropertyChangeEvent;
+
public class HabitVM extends ProduitVM {
public HabitVM(String nom, int prix){
- modele = new Habit(nom, prix);
+ this(new Habit(nom, prix));
+
+ }
+
+ public HabitVM(Habit produit){
+ this.modele = produit;
setNom(modele.getNom());
setPrix(modele.getPrix());
}
- public HabitVM(Habit produit){
- this(produit.getNom(), produit.getPrix());
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+
}
}
diff --git a/Boutique/src/view_modele/ParfumVM.java b/Boutique/src/view_modele/ParfumVM.java
index 69ed6f0..35e1561 100644
--- a/Boutique/src/view_modele/ParfumVM.java
+++ b/Boutique/src/view_modele/ParfumVM.java
@@ -3,16 +3,49 @@ package view_modele;
import Modele.metier.Habit;
import Modele.metier.Parfum;
import Modele.metier.Produit;
+import javafx.beans.property.ListProperty;
+import javafx.beans.property.SimpleListProperty;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+
+import java.beans.IndexedPropertyChangeEvent;
+import java.beans.PropertyChangeEvent;
+import java.util.List;
public class ParfumVM extends ProduitVM {
- public ParfumVM(String nom, int prix){
- modele = new Habit(nom, prix);
+ private ObservableList fragrancesObs = FXCollections.observableArrayList();
+ private ListProperty listeFragrances = new SimpleListProperty<>(fragrancesObs);
+ public ObservableList getListeFragrances() { return listeFragrances.get(); }
+ public ListProperty listeFragrancesProperty() { return listeFragrances; }
+ public void setListeFragrances(ObservableList listeFragrances) { this.listeFragrances.set(listeFragrances); }
+
+ public ParfumVM(String nom, int prix, List fragrances){
+ this(new Parfum(nom, prix, fragrances));
+ }
+
+ public ParfumVM(Parfum produit){
+ this.modele = produit;
setNom(modele.getNom());
setPrix(modele.getPrix());
+
+ modele.addListener(this);
+ fragrancesObs.addAll(produit.getFragrances());
}
- public ParfumVM(Parfum produit){
- this(produit.getNom(), produit.getPrix());
+ public void addFragrance(String fragrance){
+ ((Parfum)modele).ajouterFragrance(fragrance);
+ }
+
+ public void removeFragrance(String fragrance){
+ ((Parfum)modele).supprimerFragrance(fragrance);
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ switch (evt.getPropertyName()){
+ case Parfum.PROP_AJOUT_FRAGRANCE -> fragrancesObs.add(((IndexedPropertyChangeEvent)evt).getIndex(), (String)evt.getNewValue());
+ case Parfum.PROP_SUPPRESSION_FRAGRANCE -> fragrancesObs.remove((String)evt.getOldValue());
+ }
}
}
diff --git a/Boutique/src/view_modele/ProduitVM.java b/Boutique/src/view_modele/ProduitVM.java
index 6ebde3d..3a4d9c8 100644
--- a/Boutique/src/view_modele/ProduitVM.java
+++ b/Boutique/src/view_modele/ProduitVM.java
@@ -6,9 +6,10 @@ import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
+import java.beans.PropertyChangeListener;
import java.security.ProtectionDomain;
-public abstract class ProduitVM {
+public abstract class ProduitVM implements PropertyChangeListener {
protected Produit modele;