Merge pull request #10199 from eugenp/issue-10196

fix results display
This commit is contained in:
Loredana Crusoveanu 2020-10-26 16:36:33 +02:00 committed by GitHub
commit 84d1f065bc
2 changed files with 27 additions and 24 deletions

View File

@ -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();

View File

@ -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>