|
- package de.uniluebeck.mi.projmi6.controller;
-
- import de.uniluebeck.mi.projmi6.db.DBHandler;
- import de.uniluebeck.mi.projmi6.model.HL7LogEntry;
- import javafx.collections.FXCollections;
- import javafx.concurrent.Task;
- import javafx.fxml.FXML;
- import javafx.scene.control.*;
- import javafx.scene.control.cell.PropertyValueFactory;
- import javafx.scene.text.Text;
-
- import java.time.LocalDateTime;
- import java.util.List;
-
-
- /**
- * Created by 631806 on 19.11.15.
- */
- public class LogController {
- final MainController mainController;
-
- @FXML
- TableView<HL7LogEntry> tblLog;
-
- @FXML
- TableColumn<HL7LogEntry, String> colLogIp, colLogMessage;
-
- @FXML
- TableColumn<HL7LogEntry, LocalDateTime> colLogTime;
-
- @FXML
- TableColumn<HL7LogEntry, HL7LogEntry.Direction> colLogDirection;
-
-
- @FXML
- Button btnRefresh;
- private Task<List<HL7LogEntry>> loadLogEntryTask = null;
-
- public LogController(MainController mainController) {
- this.mainController = mainController;
- }
-
- @FXML
- private void initialize() {
- initColumns();
- refreshLogFromDb();
- }
-
- private void initColumns() {
- colLogDirection.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, HL7LogEntry.Direction>("direction"));
- colLogIp.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, String>("source"));
- colLogTime.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, LocalDateTime>("timestamp"));
- colLogMessage.setCellValueFactory(new PropertyValueFactory<HL7LogEntry, String>("message"));
-
- colLogMessage.setCellFactory(column -> {
- return new TableCell<HL7LogEntry, String>() {
- private TextArea textArea = new TextArea();
-
- {
- textArea.setEditable(false);
- textArea.setPrefRowCount(5);
- }
-
- @Override
- protected void updateItem(String item, boolean empty) {
- super.updateItem(item, empty);
- this.setText(null);
- if (item == null || empty) {
- this.setGraphic(null);
- return;
- }
- textArea.setText(item);
- textArea.setWrapText(true);
- this.setGraphic(textArea);
- }
- };
- });
- }
-
- public void refreshLogFromDb() {
- if (this.loadLogEntryTask != null && this.loadLogEntryTask.isRunning()) {
- return;
- }
-
- btnRefresh.setDisable(true);
-
- tblLog.setItems(null);
- mainController.increaseParallelTaskCount();
-
- tblLog.setPlaceholder(new Text("Liste wird geladen..."));
-
- loadLogEntryTask = new Task<List<HL7LogEntry>>() {
-
- @Override
- protected List<HL7LogEntry> call() throws Exception {
- return FXCollections.observableArrayList(DBHandler.getLastHL7LogEntries());
- }
-
- @Override
- protected void succeeded() {
- super.succeeded();
- tblLog.setPlaceholder(new Text("Liste ist leer."));
- tblLog.setItems(FXCollections.observableArrayList(this.getValue()));
- mainController.decreaseParallelTaskCount();
- btnRefresh.setDisable(false);
-
- }
-
- @Override
- protected void failed() {
- super.failed();
- tblLog.setPlaceholder(new Text("Laden fehlgeschlagen"));
- mainController.decreaseParallelTaskCount();
- tblLog.setItems(null);
- getException().printStackTrace();
- }
- };
-
- Thread thread = new Thread(loadLogEntryTask);
- thread.setDaemon(true);
- thread.start();
- }
-
-
- @FXML
- private void clickedRefresh() {
- refreshLogFromDb();
- }
-
-
- }
|