Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package guifx;
- import java.time.LocalDate;
- import java.time.temporal.ChronoUnit;
- import java.util.ArrayList;
- import application.controller.Controller;
- import application.model.Addition;
- import application.model.Conferee;
- import application.model.Conference;
- import application.model.Enrollment;
- import application.model.Excursion;
- import application.model.Hotel;
- import javafx.beans.value.ChangeListener;
- import javafx.collections.ObservableList;
- import javafx.geometry.HPos;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.CheckBox;
- import javafx.scene.control.ComboBox;
- import javafx.scene.control.Label;
- import javafx.scene.control.ListView;
- import javafx.scene.control.SelectionMode;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.VBox;
- import javafx.scene.text.Font;
- import javafx.scene.text.Text;
- import javafx.stage.Modality;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- public class AddWindow extends Stage {
- private Conference conference;
- private Conferee conferee;
- private Text confTitle;
- private ComboBox<LocalDate> cbbArrival = new ComboBox<>(), cbbDeparture = new ComboBox<>();
- private CheckBox cbxSpeaker = new CheckBox(), cbxCompanion = new CheckBox(), cbxHotel = new CheckBox();
- private TextField txfCompanion = new TextField();
- private ListView<Excursion> lvwExcursions = new ListView<>();
- private ListView<Hotel> lvwHotels = new ListView<>();
- private ListView<Addition> lvwAdditions = new ListView<>();
- private TextField txfName = new TextField(), txfPhone = new TextField(), txfCountry = new TextField(),
- txfCompany = new TextField();
- public AddWindow(Conference conference, String title, Conferee conferee) {
- this.conference = conference;
- this.conferee = conferee;
- this.confTitle = new Text(conference.getName());
- this.initStyle(StageStyle.UTILITY);
- this.initModality(Modality.APPLICATION_MODAL);
- this.setResizable(false);
- this.setTitle(title);
- GridPane pane = new GridPane();
- this.initContent(pane);
- Scene scene = new Scene(pane);
- this.setScene(scene);
- updateControls();
- }
- public AddWindow(Conference conference, String title) {
- this(conference, title, null);
- }
- private void initContent(GridPane pane) {
- pane.setPadding(new Insets(20));
- pane.setHgap(10);
- pane.setVgap(10);
- //pane.setGridLinesVisible(true);
- //Personal info panel
- Label lblPersonInfo = new Label("Personal info");
- lblPersonInfo.setFont(Font.font(15));
- pane.add(lblPersonInfo, 0, 0, 2, 1);
- VBox pInfo = new VBox(15);
- pInfo.getChildren().addAll(new Label("Name:"), new Label("Phone:"), new Label("Country:"),
- new Label("Company:"));
- pane.add(pInfo, 0, 1);
- VBox txfBox = new VBox(5);
- txfBox.getChildren().addAll(txfName, txfPhone, txfCountry, txfCompany);
- pane.add(txfBox, 1, 1);
- //Conference info Panel
- Label lblConfInfo = new Label("Conference info");
- lblConfInfo.setFont(Font.font(15));
- pane.add(lblConfInfo, 2, 0, 2, 1);
- VBox confLblBox = new VBox(10);
- confLblBox.getChildren().addAll(new Label("Conference:"), new Label("Arrival:"), new Label("Departure:"),
- new Label("Speaker:"));
- pane.add(confLblBox, 2, 1);
- VBox edidableStuffBox = new VBox(5);
- edidableStuffBox.getChildren().addAll(confTitle, cbbArrival, cbbDeparture, cbxSpeaker);
- edidableStuffBox.setAlignment(Pos.TOP_RIGHT);
- pane.add(edidableStuffBox, 3, 1);
- ///Companion info panel
- Label lblCompanion = new Label("Companion info");
- lblCompanion.setStyle("-fx-font-size: 15");
- pane.add(lblCompanion, 0, 2, 2, 1);
- VBox companionLblBox = new VBox(10);
- companionLblBox.getChildren().addAll(new Label("Companion:"), new Label("Name:"),
- new Label("Choose excursions:\n(ctrl+click to\nselect more)"));
- pane.add(companionLblBox, 0, 3);
- VBox edidableCompanionStuff = new VBox(5);
- lvwExcursions.setPrefHeight(120);
- lvwExcursions.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
- edidableCompanionStuff.getChildren().addAll(cbxCompanion, txfCompanion, lvwExcursions);
- pane.add(edidableCompanionStuff, 1, 3);
- ChangeListener<Boolean> listener = (pv, ov, nv) -> this.companionChanged(nv);
- cbxCompanion.selectedProperty().addListener(listener);
- cbxCompanion.setSelected(true);
- ////Hotel info panel
- Label lblHotel = new Label("Hotel info");
- lblHotel.setStyle("-fx-font-size:15");
- pane.add(lblHotel, 2, 2, 2, 1);
- VBox hotelLblBox = new VBox(2);
- hotelLblBox.getChildren().addAll(new Label("Hotels"), lvwHotels);
- lvwHotels.setMaxSize(120, 150);
- pane.add(hotelLblBox, 2, 3);
- ChangeListener<Hotel> hotelListener = (pv, ov, nv) -> this.selectedHotelChanged();
- lvwHotels.getSelectionModel().selectedItemProperty().addListener(hotelListener);
- VBox addBox = new VBox(2);
- addBox.getChildren().addAll(new Label("Additions"), lvwAdditions);
- lvwAdditions.setMaxSize(120, 150);
- lvwAdditions.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
- pane.add(addBox, 3, 3);
- cbxHotel.setText("Book hotel");
- cbxHotel.setSelected(true);
- ChangeListener<Boolean> hotelListenerCbx = (pv, ov, nv) -> this.hotelChanged(nv);
- cbxHotel.selectedProperty().addListener(hotelListenerCbx);
- cbxHotel.setSelected(true);
- pane.add(cbxHotel, 3, 2);
- Button btnOk = new Button("Add registration");
- pane.add(btnOk, 2, 4);
- Button btnCancel = new Button("Cancel");
- GridPane.setHalignment(btnCancel, HPos.RIGHT);
- pane.add(btnCancel, 1, 4);
- btnOk.setOnAction(event -> this.okAction());
- btnCancel.setOnAction(event -> this.cancelAction());
- }
- private void hotelChanged(Boolean nv) {
- lvwHotels.setDisable(!nv);
- lvwAdditions.setDisable(!nv);
- }
- private void okAction() {
- if (conferee == null) {
- this.conferee = Controller.createConferee(txfName.getText(),
- txfPhone.getText(), txfCountry.getText(),
- Controller.createCompany(txfCompany.getText(), "123456"));
- }
- Hotel hotel = null;
- if (cbxHotel.isSelected()) {
- hotel = lvwHotels.getSelectionModel().getSelectedItem();
- }
- Enrollment enrollment = Controller.createEnrollment(conference,
- cbbArrival.getSelectionModel().getSelectedItem(), cbbDeparture.getSelectionModel().getSelectedItem(),
- hotel, cbxSpeaker.isSelected(), cbxCompanion.isSelected(), txfCompanion.getText(),
- getSelectedAdditions(),
- getSelectedExcursions());
- ConfirmEnrollmentWindow window = new ConfirmEnrollmentWindow(conferee, enrollment);
- window.showAndWait();
- if (window.getResult()) {
- Controller.enrollConferee(conferee, enrollment);
- this.close();
- } else {
- conferee = null;
- }
- }
- private void cancelAction() {
- this.close();
- }
- private void selectedHotelChanged() {
- Hotel selected = lvwHotels.getSelectionModel().getSelectedItem();
- lvwAdditions.getItems().setAll(selected.getAdditions());
- }
- private void companionChanged(Boolean nv) {
- txfCompanion.setDisable(!nv);
- lvwExcursions.setDisable(!nv);
- }
- private ArrayList<Addition> getSelectedAdditions() {
- ArrayList<Addition> list = new ArrayList<>();
- ObservableList<Addition> oList = lvwAdditions.getSelectionModel().getSelectedItems();
- for (Addition a : oList) {
- list.add(a);
- }
- if (list.isEmpty()) {
- return null;
- } else {
- return list;
- }
- }
- private ArrayList<Excursion> getSelectedExcursions() {
- ObservableList<Excursion> list = lvwExcursions.getSelectionModel().getSelectedItems();
- ArrayList<Excursion> reList = new ArrayList<>();
- for (Excursion e : list) {
- reList.add(e);
- }
- if (reList.isEmpty()) {
- return null;
- } else
- return reList;
- }
- private void updateControls() {
- ArrayList<LocalDate> arrivalDates = new ArrayList<>();
- int days = (int) conference.getStartDate().until(conference.getEndDate(), ChronoUnit.DAYS);
- for (int i = 0; i <= days; i++) {
- arrivalDates.add(conference.getStartDate().plusDays(i));
- }
- lvwHotels.getItems().setAll(conference.getHotels());
- lvwExcursions.getItems().setAll(conference.getExcursions());
- cbbArrival.getItems().setAll(arrivalDates);
- cbbArrival.getSelectionModel().select(0);
- cbbDeparture.getItems().setAll(arrivalDates);
- cbbDeparture.getSelectionModel().select(conference.getEndDate());
- if (conferee != null) {
- txfName.setText(conferee.getName());
- txfName.setDisable(true);
- txfPhone.setText(conferee.getPhone());
- txfPhone.setDisable(true);
- txfCountry.setText(conferee.getCountry());
- txfCountry.setDisable(true);
- if (conferee.getCompany() != null) {
- txfCompany.setText(conferee.getCompany().getName());
- }
- txfCompany.setDisable(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement