blob: df8ceaea505d71e7e2c928fa0cffd1a7b55a7795 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package space.m0e.quga.oop.lab56maven.dialogs;
import javafx.beans.Observable;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.stage.Modality;
import javafx.stage.Stage;
import space.m0e.quga.oop.lab56maven.Main;
import space.m0e.quga.oop.lab56maven.entities.common.Ability;
import space.m0e.quga.oop.lab56maven.entities.common.Utils;
import space.m0e.quga.oop.lab56maven.entities.micro.Immigrant;
import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
public class SearchDialog implements Initializable {
public static Stage window = null;
public static Scene scene;
public ComboBox searchCombo;
public Button submitButton;
public TextField searchQuery;
public static void display() throws IOException {
Parent root = FXMLLoader.load(Objects.requireNonNull(SearchDialog.class.getResource("search_dialog.fxml")));
window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Search");
scene = new Scene(root, 440, 350);
window.setScene(scene);
window.showAndWait();
}
@Override
public void initialize(URL location, ResourceBundle resources) {
searchCombo.getItems().addAll("Name", "Age");
searchCombo.setValue("Name");
}
public void sendError(String title, String description) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText(title);
alert.setContentText(description);
alert.showAndWait();
}
public void submitButtonHandler(MouseEvent mouseEvent) throws IOException {
Utils.findImmigrants("Search result", immigrant -> {
switch (searchCombo.getValue().toString()) {
case "Name" -> {
return immigrant.getFullName().contains(searchQuery.getText());
}
case "Age" -> {
return immigrant.getAge() == Integer.parseInt(searchQuery.getText());
}
}
return false;
});
window.close();
}
}
|