Reputation: 391
I have a InfosPatient class which contains the informations of a patient: His different names (birth name, official name...), different address (primary, work...), different phone numbers and other informations (sexe, birth date)
Here's is the class:
public class InfosPatient {
private Identity[] identities;
private String birthDate="";
private String sexe="";
private Adresse[] adresse;
private NumeroTelephone[] telephones;
private String numeroCafat="",numeroMed="";}
Here's the Identity class:
public class Identity {
private String prenom,nom;
private TypeNom typeNom;
TypeNom is an enumeration with 2 different values: Usuel (official name) and Naissance (birth name).
The address and phones classes are similar (with enumerations).
So my question is:
How to add in a TableView row the different identities in different columns?
I want to have a column with the birth name and another with the official name. Like this: One column with the official name and surname, a second with the birth name and surname.
Thank you for your help.
PS: To access a specific identity, I use this:
public Identity getIdentity(TypeNom typeNom) {
for (Identity identity:this.identities) {
if (identity.getTypeNom() == typeNom){
return identity;
}
}
return null;
}
Upvotes: 0
Views: 80
Reputation: 391
Okay so I find a solution: I just needed to use a ReadOnlyStringWrapper:
TableColumn<InfosPatient,Identity> identiteUsuelle = new TableColumn<>("Nom usuel");
TableColumn<InfosPatient,String> prenomUsuel = new TableColumn<>("Prenom");
prenomUsuel.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getIdentity(TypeNom.USUEL).getPrenom()));
TableColumn<InfosPatient,String> nomUsuel = new TableColumn<>("Nom");
nomUsuel.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getIdentity(TypeNom.USUEL).getNom()));
Upvotes: 1