java - JavaFX Application - architectural issue - diffrent lists of inherited classes -
i'm learning javafx tutorial http://code.makery.ch/library/javafx-8-tutorial/, in app i've made login module , want create 3 diffrent views - depending on type of user: admin, patient, doctor, , of them inherit user class. create doctor view , keep list of patients in main class:
private observablelist<patient> patientdata = fxcollections .observablearraylist(); public observablelist<patient> getpatientdata() { return patientdata; } public main() { patientdata.add(new patient("hans", "muster", 23)); }
i dont know should next move be. if make 1 list user , keep them doctors, patients , admins problem generating proper views, cause e.g doctor have patients' list. big problem me how serialize xml. if make 3 separate list won't 'elegant' way think.
you create single observablelist<user>
, , populate various views using filteredlist
.
e.g.
observablelist<user> userlist = fxcollections.observablearraylist(); // ... listview<user> patientview = new listview<>(); patientview.setitems(new filteredlist<>(userlist, patient.class::isinstance));
if want listview<patient>
instead of listview<user>
, easiest way use easybind library:
listview<patient> patientview = new list<view>(); patientview.setitems(easybind.map(new filteredlist<>(userlist, patient.class::isinstance), patient.class::cast);
Comments
Post a Comment