JavaFX TableView Nested Property Binding -


i have list of objects containing lists of complex data type , need bind these properties tableview. entities looking this:

public class customer {    stringproperty property1;    stringproperty property2;    ....    list<contract> contracts; }   public class contract {     stringproperty property1;     stringproperty property2;     .... } 

my observablearraylist contains list of customer contains list of contract. getting customer properties easy:

samplecolumn1.setcellvaluefactory(celldata -> celldata.getvalue().sampleproperty1()); samplecolumn2.setcellvaluefactory(celldata -> celldata.getvalue().sampleproperty2()); ... 

but can't properties of contract list.. following workaround:

propertyvaluefactory<customer, list<contract>> contractfactory = new propertyvaluefactory<>("contracts"); contractidcolumn.setcellvaluefactory(contractfactory); contractidcolumn.setcellfactory(celldata -> new tablecell<customer>, list<contract>>(){ @override public void updateitem(list<contract> contracts, boolean empty){     super.updateitem(contracts, empty);     if(empty)     settext("");                 else     settext(contracts.stream().map(contract::getcontractid)    .collect(collectors.joining("\n"))); } }); 

but code dirty, know approach cellvaluefactory , lambda expressions? suggestions?

a cell value factory callback taking celldatafeatures , returning appropriate observable value, should able this:

contractidcolumn.setcellvaluefactory(celldatafeatures -> new simplestringproperty(celldatafeatures.getvalue().contracts.stream()     .map(contract::getcontractid)     .collect(collectors.joining("\n"))));   

note if use observablelist instead of list use bindings.createstringbinding value update if list updates customer element not change.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -