@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; }); }
/** Starts the Gui applicaiton. */ public void start(Stage myStage) { System.out.println("Inside the start() method."); table = new TableView<PersonBean>(); table.setEditable(true); // Give the stage a title. myStage.setTitle("Person Spam App"); filteredData = new FilteredList<>(personData, p -> true); sortedData = new SortedList<>(filteredData); sortedData.comparatorProperty().bind(table.comparatorProperty()); table.setItems(sortedData); table.setPrefWidth(500); table.getStylesheets().add("resource/style.css"); table.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY); // My edition: TableColumn<PersonBean, String> wholeNameCol = new TableColumn<PersonBean, String>("Full name"); wholeNameCol.setCellValueFactory(new PropertyValueFactory("firstAndLastName")); wholeNameCol.setCellFactory(TextFieldTableCell.<PersonBean>forTableColumn()); wholeNameCol.setOnEditCommit( (CellEditEvent<PersonBean, String> t) -> { // Start on line below ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setFirstAndLastName(t.getNewValue()); }); // TableColumn<PersonBean, String> firstNameCol = new TableColumn<PersonBean, String>("First // Name"); // firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName")); // firstNameCol.setCellFactory(TextFieldTableCell.<PersonBean> forTableColumn()); // firstNameCol.setOnEditCommit((CellEditEvent<PersonBean, String> t) -> { // // ((PersonBean)t.getTableView().getItems().get(t.getTablePosition().getRow())).setFirstName(t.getNewValue()); // }); // // TableColumn<PersonBean, String> lastNameCol = new TableColumn<PersonBean, String>("Last // Name"); // lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName")); // lastNameCol.setCellFactory(TextFieldTableCell.<PersonBean> forTableColumn()); // lastNameCol.setOnEditCommit((CellEditEvent<PersonBean, String> t) -> { // ((PersonBean) // t.getTableView().getItems().get(t.getTablePosition().getRow())).setLastName(t.getNewValue()); // }); TableColumn<PersonBean, String> emailCol = new TableColumn<PersonBean, String>("Email"); emailCol.setCellValueFactory(new PropertyValueFactory("email")); emailCol.setCellFactory(TextFieldTableCell.<PersonBean>forTableColumn()); emailCol.setOnEditCommit( (CellEditEvent<PersonBean, String> t) -> { ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setEmail(t.getNewValue()); }); TableColumn<PersonBean, String> genderCol = new TableColumn<PersonBean, String>("Gender"); genderCol.setCellValueFactory(new PropertyValueFactory("gender")); genderCol.setCellFactory(TextFieldTableCell.<PersonBean>forTableColumn()); genderCol.setOnEditCommit( (CellEditEvent<PersonBean, String> t) -> { ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setGender(t.getNewValue()); }); TableColumn<PersonBean, Integer> ageCol = new TableColumn<PersonBean, Integer>("Age"); ageCol.setCellValueFactory(new PropertyValueFactory("age")); ageCol.setCellFactory( TextFieldTableCell.<PersonBean, Integer>forTableColumn(new IntegerStringConverter())); ageCol.setOnEditCommit( (CellEditEvent<PersonBean, Integer> t) -> { ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setAge(t.getNewValue()); }); table.getColumns().setAll(wholeNameCol, emailCol, genderCol, ageCol); ageCol.setId("white"); Button allButton = new Button("All"); allButton.setMinSize(100, 10); allButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Show all!"); filteredData.setPredicate(showAll()); } }); Button maleButton = new Button("Male"); maleButton.setMinSize(100, 10); maleButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Show male"); // printIt(); filteredData.setPredicate(isMale()); } }); Button femaleButton = new Button("Female"); femaleButton.setMinSize(100, 10); femaleButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Show female"); filteredData.setPredicate(isFemale()); } }); Button over18Button = new Button("Over 18"); over18Button.setMinSize(100, 10); over18Button.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Above 18"); // filteredData.setPredicate(over18()); filteredData.setPredicate( new Predicate<PersonBean>() { public boolean test(PersonBean p) { return p.getAge() > 17; } }); } }); Button addButton = new Button("Add row"); addButton.setMinSize(100, 10); addButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Add me!"); filteredData.setPredicate(showAll()); addRow(); } }); Button removeButton = new Button("Delete row"); removeButton.setMinSize(100, 10); removeButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("delete me!"); List items = new ArrayList(table.getSelectionModel().getSelectedItems()); personData.removeAll(items); table.getSelectionModel().clearSelection(); } }); // Create a root node. In this case, a flow layout // is used, but several alternatives exist. FlowPane rootNode = new FlowPane(); rootNode.getStylesheets().add("resource/style.css"); rootNode .getChildren() .addAll(table, allButton, maleButton, femaleButton, over18Button, addButton, removeButton); // Create a scene. Scene myScene = new Scene(rootNode, 800, 800); // Set the scene on the stage. myStage.setScene(myScene); // Show the stage and its scene. myStage.show(); }
@Override public void initialize(URL url, ResourceBundle rb) { TableColumnCodigo.setCellValueFactory(cellData -> cellData.getValue().CodigoProperty()); TableColumnNome.setCellValueFactory(cellData -> cellData.getValue().NomeProperty()); TableColumnServico.setCellValueFactory(cellData -> cellData.getValue().ServicoProperty()); // TableColumnVencimento.setCellValueFactory(cellData -> cellData.getValue().StatusProperty()); TableColumnValor.setCellValueFactory(cellData -> cellData.getValue().ValorProperty()); TableColumnSituacao.setCellValueFactory(cellData -> cellData.getValue().SituacaoProperty()); try { carregaTabela(); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (itens.size() > 0) TableViewBuscar.setItems(itens); itens.addListener( new ListChangeListener<BuscaCadastroContaReceberFiltro>() { @Override public void onChanged( javafx.collections.ListChangeListener.Change< ? extends BuscaCadastroContaReceberFiltro> arg0) { TextFieldTotal.setText(Integer.toString(TableViewBuscar.getItems().size())); } }); FilteredList<BuscaCadastroContaReceberFiltro> filteredData = new FilteredList<>(itens, p -> true); TextFieldFiltro.textProperty() .addListener( (observable, oldValue, newValue) -> { TextFieldTotal.setText(Integer.toString(TableViewBuscar.getItems().size())); filteredData.setPredicate( person -> { if (newValue == null || newValue.isEmpty()) { return true; } String lowerCaseFilter = newValue.toLowerCase(); if (person.getNome().toLowerCase().indexOf(lowerCaseFilter) != -1) { return true; } return false; }); }); SortedList<BuscaCadastroContaReceberFiltro> sortedData = new SortedList<>(filteredData); sortedData.comparatorProperty().bind(TableViewBuscar.comparatorProperty()); TableViewBuscar.setItems(sortedData); ButtonOk.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { if (TableViewBuscar.getSelectionModel().getSelectedItems().size() < 1) { Alerta alerta = new Alerta("Busca", "Conta não selecionada!"); alerta.Alertar(BuscaCadastroContaReceberView.myStage); return; } try { // if (opt == 0){ CadastroContasReceberController.setcontareceber( ControllerContaReceber.BuscaContaReceber( TableViewBuscar.getSelectionModel().getSelectedItems().get(0).getCodigo())); CadastroContasReceberController.tela.carregaInfo(); // }else if(opt == 1){ // CadastroMatriculaController.setaluno(ControllerAluno.BuscaAluno(TableViewBuscar.getSelectionModel().getSelectedItems().get(0).getCodigo())); // CadastroMatriculaController.tela.carregaInfoAluno(); // } } catch (ClassNotFoundException | SQLException e1) { e1.printStackTrace(); } BuscaCadastroContaReceberView.myStage.close(); } }); ButtonCancelar.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { BuscaCadastroContaReceberView.myStage.close(); } }); }