Detail parfum fonctionnel + début detail habit

master
Louis PERRET 3 years ago
parent 3e344a8f74
commit db1f986314

@ -23,15 +23,6 @@
</left>
<center>
<VBox>
<HBox>
<Label text="Nom : "/>
<TextField fx:id="nomProduit"/>
</HBox>
<HBox>
<Label text="Prix : "/>
<TextField fx:id="prixProduit"/>
</HBox>
</VBox>
<VBox fx:id="layoutDetail"/>
</center>
</BorderPane>

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<fx:root type="VBox" xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
prefHeight="400.0" prefWidth="600.0">
<HBox>
<Label text="Nom : "/>
<TextField fx:id="nomProduit"/>
</HBox>
<HBox>
<Label text="Prix : "/>
<TextField fx:id="prixProduit"/>
</HBox>
</fx:root>

@ -6,9 +6,12 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
<fx:root type="VBox" xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="view.uc.UCDetailHabit"
prefHeight="400.0" prefWidth="600.0">
</AnchorPane>
<VBox>
<ListView fx:id="listeCouleurs"/>
</VBox>
</fx:root>

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import view.uc.UCCommun?>
<fx:root type="VBox" xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
prefHeight="400.0" prefWidth="600.0">
<ListView fx:id="listeFragrances"/>
<HBox>
<TextField fx:id="nouvelleFragrance"/>
<Button onAction="#ajouterFragrance" text="Ajouter"/>
<Button onAction="#supprimerFragrance" text="Supprimer"/>
<Button text="Désélectionner" onAction="#deselectionner"/>
</HBox>
</fx:root>

@ -8,6 +8,10 @@ public class Parfum extends Produit{
private List<String> 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<String> getFragrances(){

@ -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;
}

@ -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);

@ -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<ProduitVM> 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);
}
}
});
}

@ -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());
}
}

@ -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<CouleurVM> 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);
}
}

@ -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<String> 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());
}
}

@ -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;

@ -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) {
}
}

@ -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<String> fragrancesObs = FXCollections.observableArrayList();
private ListProperty<String> listeFragrances = new SimpleListProperty<>(fragrancesObs);
public ObservableList<String> getListeFragrances() { return listeFragrances.get(); }
public ListProperty<String> listeFragrancesProperty() { return listeFragrances; }
public void setListeFragrances(ObservableList<String> listeFragrances) { this.listeFragrances.set(listeFragrances); }
public ParfumVM(String nom, int prix, List<String> 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());
}
}
}

@ -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;

Loading…
Cancel
Save