|
|
|
@ -2,17 +2,19 @@ package Modele.metier;
|
|
|
|
|
|
|
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
|
import java.beans.PropertyChangeSupport;
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class Boutique {
|
|
|
|
|
public class Boutique implements Serializable {
|
|
|
|
|
|
|
|
|
|
private List<Produit> produits;
|
|
|
|
|
|
|
|
|
|
private PropertyChangeSupport support = new PropertyChangeSupport(this);
|
|
|
|
|
transient private PropertyChangeSupport support = new PropertyChangeSupport(this);
|
|
|
|
|
|
|
|
|
|
public static final String PROP_AJOUT = "AjoutProduit";
|
|
|
|
|
public static final String PROP_SUPPRESSION = "SuppressionProduit";
|
|
|
|
|
|
|
|
|
|
public Boutique(){
|
|
|
|
|
produits = new ArrayList<>();
|
|
|
|
@ -23,7 +25,7 @@ public class Boutique {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addListener(PropertyChangeListener listener){
|
|
|
|
|
support.addPropertyChangeListener(listener);
|
|
|
|
|
getSupport().addPropertyChangeListener(listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ajouterProduit(Produit produit){
|
|
|
|
@ -34,17 +36,29 @@ public class Boutique {
|
|
|
|
|
Produit produit = new Habit(nom, prix);
|
|
|
|
|
produits.add(produit);
|
|
|
|
|
int index = produits.size() - 1;
|
|
|
|
|
support.fireIndexedPropertyChange(PROP_AJOUT, index, null, produit);
|
|
|
|
|
getSupport().fireIndexedPropertyChange(PROP_AJOUT, index, null, produit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ajouterParfum(String nom, int prix, List<String> fragrances){
|
|
|
|
|
Produit produit = new Parfum(nom, prix, fragrances);
|
|
|
|
|
produits.add(produit);
|
|
|
|
|
int index = produits.size() - 1;
|
|
|
|
|
support.fireIndexedPropertyChange(PROP_AJOUT, index, null, produit);
|
|
|
|
|
getSupport().fireIndexedPropertyChange(PROP_AJOUT, index, null, produit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void supprimerProduit(Produit produit){
|
|
|
|
|
produits.remove(produit);
|
|
|
|
|
getSupport().firePropertyChange(PROP_SUPPRESSION, produit, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Produit> getProduits() {
|
|
|
|
|
return Collections.unmodifiableList(produits);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected PropertyChangeSupport getSupport() {
|
|
|
|
|
if(support == null){
|
|
|
|
|
support = new PropertyChangeSupport(this);
|
|
|
|
|
}
|
|
|
|
|
return support;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|