Created
December 31, 2017 12:57
-
-
Save ajfmo/c76db46f1a5701e827942550b5f01d93 to your computer and use it in GitHub Desktop.
View Controller for Student Menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ajfmo.studycontrol.view; | |
import java.net.URL; | |
import java.util.ResourceBundle; | |
import ajfmo.studycontrol.DAO.StudentDAO; | |
import ajfmo.studycontrol.entities.Career; | |
import ajfmo.studycontrol.entities.Section; | |
import ajfmo.studycontrol.entities.Student; | |
import ajfmo.studycontrol.utils.HibernateUtil; | |
import javafx.collections.FXCollections; | |
import javafx.collections.ObservableList; | |
import javafx.fxml.FXML; | |
import javafx.fxml.Initializable; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.ComboBox; | |
import javafx.scene.control.TableColumn; | |
import javafx.scene.control.TableView; | |
import javafx.scene.control.TextField; | |
import javafx.stage.Stage; | |
public class StudentView implements Initializable { | |
// Objetos | |
StudentDAO student = new StudentDAO(); | |
// Colections | |
private ObservableList<Career> careersList; | |
private ObservableList<Section> sectionsList; | |
// FXML | |
@FXML | |
private TextField txtNombre, txtNombreB, txtCodigo, txtCodigoB, txtSeccion, txtCarrera; | |
@FXML | |
private Button btnBuscar, btnGuardar, btnLimpiar, btnSalir; | |
@FXML | |
private TableView<Student> tblEstudiantes; | |
@FXML | |
private TableColumn<Student, Integer> colCodigo; | |
@FXML | |
private TableColumn<Student, String> colNombre; | |
@FXML | |
private TableColumn<Student, String> colCarrera; | |
@FXML | |
private TableColumn<Student, String> colSection; | |
@FXML | |
private ComboBox<Career> cboCarrera; | |
@FXML | |
private ComboBox<Section> cboSeccion; | |
@Override | |
public void initialize(URL location, ResourceBundle resources) { | |
careersList = FXCollections.observableArrayList(); | |
sectionsList = FXCollections.observableArrayList(); | |
fillCareersCbo(careersList); | |
fillSectionsCbo(sectionsList); | |
cboCarrera.setItems(careersList); | |
cboSeccion.setItems(sectionsList); | |
} | |
private void fillCareersCbo(ObservableList<Career> careersList) { | |
for (Career careers : student.careerCriteria()) { | |
careersList.add(new Career(careers.getCareerId(), careers.getCareerName())); | |
} | |
} | |
private void fillSectionsCbo(ObservableList<Section> sectionList) { | |
for (Section sections : student.sectionCriteria()) { | |
sectionList.add(new Section(sections.getSectionId(), sections.getSectionName())); | |
} | |
} | |
/** | |
* Fill TableView | |
*/ | |
private void fillTableView(ObservableList<Student> studentList) { | |
for (Student students : student.studentCriteria()) { | |
studentList.add(new Student(students.getStudentId(), students.getStudentName(), students.getCareer(), | |
students.getSection())); | |
} | |
} | |
@FXML | |
private void create() { | |
student.createStudent(txtCodigo.getText(), txtNombre.getText(), cboCarrera.getValue(), cboSeccion.getValue()); | |
} | |
@FXML | |
private void salir() { | |
HibernateUtil.shutdown(); | |
Stage stage = (Stage) btnSalir.getScene().getWindow(); | |
stage.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment