package database;/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package javafxapplication2;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;

/**
 * FXML Controller class
 *
 * @author jroll
 */
public class RoomsList_Controller implements Initializable {

    Stage stage;

    @FXML
    private Button backButton;
    @FXML
    private Button addButton;
    @FXML
    private Button removeButton;
    @FXML
    private Button editButton;
    @FXML
    private TableView tableView;
    @FXML
    TableColumn columnBuildingNumber;
    @FXML
    TableColumn columnRoomNumber;
    @FXML
    TableColumn columnComputers;
    @FXML
    TableColumn columnCapacity;
    @FXML
    TableColumn columnSmartRoom;
    @FXML
    TableColumn columnOther;

    public class Record {

        private SimpleStringProperty fieldBuildingNumber;
        private SimpleStringProperty fieldRoomNumber;
        private SimpleStringProperty fieldCapacity;
        private SimpleStringProperty fieldComputers;
        private SimpleStringProperty fieldSmartRoom;
        private SimpleStringProperty fieldOther;

        Record(String fieldBuildingNumber, String fieldRoomNumber, String fieldCapacity, String fieldComputers, String fieldSmartRoom, String fieldOther) {
            this.fieldBuildingNumber = new SimpleStringProperty(fieldBuildingNumber);
            this.fieldRoomNumber = new SimpleStringProperty(fieldRoomNumber);
            this.fieldCapacity = new SimpleStringProperty(fieldCapacity);
            this.fieldComputers = new SimpleStringProperty(fieldComputers);
            this.fieldSmartRoom = new SimpleStringProperty(fieldSmartRoom);
            this.fieldOther = new SimpleStringProperty(fieldOther);
        }

        /**
         * @return the fieldBuildingNumber
         */
        public String getFieldBuildingNumber() {
            return fieldBuildingNumber.get();
        }

        /**
         * @return the fieldRoomNumber
         */
        public String getFieldRoomNumber() {
            return fieldRoomNumber.get();
        }

        /**
         * @return the fieldCapacity
         */
        public String getFieldCapacity() {
            return fieldCapacity.get();
        }

        /**
         * @return the fieldComputers
         */
        public String getFieldComputers() {
            return fieldComputers.get();
        }

        /**
         * @return the fieldSmartRoom
         */
        public String getFieldSmartRoom() {
            return fieldSmartRoom.get();
        }

        /**
         * @return the fieldOther
         */
        public String getFieldOther() {
            return fieldOther.get();
        }

    }

    private ObservableList<Record> dataList
            = FXCollections.observableArrayList(
                    new Record("14", "232a", "20", "20", "yes", "N/A"),
                    new Record("14", "232b", "20", "20", "yes", "N/A"),
                    new Record("14", "301", "24", "24", "yes", "Computer Lab Setting"),
                    new Record("14", "302", "24", "24", "yes", "N/A"),
                    new Record("14", "303", "24", "24", "yes", "N/A"),
                    new Record("14", "255", "30", "10", "yes", "N/A"),
                    new Record("14", "256", "30", "10", "yes", "Tables rather than traditional desks."),
                    new Record("14", "257", "30", "10", "yes", "N/A"),
                    new Record("14", "250", "35", "5", "yes", "N/A"),
                    new Record("14", "251", "35", "5", "yes", "N/A"),
                    new Record("14", "247", "35", "35", "yes", "N/A"),
                    new Record("8", "121", "36", "36", "yes", "N/A"));

    /**
     * Initializes the controller class.
     */
    public void setStage(Stage stage) {
        this.stage = stage;
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {

        columnBuildingNumber.setCellValueFactory(
                new PropertyValueFactory<RoomsList_Controller.Record, String>("fieldBuildingNumber"));

        columnRoomNumber.setCellValueFactory(
                new PropertyValueFactory<RoomsList_Controller.Record, String>("fieldRoomNumber"));

        columnCapacity.setCellValueFactory(
                new PropertyValueFactory<RoomsList_Controller.Record, String>("fieldCapacity"));

        columnComputers.setCellValueFactory(
                new PropertyValueFactory<RoomsList_Controller.Record, String>("fieldComputers"));

        columnSmartRoom.setCellValueFactory(
                new PropertyValueFactory<RoomsList_Controller.Record, String>("fieldSmartRoom"));

        columnOther.setCellValueFactory(
                new PropertyValueFactory<RoomsList_Controller.Record, String>("fieldOther"));
        
        tableView.setItems(dataList);
    }

    @FXML
    private void backButtonClicked(ActionEvent event) {
           stage.close();
    }

    @FXML
    private void addButtonClicked(ActionEvent event) {
        try {
            final FXMLLoader loader = new FXMLLoader(getClass().getResource("chooseBuilding.fxml"));
            final Parent root = (Parent) loader.load();

            final ChooseBuildingController controller = loader.<ChooseBuildingController>getController();
            Scene scene = new Scene(root);

            controller.setStage(stage);

            stage.setScene(scene);
            stage.show();

            // Hide the current screen
            //((Node)(event.getSource())).getScene().getWindow().hide();
        } catch (IOException ex) {
            Logger.getLogger(ChooseBuildingController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @FXML
    private void removeButtonClicked(ActionEvent event) {
    }

    @FXML
    private void editButtonClicked(ActionEvent event) {
    }

}