-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseController.java
More file actions
147 lines (127 loc) · 5.74 KB
/
CourseController.java
File metadata and controls
147 lines (127 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package controller;
import animatefx.animation.FadeIn;
import animatefx.animation.RubberBand;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import model.Course;
import model.Participant;
import javax.swing.*;
import java.io.IOException;
import java.time.LocalDate;
public class CourseController {
//Obiekt listy Kursów
ObservableList<Course> courses = FXCollections.observableArrayList();
public static int id;
////////
@FXML
private TableView<Course> tbl_course;
@FXML
private TableColumn<Course, String> col_course_name;
@FXML
private TableColumn<Course, String> col_course_category;
@FXML
private TextField tf_course_name;
@FXML
private TextField tf_course_category;
@FXML
private TextField tf_course_trainer;
@FXML
private DatePicker dp_course_date;
@FXML
Button btn_add, btn_delate, btn_view;
@FXML
void addCourse(ActionEvent event) {
//walidacja danych
if (!tf_course_name.getText().equals("") && !tf_course_category.getText().equals("") && dp_course_date.getValue() != null) {
//pobieranie wartosci z kontrolki TextField
String course_name = tf_course_name.getText();
String course_category = tf_course_category.getText();
LocalDate course_date = dp_course_date.getValue();
String course_trainer = tf_course_trainer.getText();
//Tworzenie obiektu klasy Course
Course c = new Course(++id, course_name, course_category, course_date, course_trainer);
courses.add(c);
//Zerowanie wartosci po dodaniu kursu
tf_course_name.setText("");
tf_course_category.setText("");
tf_course_trainer.setText("");
dp_course_date.setValue(null);
//Odswiezenie TableView
new FadeIn(btn_add).play();
insertCoursesIntoTableView();
} else {
//JOptionPane.showMessageDialog(null, "Błąd.
Alert a = new Alert(Alert.AlertType.ERROR);
a.setTitle("Błąd");
a.setHeaderText("Błąd dodawania nowego kursu");
a.setContentText("Musisz podać wszystkie dane");
a.show();
new RubberBand(btn_add).play();
}
}
@FXML
void deleteCourse(ActionEvent event) {
//odczyt zaznaczonego rekordu z tabeli
Course c_deleted = tbl_course.getSelectionModel().getSelectedItem();
courses.remove(c_deleted);
new RubberBand(btn_delate).play();
insertCoursesIntoTableView();
}
//przekazywanie obiektu statycznego do innego widoku
static Course c_selected;
@FXML
void getCourse(ActionEvent event) throws IOException {
c_selected = tbl_course.getSelectionModel().getSelectedItem();
Stage courseStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("/view/detailCourseView.fxml"));
courseStage.setTitle("Wybrany kurs");
courseStage.setScene(new Scene(root));
courseStage.getScene().getStylesheets().add("Style.css");
Image image = new Image("/view/img/logo.png");
courseStage.getIcons().add(image);
courseStage.setResizable(false);
new FadeIn(btn_view).play();
courseStage.show();
}
//metoda do wprowadzania zawartosci kursow do tabelki
private void insertCoursesIntoTableView() {
//konfiguracja zmiennych do klolumn
col_course_name.setCellValueFactory(new PropertyValueFactory<Course, String>("course_name"));
col_course_category.setCellValueFactory(new PropertyValueFactory<Course, String>("course_category"));
//wprowadzenie danych do tabeli z listy ObservedList
tbl_course.setItems(courses);
}
private void addSampleData(){
courses.add(new Course(++id,"Java FX" , "Programowanie", LocalDate.of(2019,01,12),"Roman Taczka"));
courses.add(new Course(++id,"CSS i HTML" , "Strony WWW", LocalDate.of(2019,01,12),"Grzegorz Wiadro"));
courses.add(new Course(++id,"ISTQB" , "Testowanie", LocalDate.of(2019,01,12),"Stanisław Szybki"));
courses.add(new Course(++id,"Javascript" , "Programowanie", LocalDate.of(2019,01,12),"Wojciech Mojżesz"));
courses.add(new Course(++id,"MY SQL" , "Bazy Danych", LocalDate.of(2019,01,12),"Maciej Borek"));
courses.add(new Course(++id,"Android studio" , "Programowanie", LocalDate.of(2019,01,12),"Radosław Kałuża"));
courses.get(1).addParticipant(new Participant("Janusz", "Kowalski"));
courses.get(0).addParticipant(new Participant("Grażyna", "Nowak"));
courses.get(2).addParticipant(new Participant("Jakub", "Dudek"));
courses.get(3).addParticipant(new Participant("Grzegorz", "Szczęsny"));
courses.get(4).addParticipant(new Participant("Maciej", "Glik"));
courses.get(5).addParticipant(new Participant("Władysław", "Jagiełło"));
courses.get(0).addParticipant(new Participant("Mariola", "Kownacka"));
courses.get(1).addParticipant(new Participant("Ździsław", "Sosna"));
courses.get(2).addParticipant(new Participant("Michał", "Warzycha"));
courses.get(3).addParticipant(new Participant("Teresa", "Maj"));
courses.get(4).addParticipant(new Participant("Benedykt", "Lewandpwski"));
courses.get(5).addParticipant(new Participant("Andrzej", "Piszczel"));
}
public void initialize() {
addSampleData();
insertCoursesIntoTableView();
}
}