It's an application that manages students, and it has a class named StudentsViewController
that links the graphical part(the StudentView
) and the functions that effectively make the changes on an ArrayList
(the Service
). I'll show you the part I don't understand in JavaFX Graphic User Interfaces:
public class StudentViewController implements Observer<Student>{
private ObservableList<Student> model;
private StudentView view;
StudentService service;
public StudentViewController(StudentService service, StudentView view){
this.view=view;
this.model= FXCollections.observableArrayList(service.getAllStudents());
view.studTable.setItems(model);
this.service=service;
}
@Override
public void update(Observable<Student> observable) {
StudentService s=(StudentService)observable;
model.setAll(s.getAllStudents());
}
}
My question is:
If I have an ObservableList
that wraps my ArrayList
and a TableView
that uses the ObservableList
, why do I need the update function?
Why do I have to clear all the data from my model and put a new one there?