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 CourseListController 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
    private TableColumn columnDept;
    @FXML
    private TableColumn columnCoListDept;
    @FXML
    private TableColumn columnCourseNumber;
    @FXML
    private TableColumn columnTitle;
    @FXML
    private TableColumn columnType;
    @FXML
    private TableColumn columnWtus;
    @FXML
    private TableColumn columnCredits;
    @FXML
    private TableColumn columnDuration;
    @FXML
    private TableColumn columnSize;

    public class Record {

        private SimpleStringProperty fieldDept;
        private SimpleStringProperty fieldCoListDept;
        private SimpleStringProperty fieldCourseNumber;
        private SimpleStringProperty fieldTitle;
        private SimpleStringProperty fieldType;
        private SimpleStringProperty fieldWtus;
        private SimpleStringProperty fieldCredits;
        private SimpleStringProperty fieldDuration;
        private SimpleStringProperty fieldSize;

        Record(String fieldDept, String fieldCoListDept, String fieldCourseNumber, String fieldTitle, String fieldType, String fieldWtus, String fieldCredits, String fieldDuration, String fieldSize) {
            this.fieldDept = new SimpleStringProperty(fieldDept);
            this.fieldCoListDept = new SimpleStringProperty(fieldCoListDept);
            this.fieldCourseNumber = new SimpleStringProperty(fieldCourseNumber);
            this.fieldTitle = new SimpleStringProperty(fieldTitle);
            this.fieldType = new SimpleStringProperty(fieldType);
            this.fieldWtus = new SimpleStringProperty(fieldWtus);
            this.fieldCredits = new SimpleStringProperty(fieldCredits);
            this.fieldDuration = new SimpleStringProperty(fieldDuration);
            this.fieldCredits = new SimpleStringProperty(fieldCredits);
            this.fieldSize = new SimpleStringProperty(fieldSize);
        }

        /**
         * @return the fieldDept
         */
        public String getFieldDept() {
            return fieldDept.get();
        }

        /**
         * @return the fieldCoListDept
         */
        public String getFieldCoListDept() {
            return fieldCoListDept.get();
        }

        /**
         * @return the fieldCourseNumber
         */
        public String getFieldCourseNumber() {
            return fieldCourseNumber.get();
        }

        /**
         * @return the fieldTitle
         */
        public String getFieldTitle() {
            return fieldTitle.get();
        }

        /**
         * @return the fieldType
         */
        public String getFieldType() {
            return fieldType.get();
        }

        /**
         * @return the fieldWtus
         */
        public String getFieldWtus() {
            return fieldWtus.get();
        }

        /**
         * @return the fieldCredits
         */
        public String getFieldCredits() {
            return fieldCredits.get();
        }

        /**
         * @return the fieldDuration
         */
        public String getFieldDuration() {
            return fieldDuration.get();
        }

        /**
         * @return the fieldSize
         */
        public String getFieldSize() {
            return fieldSize.get();
        }
    }

    private ObservableList<Record> dataList
            = FXCollections.observableArrayList(
                    new Record("CSC", "", "100", "Computer Science Orientation", "Lecture", "2.0", "4", "3", "30"),
                    new Record("CSC", "CPE", "101", "Fundamentals in Computer Science 1", "Lecture", "3.0", "3", "3", "30"),
                    new Record("CSC", "CPE", "101", "Fundamentals in Computer Science 1", "Lab", "1.0", "1", "3", "30"),
                    new Record("CSC", "CPE", "102", "Fundamentals in Computer Science 2", "Lecture", "3.0", "3", "3", "30"),
                    new Record("CSC", "CPE", "102", "Fundamentals in Computer Science 2", "Lab", "1.0", "1", "3", "30"),
                    new Record("CSC", "CPE", "103", "Fundamentals in Computer Science 3", "Lecture", "3.0", "3", "3", "30"),
                    new Record("CSC", "CPE", "103", "Fundamentals in Computer Science 3", "Lab", "1.0", "1", "3", "30"),
                    new Record("CSC", "CPE", "123", "Introduction to Computing", "Lecture", "3.0", "3", "3", "30"),
                    new Record("CSC", "CPE", "123", "Introduction to Computing", "Lab", "1.0", "1", "3", "30"),
                    
                    new Record("CSC", "CPE", "141", "Discrete Structures", "Lab", "4.0", "4", "4", "30"),
                    new Record("CSC", "CPE", "225", "Computer Organization", "Lab", "3.0", "3", "3", "30"),
                    new Record("CSC", "CPE", "225", "Computer Organization", "Lab", "1.0", "1", "3", "30"));

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

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

        columnDept.setCellValueFactory(
                new PropertyValueFactory<BuildingsList_Controller.Record, String>("fieldDept"));

        columnCoListDept.setCellValueFactory(
                new PropertyValueFactory<BuildingsList_Controller.Record, String>("fieldCoListDept"));

        columnCourseNumber.setCellValueFactory(
                new PropertyValueFactory<BuildingsList_Controller.Record, String>("fieldCourseNumber"));

        columnTitle.setCellValueFactory(
                new PropertyValueFactory<BuildingsList_Controller.Record, String>("fieldCourseTitle"));
        columnType.setCellValueFactory(
                new PropertyValueFactory<BuildingsList_Controller.Record, String>("fieldType"));
        columnWtus.setCellValueFactory(
                new PropertyValueFactory<BuildingsList_Controller.Record, String>("fieldWtus"));
        columnCredits.setCellValueFactory(
                new PropertyValueFactory<BuildingsList_Controller.Record, String>("fieldCredits"));
        columnDuration.setCellValueFactory(
                new PropertyValueFactory<BuildingsList_Controller.Record, String>("fieldDuration"));
        columnSize.setCellValueFactory(
                new PropertyValueFactory<BuildingsList_Controller.Record, String>("fieldSize"));

        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("addCourseData.fxml"));
            final Parent root = (Parent) loader.load();

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

}