Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.scene.Group;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.*;
- import javafx.scene.control.cell.PropertyValueFactory;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Modality;
- import javafx.stage.Stage;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Optional;
- public class PatientsTableView {
- private PatientsModel model = new PatientsModel();
- private PatientsController controller = new PatientsController();
- private BorderPane borderPane = new BorderPane();
- public PatientsTableView(PatientsController controller,PatientsModel model){
- this.controller = controller;
- this.model = model;
- controller.ReadBySAX();
- createAndLayoutControls();
- }
- public Parent asParent() {
- return borderPane ;
- }
- private void createAndLayoutControls(){
- GridPane tableView = new GridPane();
- configurateTableView(tableView,controller.getModelArray(),1,controller.getModelArray().size());
- GridPane navigationView = new GridPane();
- configurateNavigationVIew(navigationView,tableView,controller.getModelArray());
- GridPane functionalView = new GridPane();
- configurateFunctionalView(functionalView,tableView,navigationView);
- borderPane.setTop(tableView);
- borderPane.setCenter(navigationView);
- borderPane.setLeft(functionalView);
- }
- private TableView<PatientsModel> createTable(int x, int page, List<PatientsModel> newArray){
- GridPane view = new GridPane();
- ObservableList<PatientsModel> patient = FXCollections.observableArrayList();
- for(int i = (page-1)*x;i<page*x;i++)
- {
- if(i == newArray.size()){
- break;
- }
- patient.add(newArray.get(i));
- }
- TableView<PatientsModel> table = new TableView<PatientsModel>(patient);
- table.setPrefWidth(1280);
- //table.setPrefHeight(500);
- TableColumn<PatientsModel, String> patientFIOcolumn = new TableColumn<PatientsModel, String>("ФИО пациентов");
- patientFIOcolumn.setCellValueFactory(new PropertyValueFactory<PatientsModel, String>("patientSurname"));
- table.getColumns().add(patientFIOcolumn);
- TableColumn<PatientsModel, String> addressColumn = new TableColumn<PatientsModel, String>("адрес");
- addressColumn.setCellValueFactory(new PropertyValueFactory<PatientsModel, String>("town"));
- table.getColumns().add(addressColumn);
- //FlowPane root = new FlowPane(10, 10, table);
- return table;
- }
- private void configurateTableView(GridPane tableView,List<PatientsModel> newArray,int page,int numOfRecordsOnPage) {
- tableView.getChildren().clear();
- tableView.add(createTable(numOfRecordsOnPage,page,newArray),0,0);
- }
- private void configurateNavigationVIew(GridPane navigativonView, GridPane tableView,List<PatientsModel> newArray){
- navigativonView.getChildren().clear();
- Button setNumberOfRecords = new Button("Уcтановить количество записей");
- Button setPage = new Button ("Выбрать страницу");
- Label numOfRecordsOnPageLabel = new Label(Integer.toString(newArray.size()));
- Label totalNumOfRecords = new Label (Integer.toString(newArray.size()));
- Label currentPageLabel = new Label("1");
- Label totalPageLabel = new Label("1");
- updateTotalPageLabel(totalPageLabel,Integer.parseInt(numOfRecordsOnPageLabel.getText()),
- Integer.parseInt(totalNumOfRecords.getText()));
- setNumberOfRecords.setOnAction(click ->{
- TextInputDialog dialog = new TextInputDialog();
- dialog.setTitle("Input num of records on page");
- dialog.setHeaderText(null);
- dialog.setContentText("Please enter num of records:");
- Optional<String> result = dialog.showAndWait();
- if (result.isPresent()){
- int tmp = Integer.parseInt(result.get());
- if( tmp <= newArray.size()) {
- numOfRecordsOnPageLabel.setText(result.get());
- configurateTableView(tableView,newArray,1,Integer.parseInt(numOfRecordsOnPageLabel.getText()));
- updateTotalPageLabel(totalPageLabel,Integer.parseInt(numOfRecordsOnPageLabel.getText()),
- Integer.parseInt(totalNumOfRecords.getText()));
- }
- else{
- Alert alert = new Alert(Alert.AlertType.INFORMATION);
- alert.setTitle("Information");
- alert.setHeaderText(null);
- alert.setContentText("нету такого количества записей");
- alert.showAndWait();
- }
- }
- });
- setPage.setOnAction(click ->{
- List<String> choices = new ArrayList<>();
- for(int i = 1; i<=Integer.parseInt(totalPageLabel.getText());i++)
- {
- choices.add(Integer.toString(i));
- }
- ChoiceDialog<String> dialog = new ChoiceDialog<>("1", choices);
- dialog.setTitle("Choice Dialog");
- dialog.setHeaderText("Look, a Choice Dialog");
- dialog.setContentText("Choose your letter:");
- Optional<String> result = dialog.showAndWait();
- if (result.isPresent()){
- currentPageLabel.setText(result.get());
- configurateTableView(tableView,newArray,Integer.parseInt(currentPageLabel.getText()),
- Integer.parseInt(numOfRecordsOnPageLabel.getText()));
- }
- });
- navigativonView.add(setNumberOfRecords,0,0);
- navigativonView.add(new Label(" записей на странице: "),1,0);
- navigativonView.add(numOfRecordsOnPageLabel,2,0);
- navigativonView.add(new Label(" Всего записей: "),3,0);
- navigativonView.add(totalNumOfRecords,4,0);
- navigativonView.add(setPage,0,1);
- navigativonView.add(new Label("текущая страница:"),1,1);
- navigativonView.add(currentPageLabel,2,1);
- navigativonView.add(new Label(" Всего страниц:"),3,1);
- navigativonView.add(totalPageLabel,4,1);
- }
- private void updateTotalPageLabel(Label totalPageLabel,int numOfRecordsOnPage,int totalNumOfRecords){
- double allPage = (double)totalNumOfRecords/(double)(numOfRecordsOnPage);
- int tmp = (int)allPage;
- System.out.println("PAGES double = " + allPage);
- if(numOfRecordsOnPage == 0){
- totalPageLabel.setText("1");
- }
- else {
- if (tmp < allPage) {
- tmp++;
- System.out.println("PAGES = " + tmp);
- }
- totalPageLabel.setText(Integer.toString(tmp));
- }
- }
- private void configurateFunctionalView(GridPane functionalView,GridPane tableView,GridPane navigationView) {
- Button addNewRecord = new Button("Добавить запись");
- Button search = new Button ("поиск");
- Button delete = new Button ("Удаление");
- functionalView.add(addNewRecord,0,0);
- functionalView.add(search,0,1);
- functionalView.add(delete,0,2);
- search.setOnAction(click ->
- {
- newSearchStage();
- });
- addNewRecord.setOnAction(click ->
- {
- try {
- newRecordStage(tableView,navigationView);
- } catch (Exception e) {
- e.printStackTrace();
- }
- });
- delete.setOnAction(click ->
- {
- newDeleteStage(tableView,navigationView);
- });
- }
- public void newSearchStage(){
- final Stage dialogStage = new Stage();
- dialogStage.initModality(Modality.APPLICATION_MODAL);
- BorderPane borderPane = new BorderPane();
- List<PatientsModel> arrayOfFound = new ArrayList<PatientsModel>();
- GridPane tableView = new GridPane();
- configurateTableView(tableView,arrayOfFound,1,arrayOfFound.size());
- GridPane navigationView = new GridPane();
- configurateNavigationVIew(navigationView,tableView,arrayOfFound);
- GridPane functionalView = new GridPane();
- configurateSearchStageFunctionalView(functionalView,tableView,navigationView,arrayOfFound);
- borderPane.setTop(tableView);
- borderPane.setCenter(navigationView);
- borderPane.setLeft(functionalView);
- Scene dialogScene = new Scene(borderPane, 1280, 800);
- dialogStage.setScene(dialogScene);
- dialogStage.show();
- }
- private void configurateSearchStageFunctionalView(GridPane functionalView,GridPane tableView,GridPane navigationView,
- List<PatientsModel> arrayOfFound){
- Button chooseSearchPatientFio = new Button("ФИО пациента");
- Button chooseSearchAddress = new Button("адрес");
- //Label patientFioLabel = new Label();
- chooseSearchPatientFio.setOnAction(click ->
- {
- TextInputDialog dialog = new TextInputDialog();
- dialog.setTitle("Text Input Dialog");
- dialog.setHeaderText(null);
- dialog.setContentText("Please enter patient FIO:");
- Optional<String> result = dialog.showAndWait();
- if (result.isPresent()) {
- //patientFioLabel.setText(result.get());
- arrayOfFound.clear();
- for (int i = 0; i < controller.getModelArray().size(); i++) {
- if(result.get().equals(controller.getModelArray().get(i).getPatientSurname())){
- System.out.println("Yep");
- arrayOfFound.add(controller.getModelArray().get(i));
- }
- }
- configurateTableView(tableView,arrayOfFound,1, arrayOfFound.size());
- configurateNavigationVIew(navigationView,tableView,arrayOfFound);
- }
- });
- chooseSearchAddress.setOnAction(click ->
- {
- TextInputDialog dialog = new TextInputDialog();
- dialog.setTitle("Text Input Dialog");
- dialog.setHeaderText(null);
- dialog.setContentText("Please enter patient address :");
- Optional<String> result = dialog.showAndWait();
- if (result.isPresent()) {
- arrayOfFound.clear();
- //addressLabel.setText(result.get());
- for (int i = 0; i < controller.getModelArray().size(); i++) {
- String tmpSTR = controller.getModelArray().get(i).getTown();
- if (tmpSTR.equals(result.get())) {
- System.out.println("Yep");
- arrayOfFound.add(controller.getModelArray().get(i));
- }
- }
- configurateTableView(tableView,arrayOfFound,1, arrayOfFound.size());
- configurateNavigationVIew(navigationView,tableView,arrayOfFound);
- /////
- }
- });
- functionalView.add(new Label("Поиск по:"),0,0);
- functionalView.add(chooseSearchPatientFio,1,0);
- functionalView.add(chooseSearchAddress,1,1);
- }
- private void newRecordStage(GridPane tableView, GridPane navigationView){
- final Stage dialogStage = new Stage();
- dialogStage.initModality(Modality.APPLICATION_MODAL);
- BorderPane borderPane = new BorderPane();
- GridPane addElementView = new GridPane();
- Button addRecordButton = new Button("добавить запись");
- TextField patientSurnameTF = new TextField("");
- TextField townTF = new TextField("");
- addRecordButton.setOnAction(click ->
- {
- boolean checkPatientFIO =patientSurnameTF.getText().trim().isEmpty();
- boolean checkAddress = townTF.getText().trim().isEmpty();
- if(!checkPatientFIO && !checkAddress){
- controller.writeByDOM(patientSurnameTF.getText(),townTF.getText());
- controller.ReadBySAX();
- configurateTableView(tableView,controller.getModelArray(),1, controller.getModelArray().size());
- configurateNavigationVIew(navigationView,tableView,controller.getModelArray());
- dialogStage.close();
- }
- else{
- Alert alert = new Alert(Alert.AlertType.INFORMATION);
- alert.setTitle("Information");
- alert.setHeaderText(null);
- alert.setContentText("Заполните информацию корректно");
- alert.showAndWait();
- }
- });
- addElementView.add(new Label("Фамилия Пациента"),0,0);
- addElementView.add(patientSurnameTF,1,0);
- addElementView.add(new Label("город"),0,1);
- addElementView.add(townTF,1,1);
- addElementView.add(addRecordButton,2,0);
- borderPane.setLeft(addElementView);
- Scene dialogScene = new Scene(borderPane, 500, 500);
- dialogStage.setScene(dialogScene);
- dialogStage.show();
- }
- private void newDeleteStage(GridPane tableView,GridPane navigationView){
- final Stage dialogStage = new Stage();
- dialogStage.initModality(Modality.APPLICATION_MODAL);
- GridPane view = new GridPane();
- Button chooseDeletePatientFio = new Button("ФИО пациента");
- Button chooseDeleteAddress = new Button("адрес");
- Label patientFioLabel = new Label();
- Label addressLabel = new Label();
- Label counterDeleted = new Label("0");
- view.add(chooseDeletePatientFio, 0, 0);
- view.add(patientFioLabel, 1, 0);
- view.add(chooseDeleteAddress, 0, 1);
- view.add(addressLabel, 1, 1);
- view.add(new Label ("Удалено: "),0,2);
- view.add(counterDeleted,1,2);
- chooseDeletePatientFio.setOnAction(click ->
- {
- TextInputDialog dialog = new TextInputDialog();
- dialog.setTitle("Text Input Dialog");
- dialog.setHeaderText(null);
- dialog.setContentText("Please enter patient FIO:");
- Optional<String> result = dialog.showAndWait();
- if (result.isPresent()) {
- patientFioLabel.setText(result.get());;
- int tmp = 0;
- counterDeleted.setText("0");
- for (int i = 0; i < controller.getModelArray().size(); i++) {
- if (result.get().equals(controller.getModelArray().get(i).getPatientSurname())){
- System.out.println("DEATH");
- controller.delTag(i);
- i--;
- controller.ReadBySAX();
- tmp++;
- counterDeleted.setText(Integer.toString(tmp));
- configurateTableView(tableView,controller.getModelArray(),1, controller.getModelArray().size());
- configurateNavigationVIew(navigationView,tableView,controller.getModelArray());
- }
- }
- }
- });
- chooseDeleteAddress.setOnAction(click ->
- {
- TextInputDialog dialog = new TextInputDialog();
- dialog.setTitle("Text Input Dialog");
- dialog.setHeaderText(null);
- dialog.setContentText("Please enter patient address :");
- Optional<String> result = dialog.showAndWait();
- if (result.isPresent()) {
- counterDeleted.setText("0");
- addressLabel.setText(result.get());
- int tmp = 0;
- for (int i = 0; i < controller.getModelArray().size(); i++) {
- String tmpSTR = controller.getModelArray().get(i).getTown();
- if (tmpSTR.equals(result.get())) {
- System.out.println("DEATH");
- controller.delTag(i);
- i--;
- controller.ReadBySAX();
- tmp++;
- counterDeleted.setText(Integer.toString(tmp));
- configurateTableView(tableView,controller.getModelArray(),1, controller.getModelArray().size());
- configurateNavigationVIew(navigationView,tableView,controller.getModelArray());
- }
- }
- }
- });
- Scene dialogScene = new Scene(view, 500, 900);
- dialogStage.setScene(dialogScene);
- dialogStage.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement