1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
package application;
import java.util.Arrays;
import application.models.Adresse;
import application.models.Utilisateur;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.util.Callback;
public class SampleController {
@FXML
private BorderPane bPane;
@FXML
private TableView<Utilisateur> userTab;
@FXML
private TableColumn<Utilisateur, SimpleStringProperty> nomCol;
@FXML
private TableColumn<Utilisateur,SimpleStringProperty> prenomCol;
@FXML
private TableColumn<Utilisateur,SimpleObjectProperty<Adresse>> villeCol;
@FXML
private Label titre;
@FXML
private Button valider;
@FXML
public void initialize(){
valider.setDisable(true);
double size = userTab.getWidth()/3;
nomCol.setMinWidth(size);
prenomCol.setMinWidth(size);
villeCol.setMinWidth(size);
titre.setAlignment(Pos.CENTER);
initialisationTableau();
Utilisateur user1 = new Utilisateur();
Utilisateur user2 = new Utilisateur();
Utilisateur user3 = new Utilisateur();
user1.setNom(new SimpleStringProperty("Durand"));
user2.setNom(new SimpleStringProperty("Dupont"));
user3.setNom(new SimpleStringProperty("Marion"));
user1.setPrenom(new SimpleStringProperty("Louis"));
user2.setPrenom(new SimpleStringProperty("Julie"));
user3.setPrenom(new SimpleStringProperty("Jacques"));
Adresse adresse1 = new Adresse();
Adresse adresse2 = new Adresse();
Adresse adresse3 = new Adresse();
adresse1.setCodePostal(new SimpleLongProperty(Long.valueOf(33000)));
adresse2.setCodePostal(new SimpleLongProperty(Long.valueOf(33000)));
adresse3.setCodePostal(new SimpleLongProperty(Long.valueOf(33000)));
adresse1.setRue(new SimpleStringProperty("1 rue du jardin public"));
adresse2.setRue(new SimpleStringProperty("1 cours Aristide Briand"));
adresse3.setRue(new SimpleStringProperty("1 rue sainte Catherine"));
adresse1.setVille(new SimpleStringProperty("Bordeaux"));
adresse2.setVille(new SimpleStringProperty("Bordeaux"));
adresse3.setVille(new SimpleStringProperty("Bordeaux"));
user1.setAdresse(new SimpleObjectProperty<Adresse>(adresse1));
user2.setAdresse(new SimpleObjectProperty<Adresse>(adresse2));
user3.setAdresse(new SimpleObjectProperty<Adresse>(adresse3));
userTab.setItems(FXCollections.observableList(Arrays.asList(user1,user2,user3)));
System.out.println(userTab.skinProperty().toString());
}
public void initialisationTableau(){
this.nomCol.setCellValueFactory(new PropertyValueFactory<Utilisateur,SimpleStringProperty>("nom"));
this.prenomCol.setCellValueFactory(new PropertyValueFactory<Utilisateur,SimpleStringProperty>("prenom"));
this.villeCol.setCellValueFactory(new PropertyValueFactory<Utilisateur,SimpleObjectProperty<Adresse>>("adresse"));
villeCol.setCellFactory(new Callback<TableColumn<Utilisateur, SimpleObjectProperty<Adresse>>, TableCell<Utilisateur, SimpleObjectProperty<Adresse>>>(){
@Override
public TableCell<Utilisateur, SimpleObjectProperty<Adresse>> call(TableColumn<Utilisateur, SimpleObjectProperty<Adresse>> arg0) {
TableCell<Utilisateur, SimpleObjectProperty<Adresse>> villeCell = new TableCell<Utilisateur, SimpleObjectProperty<Adresse>>(){
@Override
protected void updateItem(SimpleObjectProperty<Adresse> item, boolean empty) {
if (item != null) {
setText(item.get().getVille().get());
}
}
};
return villeCell;
}
});
}
public void valider(ActionEvent event){
ObservableList<Utilisateur> userListe = userTab.getSelectionModel().getSelectedItems();
userListe.forEach(ee -> System.out.println(ee.getNom() + " " + ee.getPrenom()));
}
} |
Partager