diff options
| author | Viktoria Pundy <viktoria.pundy@aon.at> | 2018-05-22 21:10:04 +0200 | 
|---|---|---|
| committer | Viktoria Pundy <viktoria.pundy@aon.at> | 2018-05-22 21:10:04 +0200 | 
| commit | 3f45e04f289edf24de1b7254138a882cb9226156 (patch) | |
| tree | bdaf518c2900c4baa883f6195314bfeadc1594ee /src/main/java/at/ac/tuwien/sepm | |
| parent | 38301afa2221ff5cc07ea73e8eaa104eee3e787f (diff) | |
| download | sepm-groupproject-3f45e04f289edf24de1b7254138a882cb9226156.tar.gz sepm-groupproject-3f45e04f289edf24de1b7254138a882cb9226156.tar.xz sepm-groupproject-3f45e04f289edf24de1b7254138a882cb9226156.zip  | |
Fixed some errors, added listener for mouse input on active-operation list
Diffstat (limited to 'src/main/java/at/ac/tuwien/sepm')
4 files changed, 50 insertions, 15 deletions
diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java index 773ccb6..bb6fb27 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/DBOperationDAO.java @@ -201,7 +201,22 @@ public class DBOperationDAO implements OperationDAO {      @Override      public Operation get(long operationId) throws ElementNotFoundException, PersistenceException { -        return null; +        if (operationId <= 0) +            throw new ElementNotFoundException("Es wurde eine falsche ID übergeben!"); + +        String sql = "Select * from operation where id = ?"; + +        try (PreparedStatement pstmt = +                jdbcConnectionManager.getConnection().prepareStatement(sql)) { +            pstmt.setLong(1, operationId); +            pstmt.execute(); +            ResultSet rs = pstmt.getResultSet(); +            if (rs.next()) { +                return operationFromRS(rs); +            } else throw new ElementNotFoundException("No element could be found!"); +        } catch (SQLException e) { +            throw new PersistenceException(e); +        }      }      @Override diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java index 796dd7b..7e0f494 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/dao/VehicleDatabaseDao.java @@ -180,13 +180,14 @@ public class VehicleDatabaseDao implements VehicleDAO {          try {              Connection con = jdbcConnectionManager.getConnection(); -            try (PreparedStatement pstmt = con.prepareStatement(sql); -                    ResultSet rs = pstmt.executeQuery()) { +            try (PreparedStatement pstmt = con.prepareStatement(sql)) {                  pstmt.setLong(1, id); -                if (!rs.first()) throw new ElementNotFoundException("No such vehicle exists"); +                try (ResultSet rs = pstmt.executeQuery()) { +                    if (!rs.first()) throw new ElementNotFoundException("No such vehicle exists"); -                return vehicleFromRS(rs); +                    return vehicleFromRS(rs); +                }              }          } catch (SQLException e) {              throw new PersistenceException(e); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java index 44e28d8..2744fcd 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/CreateOperationController.java @@ -21,6 +21,7 @@ import java.util.EnumSet;  import java.util.LinkedList;  import java.util.List;  import java.util.Set; +import javafx.collections.FXCollections;  import javafx.event.ActionEvent;  import javafx.fxml.FXML;  import javafx.fxml.FXMLLoader; @@ -31,6 +32,7 @@ import javafx.scene.control.Alert.AlertType;  import javafx.scene.control.Button;  import javafx.scene.control.ContextMenu;  import javafx.scene.control.Label; +import javafx.scene.control.ListCell;  import javafx.scene.control.ListView;  import javafx.scene.control.MenuItem;  import javafx.scene.control.TextField; @@ -56,7 +58,6 @@ public class CreateOperationController {      public ListView<Vehicle> lvVehicles;      public ListView<Operation> lvActiveOperations;      public Label lblChosenVehicles; -    public LinkedList<Vehicle> chosenVehicles = new LinkedList<>();      public AnchorPane apInvisible;      @FXML private OperationDetailsController operationDetailsController;      public FlowPane fpVehicles; @@ -75,7 +76,29 @@ public class CreateOperationController {      @FXML      public void initialize() {          lblChosenVehicles.setText("keine ausgewählt"); +        lvActiveOperations.setCellFactory( +                param -> +                        new ListCell<>() { +                            @Override +                            protected void updateItem(Operation item, boolean empty) { +                                super.updateItem(item, empty); +                                if (empty || item == null || item.opCode() == null) { +                                    setText(null); +                                } else { +                                    setText(item.opCode()); +                                } +                            } +                        }); +        lvActiveOperations.setOnMouseClicked( +                event -> { +                    if (event.getClickCount() == 2) { +                        if (lvActiveOperations.getSelectionModel().getSelectedItem() == null) { +                            return; +                        } +                        openDetailsWindow(lvActiveOperations.getSelectionModel().getSelectedItem()); +                    } +                });      }      public void updateList() { @@ -147,7 +170,6 @@ public class CreateOperationController {          }      } -      private static ContextMenu createContextMenu(Vehicle data, VehicleService vehicleService) {          ContextMenu menu = new ContextMenu(); diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java index cacaa29..3809760 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/userInterface/OperationDetailsController.java @@ -8,7 +8,9 @@ import at.ac.tuwien.sepm.assignment.groupphase.einsatzverwaltung.service.Vehicle  import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidOperationException;  import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidVehicleException;  import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException; +import java.util.Collection;  import java.util.EnumSet; +import java.util.stream.Collectors;  import javafx.collections.FXCollections;  import javafx.fxml.FXML;  import javafx.scene.control.Alert; @@ -91,14 +93,9 @@ public class OperationDetailsController {          fillActiveList();          this.operation = operation;          lblCode.setText(operation.opCode()); -        StringBuilder result = new StringBuilder(); -        for (int i = 0; i < operation.vehicles().size(); i++) { -            if (i != operation.vehicles().size() - 1) { -                result.append(operation.vehicles().get(i).name()).append(","); -            } else { -                result.append(operation.vehicles().get(i).name()); -            } -        } +        Collection<String> vehicleNames = +                operation.vehicles().stream().map(Vehicle::name).collect(Collectors.toList()); +        String result = String.join(", ", vehicleNames);          lblChosenVehicles.setText(result.toString());          lblAdditionalInfo.setText(operation.additionalInfo());          lblAddress.setText(operation.destination());  | 
