0

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;
}
2
  • The same way you would define the value of any TableColumn, set the appropriate cellValueFactory. Inside this factory you'd grab the correct Identity based on the TableColumn said factory is for. Commented Nov 8, 2018 at 3:37
  • Thank you for your comment, it's the first time I create a TableView so I don't know what to put in the setCellValueFactory method. Do you have a example please? I already did it with the birthdate: birthDate.setCellValueFactory(new PropertyValueFactory<>("birthDate")); Commented Nov 8, 2018 at 3:53

1 Answer 1

1

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()));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.