commit
84d1f065bc
|
@ -10,6 +10,7 @@ import javafx.scene.Node;
|
|||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -22,11 +23,14 @@ public class SearchController {
|
|||
@FXML
|
||||
private Button searchButton;
|
||||
@FXML
|
||||
private Pagination pagination;
|
||||
@FXML
|
||||
private Label searchLabel;
|
||||
|
||||
@FXML
|
||||
private TableView tableView;
|
||||
@FXML
|
||||
private VBox dataContainer;
|
||||
|
||||
private ObservableList<Person> masterData = FXCollections.observableArrayList();
|
||||
private ObservableList<Person> results = FXCollections.observableList(masterData);
|
||||
|
||||
public SearchController() {
|
||||
masterData.add(new Person(5, "John", true));
|
||||
|
@ -40,7 +44,7 @@ public class SearchController {
|
|||
// search panel
|
||||
searchButton.setText("Search");
|
||||
searchButton.setOnAction(event -> loadData());
|
||||
searchButton.setStyle("-fx-background-color: #457ecd; -fx-text-fill: #ffffff;");
|
||||
searchButton.setStyle("-fx-background-color: slateblue; -fx-text-fill: white;");
|
||||
|
||||
searchField.setOnKeyPressed(event -> {
|
||||
if (event.getCode().equals(KeyCode.ENTER)) {
|
||||
|
@ -52,22 +56,23 @@ public class SearchController {
|
|||
searchLabel.setText(newValue);
|
||||
});
|
||||
|
||||
pagination.setPageFactory(SearchController.this::createPage);
|
||||
initTable();
|
||||
|
||||
}
|
||||
|
||||
private Node createPage(Integer pageIndex) {
|
||||
private void initTable() {
|
||||
tableView = new TableView<>(FXCollections.observableList(masterData));
|
||||
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
|
||||
|
||||
VBox dataContainer = new VBox();
|
||||
|
||||
TableView<Person> tableView = new TableView<>(masterData);
|
||||
TableColumn id = new TableColumn("ID");
|
||||
id.setCellValueFactory(new PropertyValueFactory("id"));
|
||||
TableColumn name = new TableColumn("NAME");
|
||||
name.setCellValueFactory(new PropertyValueFactory("name"));
|
||||
TableColumn employed = new TableColumn("EMPLOYED");
|
||||
|
||||
employed.setCellValueFactory(new PropertyValueFactory("isEmployed"));
|
||||
tableView.getColumns().addAll(id, name, employed);
|
||||
|
||||
dataContainer.getChildren().add(tableView);
|
||||
|
||||
return dataContainer;
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
|
@ -86,11 +91,10 @@ public class SearchController {
|
|||
};
|
||||
|
||||
task.setOnSucceeded(event -> {
|
||||
masterData = task.getValue();
|
||||
pagination.setVisible(true);
|
||||
pagination.setPageCount(masterData.size() / PAGE_ITEMS_COUNT);
|
||||
results = task.getValue();
|
||||
tableView.setItems(FXCollections.observableList(results));
|
||||
});
|
||||
|
||||
|
||||
Thread th = new Thread(task);
|
||||
th.setDaemon(true);
|
||||
th.start();
|
||||
|
|
|
@ -20,14 +20,13 @@
|
|||
<Label fx:id="searchLabel"/>
|
||||
</children>
|
||||
</HBox>
|
||||
|
||||
<Pagination fx:id="pagination"
|
||||
AnchorPane.leftAnchor="10.0"
|
||||
AnchorPane.rightAnchor="10.0"
|
||||
AnchorPane.topAnchor="50.0"
|
||||
visible="false">
|
||||
|
||||
</Pagination>
|
||||
|
||||
<VBox fx:id="dataContainer"
|
||||
AnchorPane.leftAnchor="10.0"
|
||||
AnchorPane.rightAnchor="10.0"
|
||||
AnchorPane.topAnchor="50.0">
|
||||
|
||||
</VBox>
|
||||
|
||||
</children>
|
||||
</AnchorPane>
|
Loading…
Reference in New Issue