/** * Initializes the controller class. * * @param url * @param rb */ @Override public void initialize(URL url, ResourceBundle rb) { setupTable(); inflateTable(); atracaoTableView.setRowFactory( (TableView<Atracao> atracaoTablewView) -> { final TableRow<Atracao> row = new TableRow<>(); row.addEventFilter( MouseEvent.MOUSE_PRESSED, (MouseEvent event) -> { final int index = row.getIndex(); this.currentSelectedRow = index; if (index >= 0 && index < atracaoTablewView.getItems().size()) { atracaoTableView.getSelectionModel().select(index); textField1.setText(atracaoTableView.getItems().get(index).getIdAtracao()); textArea2.setText(atracaoTableView.getItems().get(index).getDescricao()); textField3.setText( atracaoTableView.getItems().get(index).getClassificacaoEtaria()); textField4.setText(atracaoTableView.getItems().get(index).getLocal()); textField5.setText(atracaoTableView.getItems().get(index).getEvento()); textField6.setText(atracaoTableView.getItems().get(index).getData()); event.consume(); } }); return row; }); }
/** * Erzeugt eine TableView mit den Daten aus der Datenbank. * * @return Eine TableView mit Polizist Daten */ private Node getPolizistAnsichtInnereTabelle() { refreshPolizistAnsicht(); // Name Spalte TableColumn<PolizistDaten, String> SpalteName = new TableColumn<>("Name"); SpalteName.setMinWidth(200); SpalteName.setCellValueFactory(new PropertyValueFactory<>("Name")); // GebDatum Spalte TableColumn<PolizistDaten, String> SpalteDatum = new TableColumn<>("Geburtsdatum"); SpalteDatum.setMinWidth(200); SpalteDatum.setCellValueFactory(new PropertyValueFactory<>("GebDatum")); // Nationalitaet Spalte TableColumn<PolizistDaten, String> SpalteNation = new TableColumn<>("Nationalität"); SpalteNation.setMinWidth(200); SpalteNation.setCellValueFactory(new PropertyValueFactory<>("Nation")); // Geschlecht Spalte TableColumn<PolizistDaten, String> SpalteGeschlecht = new TableColumn<>("Geschlecht"); SpalteGeschlecht.setMinWidth(200); SpalteGeschlecht.setCellValueFactory(new PropertyValueFactory<>("Geschlecht")); // Todesdatum Spalte TableColumn<PolizistDaten, String> SpalteTod = new TableColumn<>("Todesdatum"); SpalteTod.setMinWidth(200); SpalteTod.setCellValueFactory(new PropertyValueFactory<>("TodDatum")); // Dienstgrad Spalte TableColumn<PolizistDaten, String> SpalteGrad = new TableColumn<>("Dienstgrad"); SpalteGrad.setMinWidth(200); SpalteGrad.setCellValueFactory(new PropertyValueFactory<>("Dienstgrad")); Tabelle.setItems(PolizistDatenListe); Tabelle.getColumns().add(SpalteName); Tabelle.getColumns().add(SpalteDatum); Tabelle.getColumns().add(SpalteNation); Tabelle.getColumns().add(SpalteGeschlecht); Tabelle.getColumns().add(SpalteTod); Tabelle.getColumns().add(SpalteGrad); Tabelle.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); // Doppelklicke auf Spalten sollen Detailansichten oeffnen: Tabelle.setRowFactory( param -> { TableRow<PolizistDaten> Spalte = new TableRow<>(); Spalte.setOnMouseClicked( event -> { if (event.getClickCount() == 2 && (!Spalte.isEmpty())) { erzeugeDetailAnsicht(Spalte.getItem()); } }); return Spalte; }); return Tabelle; }
/** * Sets up the entire TableView with all its functionalities. * * @return The created TableView. */ private TableView<FilterInput> setUpTableView() { // Set up table view final TableView<FilterInput> tableView = new TableView<>(); tableView.setEditable(true); tableView.setMinWidth(522); tableView.setMinHeight(280); // Set up columns setUpFilterColumn(tableView); setUpTypeColumn(tableView); setUpOriginColumn(tableView); setUpColorColumn(tableView); setUpPriorityColumn(tableView); setUpLegalityColumn(tableView); setUpActiveColumn(tableView); // Insert data from database into table tableView.setItems(data); // Set select/deselect on mouse click tableView.setRowFactory( tableViewLambda -> { final TableRow<FilterInput> row = new TableRow<>(); row.addEventFilter( MouseEvent.MOUSE_PRESSED, event -> { final int index = row.getIndex(); if (index >= 0 && index < tableView.getItems().size() && tableView.getSelectionModel().isSelected(index)) { tableView.getSelectionModel().clearSelection(); event.consume(); } }); return row; }); return tableView; }
@FXML public void initialize() { System.out.println("<main_contr>: controller initiation"); // observableTeams = FXCollections.observableArrayList(BetterDataGenerator.generateTeams()); observableTeams = FXCollections.observableArrayList(); teamsTable.setPlaceholder(new Label("No matching data")); FilteredList<Team> filteredTeams = new FilteredList<>(observableTeams, p -> false); teamSearcherTextField .textProperty() .addListener( (observable, oldValue, newValue) -> { if (newValue != null && newValue.length() == 3 && oldValue.length() < newValue.length()) { System.out.println("<main_contr>: query to db for '" + newValue + "'"); observableTeams.clear(); observableTeams.addAll(dbHandle.loadTeams()); } filteredTeams.setPredicate( team -> { if (newValue == null || newValue.isEmpty() || newValue.length() < 3) { return false; } String lowerCaseFilter = newValue.toLowerCase(); if (lowerCaseFilter.equals("all")) { return true; } else if (team.getTeamName().toLowerCase().contains(lowerCaseFilter)) { return true; } else if (team.getSupervisor() != null && team.getSupervisor() .toString() .toLowerCase() .contains(lowerCaseFilter)) { return true; } return false; }); }); FilteredList<Team> orphanTeams = new FilteredList<>( observableTeams, team -> { if (team.getSupervisor() == null) { return true; } else { return false; } }); SortedList<Team> sortedFilteredTeams = new SortedList<>(filteredTeams); sortedFilteredTeams.comparatorProperty().bind(teamsTable.comparatorProperty()); teamsTable.setItems(sortedFilteredTeams); SortedList<Team> sortedOrphanTeams = new SortedList<>(orphanTeams); sortedOrphanTeams.comparatorProperty().bind(orphanTeamsTable.comparatorProperty()); orphanTeamsTable.setItems(sortedOrphanTeams); teamsTable.setRowFactory( p -> { TableRow<Team> row = new TableRow<>(); row.setOnMouseClicked( event -> { if (event.getClickCount() == 2 && !row.isEmpty()) { Team selectedTeam = row.getItem(); handleTeamDoubleClick(selectedTeam); } }); return row; }); }