|
- package de.uniluebeck.mi.projmi6.controller;
-
- /**
- * Created by Johannes on 12.11.15.
- */
- import de.uniluebeck.mi.projmi6.db.DBHandler;
- import de.uniluebeck.mi.projmi6.model.Patient;
- import de.uniluebeck.mi.projmi6.model.Station;
- import de.uniluebeck.mi.projmi6.model.StationsUebersichtsItem;
- import javafx.beans.binding.Bindings;
- import javafx.beans.binding.ObjectBinding;
- import javafx.beans.property.ObjectProperty;
- import javafx.beans.property.ReadOnlyObjectProperty;
- import javafx.beans.property.SimpleObjectProperty;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.*;
- import javafx.scene.control.cell.PropertyValueFactory;
- import javafx.scene.image.Image;
- import javafx.stage.Modality;
- import javafx.stage.Stage;
-
- import java.io.IOException;
- import java.rmi.server.ExportException;
- import java.sql.SQLException;
- import java.time.LocalDate;
-
- /**
- * Controller class.
- */
- public class PatientTablesController{
-
- private MainController mainController;
-
- @FXML
- private Label lblTablePatientEmpty;
-
- @FXML
- private Label lblTableStationEmpty;
-
- @FXML
- private Button btnPatCreate;
-
- @FXML
- private Button btnPatEdit;
-
- @FXML
- private TableView<Patient> tblPatientOverview;
-
- @FXML
- private TableColumn<Patient, String> colPatPatId;
-
- @FXML
- private TableColumn<Patient, String> colPatGeburtsname;
-
- @FXML
- private TableColumn<Patient, String> colPatNachname;
-
- @FXML
- private TableColumn<Patient, String> colPatVorname;
-
- @FXML
- private TableColumn<Patient, LocalDate> colPatGebDatum;
-
- @FXML
- private TableColumn<Patient, String> colPatStrasse;
-
- @FXML
- private TableColumn<Patient, String> colPatPlz;
-
- @FXML
- private TableColumn<Patient, String> colPatOrt;
-
- @FXML
- private TableColumn<Patient, String> colPatCave;
-
-
-
-
- @FXML
- private ToggleButton btnEntlassenePatientenZeigen;
-
- @FXML
- private ComboBox<Station> cmbStationenFilter;
-
- @FXML
- private TableView<StationsUebersichtsItem> tblStationOverview;
-
- @FXML
- private TableColumn<StationsUebersichtsItem, String> colStatPatId;
-
- @FXML
- private TableColumn<StationsUebersichtsItem, String> colStatFullName;
-
- @FXML
- private TableColumn<StationsUebersichtsItem, String> colStatGebDatum;
-
- @FXML
- private TableColumn<StationsUebersichtsItem, String> colStatAlter;
-
- @FXML
- private TableColumn<StationsUebersichtsItem, String> colStatAufnahmedatum;
-
- @FXML
- private TableColumn<StationsUebersichtsItem, String> colStatEntlassungsdatum;
-
- @FXML
- private Tab stationOverviewTab, patientOverviewTab;
-
- @FXML
- private TabPane patientOverviewTabPane;
-
-
- public PatientTablesController(MainController mainController){
- this.mainController = mainController;
- }
-
-
- @FXML
- public void initialize() {
- btnPatEdit.disableProperty().bind(tblPatientOverview.getSelectionModel().selectedItemProperty().isNull());
- tblPatientOverview.setRowFactory(tableView -> {
- TableRow<Patient> tableRow = new TableRow<>();
- tableRow.setOnMouseClicked(event -> {
- if(event.getClickCount()==2 && (!tableRow.isEmpty())){
- Patient patient = tableRow.getItem();
- showEditWindow(patient);
- }
- });
- return tableRow;
- });
- lblTablePatientEmpty.setText("Liste ist leer.");
- lblTableStationEmpty.setText("Daten werden geladen...");
-
- cmbStationenFilter.itemsProperty().bind(mainController.stationenProperty());
-
- ObservableList<Patient> patientList = null;
- try {
- patientList = FXCollections.<Patient>observableArrayList(DBHandler.getAllPatients());
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
-
- patientObjectBinding = Bindings.<Patient>createObjectBinding(() ->{
- return patientOverviewTabPane.getSelectionModel().getSelectedItem().equals(patientOverviewTab)
- ? tblPatientOverview.getSelectionModel().getSelectedItem()
- : null; //(Patient)tblStationOverview.getSelectionModel().getSelectedItem(); //TODO
- }, tblPatientOverview.getSelectionModel().selectedItemProperty(),
- tblStationOverview.getSelectionModel().selectedItemProperty(),
- patientOverviewTabPane.getSelectionModel().selectedItemProperty());
-
- tblPatientOverview.setItems(patientList);
-
- initColumnsPatient();
- initColumnsStation();
- }
-
- private void initColumnsPatient(){
- colPatPatId.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patIDProperty().asString());
- colPatGeburtsname.setCellValueFactory(new PropertyValueFactory<>("geburtsname"));
- colPatNachname.setCellValueFactory(new PropertyValueFactory<>("nachname"));
- colPatVorname.setCellValueFactory(new PropertyValueFactory<>("vorname"));
- colPatGebDatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().geburtsdatumProperty());
- colPatStrasse.setCellValueFactory(cellDataFeatures -> {
- Patient patient = cellDataFeatures.getValue();
- return Bindings.concat(patient.strasseProperty(), " ", patient.hausnummerProperty());
- });
- colPatPlz.setCellValueFactory(new PropertyValueFactory<>("plz"));
- colPatOrt.setCellValueFactory(new PropertyValueFactory<>("ort"));
- colPatCave.setCellValueFactory(new PropertyValueFactory<>("cave"));
- }
-
-
- private void initColumnsStation(){
- colStatPatId.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patIdProperty().asString());
- colStatFullName.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patNameProperty());
- colStatGebDatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patBirthdateProperty().asString());
- colStatAlter.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().patAgeProperty().asString());
- colStatAufnahmedatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().stationAufnahmeProperty().asString());
- colStatEntlassungsdatum.setCellValueFactory(cellDataFeatures -> cellDataFeatures.getValue().stationEntlassungProperty().asString());
- }
-
- @FXML
- private void clickedCreatePatient (){
- showEditWindow(null);
- }
-
-
- @FXML
- private void clickedEditPatient(){
- showEditWindow(tblPatientOverview.getSelectionModel().getSelectedItem());
- }
-
- private void showEditWindow(Patient patient){
- FXMLLoader fxmlLoader = new FXMLLoader();
- fxmlLoader.setLocation(getClass().getClassLoader().getResource("patient_edit.fxml"));
- PatientEditorController patientEditorController = new PatientEditorController(mainController);
- fxmlLoader.setControllerFactory(clazz -> patientEditorController);
-
- Parent root = null;
- try{
- root = fxmlLoader.load();
- }catch (IOException e){
- e.printStackTrace();
- return;
- }
-
- Stage stage = new Stage();
-
- stage.setTitle(patient==null ? "Neuen Patienten erstellen": "Patient bearbeiten");
- stage.setScene(new Scene(root, 600, 600));
-
- stage.getIcons().add(new Image("icon.png"));
-
- stage.initModality(Modality.WINDOW_MODAL);
- stage.initOwner(btnPatEdit.getScene().getWindow());
- patientEditorController.setPatient(patient);
- stage.show();
- }
-
-
- private ObjectBinding<Patient> patientObjectBinding = null;
-
- public ObjectBinding<Patient> selectedPatientProperty(){
- return patientObjectBinding;
- }
-
- public Patient getSelectedPatient(){
- return selectedPatientProperty().get();
- }
-
- }
|