|
1 | 1 | package com.ghulam.bookissuereturn;
|
2 | 2 |
|
3 |
| -import com.ghulam.database.dao.BookDAO; |
| 3 | +import java.net.URL; |
| 4 | +import java.util.ResourceBundle; |
| 5 | + |
4 | 6 | import com.ghulam.database.table.Book;
|
5 |
| -import com.ghulam.database.table.Student; |
6 | 7 | import com.jfoenix.controls.JFXButton;
|
7 | 8 | import com.jfoenix.controls.JFXCheckBox;
|
8 | 9 | import com.jfoenix.controls.JFXTextField;
|
9 |
| -import javafx.collections.FXCollections; |
| 10 | + |
10 | 11 | import javafx.collections.ObservableList;
|
11 | 12 | import javafx.collections.transformation.FilteredList;
|
12 | 13 | import javafx.collections.transformation.SortedList;
|
|
19 | 20 | import javafx.scene.layout.BorderPane;
|
20 | 21 | import javafx.stage.Stage;
|
21 | 22 |
|
22 |
| -import javax.swing.border.Border; |
23 |
| -import java.net.URL; |
24 |
| -import java.util.ResourceBundle; |
25 |
| -import java.util.function.Predicate; |
| 23 | +public class BookList implements Initializable { |
| 24 | + @FXML |
| 25 | + private BorderPane rootPane; |
| 26 | + @FXML |
| 27 | + private JFXTextField txtSearch; |
| 28 | + @FXML |
| 29 | + private JFXButton btnSubmit; |
| 30 | + @FXML |
| 31 | + private TableView<Book> table; |
| 32 | + @FXML |
| 33 | + private TableColumn<Book, Integer> colBookID; |
| 34 | + @FXML |
| 35 | + private TableColumn<Book, String> colNameBook; |
| 36 | + @FXML |
| 37 | + private TableColumn<Book, String> colAuthorName; |
| 38 | + @FXML |
| 39 | + private TableColumn<Book, String> colDescription; |
| 40 | + @FXML |
| 41 | + private TableColumn<Book, Integer> colStock; |
| 42 | + @FXML |
| 43 | + private TableColumn<Book, JFXCheckBox> colAction; |
| 44 | + private ObservableList<Book> list; |
| 45 | + |
| 46 | + @Override |
| 47 | + public void initialize(URL location, ResourceBundle resources) { |
| 48 | + list = BookIssueReturnController.getBookObservableList(); |
| 49 | + colBookID.setCellValueFactory(new PropertyValueFactory<>("id")); |
| 50 | + colNameBook.setCellValueFactory(new PropertyValueFactory<>("name")); |
| 51 | + colAuthorName.setCellValueFactory(new PropertyValueFactory<>("authorName")); |
| 52 | + colDescription.setCellValueFactory(new PropertyValueFactory<>("description")); |
| 53 | + colStock.setCellValueFactory(new PropertyValueFactory<>("stock")); |
| 54 | + colAction.setCellValueFactory(new PropertyValueFactory<>("action")); |
| 55 | + table.setItems(list); |
| 56 | + FilteredList<Book> filteredList = new FilteredList<>(list, e -> true); |
| 57 | + txtSearch.textProperty().addListener((observable, oldValue, newValue) -> { |
| 58 | + filteredList.setPredicate(book -> { |
| 59 | + if (newValue == null || newValue.isEmpty()) |
| 60 | + return true; |
| 61 | + String data = newValue.toLowerCase(); |
| 62 | + if (String.valueOf(book.getId()).toLowerCase().contains(data) |
| 63 | + || book.getName().toLowerCase().contains(data) |
| 64 | + || book.getAuthorName().toLowerCase().contains(data)) |
| 65 | + return true; |
| 66 | + return false; |
| 67 | + }); |
| 68 | + }); |
| 69 | + SortedList<Book> sortedData = new SortedList<>(filteredList); |
| 70 | + sortedData.comparatorProperty().bind(table.comparatorProperty()); |
| 71 | + table.setItems(sortedData); |
26 | 72 |
|
27 |
| -public class BookList implements Initializable{ |
28 |
| - @FXML |
29 |
| - private BorderPane rootPane; |
30 |
| - @FXML |
31 |
| - private JFXTextField txtSearch; |
32 |
| - @FXML |
33 |
| - private JFXButton btnSubmit; |
34 |
| - @FXML |
35 |
| - private TableView<Book> table; |
36 |
| - @FXML |
37 |
| - private TableColumn<Book, Integer> colBookID; |
38 |
| - @FXML |
39 |
| - private TableColumn<Book, String> colNameBook; |
40 |
| - @FXML |
41 |
| - private TableColumn<Book, String> colAuthorName; |
42 |
| - @FXML |
43 |
| - private TableColumn<Book, String> colDescription; |
44 |
| - @FXML |
45 |
| - private TableColumn<Book, Integer> colStock; |
46 |
| - @FXML |
47 |
| - private TableColumn<Book, JFXCheckBox> colAction; |
48 |
| - private ObservableList<Book> list; |
49 |
| - @Override |
50 |
| - public void initialize(URL location, ResourceBundle resources) { |
51 |
| - list=BookIssueReturnController.getBookObservableList(); |
52 |
| - colBookID.setCellValueFactory(new PropertyValueFactory<>("id")); |
53 |
| - colNameBook.setCellValueFactory(new PropertyValueFactory<>("name")); |
54 |
| - colAuthorName.setCellValueFactory(new PropertyValueFactory<>("authorName")); |
55 |
| - colDescription.setCellValueFactory(new PropertyValueFactory<>("description")); |
56 |
| - colStock.setCellValueFactory(new PropertyValueFactory<>("stock")); |
57 |
| - colAction.setCellValueFactory(new PropertyValueFactory<>("action")); |
58 |
| - table.setItems(list); |
59 |
| - FilteredList<Book> filteredList=new FilteredList<>(list,e->true); |
60 |
| - txtSearch.textProperty().addListener((observable,oldValue,newValue)->{ |
61 |
| - filteredList.setPredicate(book -> { |
62 |
| - if(newValue==null || newValue.isEmpty()) |
63 |
| - return true; |
64 |
| - String data=newValue.toLowerCase(); |
65 |
| - if(String.valueOf(book.getId()).toLowerCase().contains(data) || book.getName().toLowerCase().contains(data) || book.getAuthorName().toLowerCase().contains(data)) |
66 |
| - return true; |
67 |
| - return false; |
68 |
| - }); |
69 |
| - }); |
70 |
| - SortedList<Book> sortedData = new SortedList<>(filteredList); |
71 |
| - sortedData.comparatorProperty().bind(table.comparatorProperty()); |
72 |
| - table.setItems(sortedData); |
| 73 | + } |
73 | 74 |
|
74 |
| - } |
75 |
| - @FXML |
76 |
| - void btnSubmitOnAction(ActionEvent event){ |
77 |
| - Stage stage = (Stage) rootPane.getScene().getWindow(); |
78 |
| - stage.close(); |
79 |
| - } |
| 75 | + @FXML |
| 76 | + void btnSubmitOnAction(ActionEvent event) { |
| 77 | + Stage stage = (Stage) rootPane.getScene().getWindow(); |
| 78 | + stage.close(); |
| 79 | + } |
80 | 80 | }
|
0 commit comments