Well, I figured it out, but I'd like input on whether or not my solution is practical.
I'm not familiar enough yet with JavaFX bindings and properties to know whether or not this solution is fine or if it would cause problems down the road.
concatColumns.setCellValueFactory(new Callback<CellDataFeatures<ObservableList, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(CellDataFeatures<ObservableList, String> p) {
final ObservableList row = p.getValue();
List<Observable> dependencies = new ArrayList<>();
for (Object value : row) {
if (value instanceof Observable) {
dependencies.add((Observable)value);
}
}
dependencies.add(row);
StringExpression se = Bindings.createStringBinding(new Callable<String>() {
@Override
public String call() throws Exception {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < row.size(); i++) {
//Check for Property objects and append the value
if (row.get(i) instanceof Property) {
sb.append(((Property)row.get(i)).getValue());
}
else {
sb.append(row.get(i));
}
if (i+1 < row.size()) {
sb.append(", ");
}
}
return sb.toString();
}
}, dependencies.toArray(new Observable[dependencies.size()]));
return se;
}
});
The TL;DR version:
I created my own StringExpression
using Bindings.createStringBinding()
and I added the ObservableList
as well as any of its values that were Observable
objects as the dependencies to the StringExpression
.
What I believe this will do is that whenever one of the list's values changes, the StringExpression
is notified to update. Additional, when the list itself changes (add/remove), the StringExpression
is notified to update.
Let me know if I'm wrong about the above statement!