fix results display

This commit is contained in:
Loredana 2020-10-24 17:15:44 +03:00
parent 16161d5c9d
commit 4c983291ac
2 changed files with 24 additions and 23 deletions

View File

@ -10,6 +10,7 @@ import javafx.scene.Node;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.control.cell.PropertyValueFactory;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -22,11 +23,14 @@ public class SearchController {
@FXML @FXML
private Button searchButton; private Button searchButton;
@FXML @FXML
private Pagination pagination;
@FXML
private Label searchLabel; private Label searchLabel;
@FXML
private TableView tableView;
@FXML
private VBox dataContainer;
private ObservableList<Person> masterData = FXCollections.observableArrayList(); private ObservableList<Person> masterData = FXCollections.observableArrayList();
private ObservableList<Person> results = FXCollections.observableList(masterData);
public SearchController() { public SearchController() {
masterData.add(new Person(5, "John", true)); masterData.add(new Person(5, "John", true));
@ -52,22 +56,21 @@ public class SearchController {
searchLabel.setText(newValue); searchLabel.setText(newValue);
}); });
pagination.setPageFactory(SearchController.this::createPage); initTable();
} }
private Node createPage(Integer pageIndex) { private void initTable() {
tableView = new TableView<>(FXCollections.observableList(masterData));
VBox dataContainer = new VBox();
TableView<Person> tableView = new TableView<>(masterData);
TableColumn id = new TableColumn("ID"); TableColumn id = new TableColumn("ID");
id.setCellValueFactory(new PropertyValueFactory("id"));
TableColumn name = new TableColumn("NAME"); TableColumn name = new TableColumn("NAME");
name.setCellValueFactory(new PropertyValueFactory("name"));
TableColumn employed = new TableColumn("EMPLOYED"); TableColumn employed = new TableColumn("EMPLOYED");
employed.setCellValueFactory(new PropertyValueFactory("isEmployed"));
tableView.getColumns().addAll(id, name, employed); tableView.getColumns().addAll(id, name, employed);
dataContainer.getChildren().add(tableView); dataContainer.getChildren().add(tableView);
return dataContainer;
} }
private void loadData() { private void loadData() {
@ -86,9 +89,8 @@ public class SearchController {
}; };
task.setOnSucceeded(event -> { task.setOnSucceeded(event -> {
masterData = task.getValue(); results = task.getValue();
pagination.setVisible(true); tableView.setItems(FXCollections.observableList(results));
pagination.setPageCount(masterData.size() / PAGE_ITEMS_COUNT);
}); });
Thread th = new Thread(task); Thread th = new Thread(task);

View File

@ -21,13 +21,12 @@
</children> </children>
</HBox> </HBox>
<Pagination fx:id="pagination" <VBox fx:id="dataContainer"
AnchorPane.leftAnchor="10.0" AnchorPane.leftAnchor="10.0"
AnchorPane.rightAnchor="10.0" AnchorPane.rightAnchor="10.0"
AnchorPane.topAnchor="50.0" AnchorPane.topAnchor="50.0">
visible="false">
</Pagination> </VBox>
</children> </children>
</AnchorPane> </AnchorPane>