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 BuildingsList_Controller implements Initializable {

    Stage stage;

    @FXML
    private Button backButton;
    @FXML
    private Button addButton;
    @FXML
    private Button removeButton;
    @FXML
    TableView tableView;
    @FXML
    TableColumn columnNumber;
    @FXML
    TableColumn columnName;
    @FXML
    TableColumn columnDepartment;

    public class Record {

        private SimpleStringProperty fieldName;
        private SimpleStringProperty fieldNumber;
        private SimpleStringProperty fieldDepartment;

        Record(String fieldNumber, String fieldName, String fieldDepartment) {
            this.fieldName = new SimpleStringProperty(fieldName);
            this.fieldDepartment = new SimpleStringProperty(fieldDepartment);
            this.fieldNumber = new SimpleStringProperty(fieldNumber);
        }

        /**
         * @return the fieldName
         */
        public String getFieldName() {
            return fieldName.get();
        }

        /**
         * @return the fieldNumber
         */
        public String getFieldNumber() {
            return fieldNumber.get();
        }

        /**
         * @return the fieldDepartment
         */
        public String getFieldDepartment() {
            return fieldDepartment.get();
        }

    }

    private ObservableList<Record> dataList
            = FXCollections.observableArrayList(
                    new Record("05", "Architecture and Environmental Design", "Architecture"),
                    new Record("08", "Bioresource & Agricultural Engineering", "Agriculture"),
                    new Record("14", "Computer Science Building", "Computer Science"),
                    new Record("42", "Robert E. Matt Physical Education", "Physical Education"));

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

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

        columnName.setCellValueFactory(
                new PropertyValueFactory<Record, String>("fieldName"));

        columnNumber.setCellValueFactory(
                new PropertyValueFactory<Record, String>("fieldNumber"));

        columnDepartment.setCellValueFactory(
                new PropertyValueFactory<Record, String>("fieldDepartment"));

        tableView.setItems(dataList);
        //tableView.getColumns().addAll(columnNumber, columnName, columnDepartment);
    }

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

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

            final ChooseBuildingLocationController controller = loader.<ChooseBuildingLocationController>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) {
    }

}