Instead of pointing a propertyvaluefactory to a property of an object as follows:
traineeCol.setCellValueFactory(new PropertyValueFactory("sumName"));
I need it to point to a property inside a map, the map in turn is a property of the object it already is pointing to in the code above. Is this possible?
edit: added code of the object in question. So basically, i need the PropertyValueFactory to point toward the Integer with given key, the key being the column header.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package models;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import database.DAO;
import java.util.Map;
/**
*
* @author Jasper
*/
public class Trainee {
private final StringProperty firstName;
private final StringProperty tussenVoegsel;
private final StringProperty lastName;
private final StringProperty branch;
private final StringProperty sumName;
private final Map<String, Integer> trainingPassed;
public Trainee(String firstName, String tussenVoegsel, String lastName, String branch)
{
this.firstName = new SimpleStringProperty(firstName);
this.tussenVoegsel = new SimpleStringProperty(tussenVoegsel);
this.lastName = new SimpleStringProperty(lastName);
this.branch = new SimpleStringProperty(branch);
trainingPassed = new DAO().loadTrainingPassed(lastName);
this.sumName = new SimpleStringProperty(this.firstName.get() + " " +
this.tussenVoegsel.get() + " " + this.lastName.get());
}
public String getFirstName() {
return firstName.get();
}
public String getTussenVoegsel() {
return tussenVoegsel.get();
}
public String getLastName() {
return lastName.get();
}
public String getBranch() {
return branch.get();
}
public String getSumName() {
return sumName.get();
}
public Map<String, Integer> getTrainingPassed() {
return trainingPassed;
}
}
Edit2: Added code area of tableview, including declarations etc.
@SuppressWarnings("unchecked")
private TableView table() {
TableView tableCourseCategories = new TableView();
ArrayList<TableColumn> colList = new ArrayList<>();
TableColumn traineeCol = new TableColumn("Training");
traineeCol.setMinWidth(130);
traineeCol.setCellValueFactory(new PropertyValueFactory("sumName"));
for (Course course : courses) {
if (course.getCategory().equals(this.category)) {
TableColumn<Trainee, Number> tc = new TableColumn<>();
tc.setEditable(true);
tc.setMinWidth(130);
tc.setText(course.getName());
// tc.setCellValueFactory(new Callback<CellDataFeatures<Trainee>>, ObservableValue<Number>>() {
// @Override
// public ObservableValue<Number> call(CellDataFeatures<Trainee> data) {
// Integer value = data.getValue().getTrainingPassed().get("sumName");
// return new ReadOnlyIntegerWrapper(value);
// }
// });
colList.add(tc);
}
}
tableCourseCategories.getItems().addAll(this.trainees);
tableCourseCategories.getColumns().add(traineeCol);
tableCourseCategories.getColumns().addAll(colList);
return tableCourseCategories;
}