From 5e74290ec48c6ce2766df7139b0585b4a22539bc Mon Sep 17 00:00:00 2001 From: Johannes Date: Mon, 23 Nov 2015 23:52:54 +0100 Subject: [PATCH] JavaDoc, Refactoring --- .../mi/projmi6/controller/DiagnoseController.java | 56 +++++-- .../controller/StationsHistorieController.java | 163 ++++++++++++++------- src/main/resources/diagnose.fxml | 2 +- src/main/resources/stationshistorie.fxml | 3 +- 4 files changed, 161 insertions(+), 63 deletions(-) diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/DiagnoseController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/DiagnoseController.java index dc089d1..0dcc0bf 100644 --- a/src/main/java/de/uniluebeck/mi/projmi6/controller/DiagnoseController.java +++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/DiagnoseController.java @@ -1,6 +1,7 @@ package de.uniluebeck.mi.projmi6.controller; +import com.sun.prism.shader.Solid_Color_AlphaTest_Loader; import de.uniluebeck.mi.projmi6.db.DBHandler; import de.uniluebeck.mi.projmi6.model.DiagArt; import de.uniluebeck.mi.projmi6.model.Diagnose; @@ -26,6 +27,16 @@ public class DiagnoseController { private SimpleObjectProperty> diagnosen = new SimpleObjectProperty<>(); + /** + * Controller state definitions + */ + public enum State { + CREATE, EDIT, VIEW + } + + /** + * Current controllers state + */ private final SimpleObjectProperty state = new SimpleObjectProperty<>(State.VIEW); @FXML @@ -65,6 +76,7 @@ public class DiagnoseController { return diagnosen.get(); } + /** * Setter for the {@link #diagnosenProperty()}. * @param diagnosen A observable list of diagnosis to be set. @@ -118,6 +130,7 @@ public class DiagnoseController { fields.disableProperty().bind(state.isEqualTo(State.VIEW)); diagnoseList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); + diagnoseList.disableProperty().bind(state.isNotEqualTo(State.VIEW)); diagnoseList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { if (newValue == null) { clearFields(); @@ -126,6 +139,24 @@ public class DiagnoseController { } }); + state.addListener((observable, oldValue, newValue) -> { + if(newValue == State.VIEW){ + mainController.unlockFromEdit(); + Diagnose diagnose = diagnoseList.getSelectionModel().getSelectedItem(); + if (diagnose == null) { + clearFields(); + } else { + copyDiagnoseDataIntoFields(diagnose); + } + }else{ + mainController.lockForEdit(MainController.TabName.DIAGNOSE); + if(newValue==State.CREATE){ + clearFields(); + diagDiagnoseArzt.setValue(mainController.getCurrentMitarbeiter()); + } + } + }); + } @@ -163,12 +194,6 @@ public class DiagnoseController { @FXML private void clickedAbort() { state.set(State.VIEW); - Diagnose diagnose = diagnoseList.getSelectionModel().getSelectedItem(); - if (diagnose == null) { - clearFields(); - } else { - copyDiagnoseDataIntoFields(diagnose); - } } /** @@ -187,6 +212,9 @@ public class DiagnoseController { } + /** + * EventHandler method for {@link #btnDiagSave} + */ @FXML void clickedDiagSave() { if (state.get() == State.CREATE) { @@ -203,8 +231,13 @@ public class DiagnoseController { } mainController.refreshCaseData(); + state.set(State.VIEW); } + /** + * Copy the object data into the fields. + * @param diagnose The object with the data. + */ private void copyDiagnoseDataIntoFields(Diagnose diagnose) { diagDiagnoseArzt.setValue(diagnose.getArzt()); @@ -219,6 +252,10 @@ public class DiagnoseController { diagChangeTime.setText(diagnose.getBearbeitetDatumZeit().toString()); } + /** + * Copy the data from the ComboBoxes into data model object + * @param diagnose The object to copy the data into + */ private void copyFieldDataIntoDiagnose(Diagnose diagnose) { diagnose.setIcd10code(diagDiagnose.getValue()); diagnose.setArzt(diagDiagnoseArzt.getValue()); @@ -230,6 +267,10 @@ public class DiagnoseController { diagnose.setBearbeiter(mainController.getCurrentMitarbeiter().getMitarbID()); } + /** + * Clear the fields in case no diagnosis is selcted, or + * creating a new one is started. + */ private void clearFields() { diagDiagnoseArzt.setValue(mainController.getCurrentMitarbeiter()); diagDiagnose.setValue(null); @@ -242,7 +283,4 @@ public class DiagnoseController { diagChangeTime.setText(""); } - public enum State { - CREATE, EDIT, VIEW - } } diff --git a/src/main/java/de/uniluebeck/mi/projmi6/controller/StationsHistorieController.java b/src/main/java/de/uniluebeck/mi/projmi6/controller/StationsHistorieController.java index 3435f32..10c84aa 100644 --- a/src/main/java/de/uniluebeck/mi/projmi6/controller/StationsHistorieController.java +++ b/src/main/java/de/uniluebeck/mi/projmi6/controller/StationsHistorieController.java @@ -26,29 +26,19 @@ import java.util.stream.Collectors; /** * The controller class for the hospital ward history. - *

+ * @author Johannes * Created by Johannes on 12.11.15. */ public class StationsHistorieController { - private final SimpleObjectProperty state = new SimpleObjectProperty<>(State.VIEW); - @FXML - private Button btnStatHistAbort; + private MainController mainController; + @FXML private GridPane fields; @FXML - private Button btnStatHistEdit; - @FXML - private Button btnStatHistDelete; - /** - * The station history that is shown in the edit window, or null if a new station history should be created. - */ - private StationsHistorie stationsHistorieSelected = null; - private MainController mainController; - @FXML private TableView tblStationsHistorie; @FXML - private Button btnStatHistCancel, btnStatHistSave; + private Button btnStatHistSave, btnStatHistCreate, btnStatHistEdit, btnStatHistDelete, btnStatHistAbort; @FXML private Label statHistCreator, statHistCreateTime, statHistEditor, statHistEditTime; @FXML @@ -63,26 +53,56 @@ public class StationsHistorieController { private ComboBox cmbAbteilung; private SimpleObjectProperty> stationsHistorie = new SimpleObjectProperty<>(); - @FXML - private Button btnStatHistCreate; + + /** + * Definition of the controllers states. + */ + public enum State { + CREATE, EDIT, VIEW; + } + + /** + * The current state of the controller. + */ + private final SimpleObjectProperty state = new SimpleObjectProperty<>(State.VIEW); + + /** + * Constructor + * @param mainController + */ public StationsHistorieController(MainController mainController) { this.mainController = mainController; } + + /** + * EventHandler for the {@link #btnStatHistEdit} + */ @FXML private void clickedEdit() { this.state.set(State.EDIT); } + /** + * Getter for the {@link #stateProperty()} + * @return The stateProperty's value. + */ public State getState() { return state.get(); } + + /** + * @return Property of the controllers state + */ public ReadOnlyObjectProperty stateProperty() { return state; } + /** + * initialize()-method of the controller. + */ @FXML private void initialize() { initColumns(); @@ -106,12 +126,16 @@ public class StationsHistorieController { }); + tblStationsHistorie.disableProperty().bind(state.isNotEqualTo(State.VIEW)); tblStationsHistorie.itemsProperty().bind(stationsHistorie); tblStationsHistorie.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> { setStationsHistorieSelected(newValue); }); } + /** + * Show/hide/disable buttons depending on the controller state + */ private void initButtons() { // btnStatHistCancel.visibleProperty().bind(state.isEqualTo(State.VIEW).and(tblStationsHistorie.getSelectionModel().selectedItemProperty().isNotNull())); // btnStatHistCancel.managedProperty().bind(btnStatHistCancel.visibleProperty()); @@ -130,22 +154,25 @@ public class StationsHistorieController { btnStatHistDelete.managedProperty().bind(btnStatHistDelete.visibleProperty()); } + + /** + * Init the comboboxes for the wards + */ private void initStationsFilter() { final String any = "beliebig"; + //Finde die Abteilungen und setzte in die ComboBox List abteilungen = mainController.getStammdaten().getStationen().stream() - .map(stat -> stat.getAbteilung()).distinct().collect(Collectors.toList()); - Collections.sort(abteilungen); + .map(stat -> stat.getAbteilung()).distinct().sorted().collect(Collectors.toList()); + cmbAbteilung.setItems(FXCollections.observableArrayList(abteilungen)); cmbAbteilung.getItems().add(0, any); cmbAbteilung.getSelectionModel().select(0); new SelectKeyComboBoxListener(cmbAbteilung); - tblStationsHistorie.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { - setStationsHistorieSelected(newValue); - }); + //Filtere die Stationscombobox nach ausgewaehlter Abteilung FilteredList stationenFiltered = new FilteredList(mainController.getStammdaten().getStationen()); stationenFiltered.predicateProperty().bind(Bindings.createObjectBinding(() -> { @@ -155,20 +182,16 @@ public class StationsHistorieController { return p -> p.getAbteilung().equals(cmbAbteilung.getValue()); }, cmbAbteilung.valueProperty())); - cmbStation.setItems(stationenFiltered); new SelectKeyComboBoxListener(cmbStation); } - @FXML - private void clickedCancel() { - // this.state.set(State.VIEW); - } + /** + * EventHandler for {@link #btnStatHistSave}. + */ @FXML private void clickedSave() { - - if (getState() == State.CREATE) { StationsHistorie stationsHistorie = new StationsHistorie(); copyFieldDataIntoStationsHistorie(stationsHistorie); @@ -182,6 +205,7 @@ public class StationsHistorieController { } mainController.refreshCaseData(); } else { + StationsHistorie stationsHistorieSelected = tblStationsHistorie.getSelectionModel().getSelectedItem(); copyFieldDataIntoStationsHistorie(stationsHistorieSelected); if (!validateData(stationsHistorieSelected)) { return; @@ -196,18 +220,31 @@ public class StationsHistorieController { state.set(State.VIEW); } + + /** + * EventHandler for {@link #btnStatHistAbort}. + */ @FXML private void clickedAbort() { state.set(State.VIEW); - copyStationsHistorieDataIntoFields(); + StationsHistorie stationsHistorieSelected = tblStationsHistorie.getSelectionModel().getSelectedItem(); + copyStationsHistorieDataIntoFields(stationsHistorieSelected); } + + /** + * EventHandler for {@link #btnStatHistCreate}. + */ @FXML private void clickedCreateAufenthalt() { this.state.set(State.CREATE); setStationsHistorieSelected(null); } + + /** + * EventHandler for the {@link #btnStatHistDelete} button. + */ @FXML private void clickedDelete() { StationsHistorie selectedItem = tblStationsHistorie.getSelectionModel().getSelectedItem(); @@ -217,7 +254,7 @@ public class StationsHistorieController { alert.setTitle("Stationsaufenthalt kann nicht entfernt werden!"); alert.setHeaderText(null); alert.setContentText("Der Aufenthalt muss in der Zukunft liegen, um gel\u00f6scht werden zu k\u00f6nnen!"); - alert.initOwner(btnStatHistCancel.getScene().getWindow()); + alert.initOwner(btnStatHistDelete.getScene().getWindow()); alert.initModality(Modality.APPLICATION_MODAL); alert.showAndWait(); return; @@ -230,30 +267,39 @@ public class StationsHistorieController { } mainController.refreshCaseData(); - - } + /** + * A getter for {@link #stationsHistorieProperty()} + * @return The value of that property. + */ public ObservableList getStationsHistorie() { return stationsHistorie.get(); } + /** + * Setter for the {@link #stationsHistorieProperty()} + * @param stationsHistorie The value to be set. + */ public void setStationsHistorie(ObservableList stationsHistorie) { this.stationsHistorie.set(stationsHistorie); } + /** + * The list that will be shown in the TableView. + * @return A property to that list. + */ public SimpleObjectProperty> stationsHistorieProperty() { return stationsHistorie; } public void setStationsHistorieSelected(StationsHistorie stationsHistorie) { - this.stationsHistorieSelected = stationsHistorie; if (stationsHistorie == null) { clearFields(); } else { - copyStationsHistorieDataIntoFields(); + copyStationsHistorieDataIntoFields(stationsHistorie); } - + tblStationsHistorie.getSelectionModel().select(stationsHistorie); } private void initColumns() { @@ -262,16 +308,19 @@ public class StationsHistorieController { colStatHistEntlassungsDatum.setCellValueFactory(new PropertyValueFactory("entlassungsDatum")); } - private void copyStationsHistorieDataIntoFields() { - if (stationsHistorieSelected == null) { + /** + * Copies the data from the given StationsHistorie into the fields in the GUI. + */ + private void copyStationsHistorieDataIntoFields(StationsHistorie stationsHistorie) { + if (stationsHistorie == null) { clearFields(); return; } //Setze Station im Dropdownfeld for (Station station : cmbStation.getItems()) { - if (station.getStation().equals(stationsHistorieSelected.getStationKey())) { + if (station.getStation().equals(stationsHistorie.getStationKey())) { cmbStation.getSelectionModel().select(station); cmbAbteilung.getSelectionModel().select(station.getAbteilung()); break; @@ -279,19 +328,23 @@ public class StationsHistorieController { } - dtTmAufnahme.setDateTime(stationsHistorieSelected.getAufnahmeDatum()); - dtTmEntlassung.setDateTime(stationsHistorieSelected.getEntlassungsDatum()); + dtTmAufnahme.setDateTime(stationsHistorie.getAufnahmeDatum()); + dtTmEntlassung.setDateTime(stationsHistorie.getEntlassungsDatum()); - statHistCreator.setText(Integer.toString(stationsHistorieSelected.getErsteller())); - if (stationsHistorieSelected.getErstellDatumZeit() != null) { - statHistCreateTime.setText(stationsHistorieSelected.getErstellDatumZeit().toString()); + statHistCreator.setText(Integer.toString(stationsHistorie.getErsteller())); + if (stationsHistorie.getErstellDatumZeit() != null) { + statHistCreateTime.setText(stationsHistorie.getErstellDatumZeit().toString()); } - statHistEditor.setText(Integer.toString(stationsHistorieSelected.getBearbeiter())); - if (stationsHistorieSelected.getBearbeitetDatumZeit() != null) { - statHistEditTime.setText(stationsHistorieSelected.getBearbeitetDatumZeit().toString()); + statHistEditor.setText(Integer.toString(stationsHistorie.getBearbeiter())); + if (stationsHistorie.getBearbeitetDatumZeit() != null) { + statHistEditTime.setText(stationsHistorie.getBearbeitetDatumZeit().toString()); } } + /** + * Copies the data entered in the fields into {@link de.uniluebeck.mi.projmi6.model.StationsHistorie} objects. + * @param stationsHistorie The object in which the data will be copied + */ private void copyFieldDataIntoStationsHistorie(StationsHistorie stationsHistorie) { stationsHistorie.setAufnahmeDatum(dtTmAufnahme.getDateTime()); stationsHistorie.setEntlassungsDatum(dtTmEntlassung.getDateTime()); @@ -306,7 +359,11 @@ public class StationsHistorieController { stationsHistorie.setBearbeiter(mainController.getCurrentMitarbeiter().getMitarbID()); } - + /** + * Helper method for {@link #validateData(StationsHistorie)}. Opens a error window. + * @param title The Alerts header text + * @param message The Alerts contents text + */ private void showMessage(String title, String message) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Ung\u00fcltige Daten!"); @@ -317,6 +374,11 @@ public class StationsHistorieController { } + /** + * Checks the StationsHistorie and makes error alerts if necessary. + * @param stationsHistorie The StationsHistorie that should be validated, + * @return true if data is valid, false otherwise. + */ private boolean validateData(StationsHistorie stationsHistorie) { if (stationsHistorie.getStationKey() == null) { showMessage("Keine Station ausgew\00e4hlt!", "Bitte Station und nicht nur Abteilung ausw\00e4hlen!"); @@ -336,8 +398,10 @@ public class StationsHistorieController { return true; } + /** + * Clears TextFields in the view + */ private void clearFields() { - statHistCreateTime.setText(""); statHistCreator.setText(""); statHistEditTime.setText(""); @@ -351,7 +415,4 @@ public class StationsHistorieController { dtTmEntlassung.setDateTime(null); } - public enum State { - CREATE, EDIT, VIEW - } } diff --git a/src/main/resources/diagnose.fxml b/src/main/resources/diagnose.fxml index 3b714bd..a2f9626 100644 --- a/src/main/resources/diagnose.fxml +++ b/src/main/resources/diagnose.fxml @@ -42,7 +42,7 @@