-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindowController.java
More file actions
166 lines (148 loc) · 5.88 KB
/
MainWindowController.java
File metadata and controls
166 lines (148 loc) · 5.88 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.organizer.projektorganizer.view;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import com.organizer.projektorganizer.MainApp;
import com.organizer.projektorganizer.model.FinalRepozitory;
import com.organizer.projektorganizer.model.Przedmiot;
import java.util.LinkedList;
import java.util.List;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
public class MainWindowController {
@FXML
private TableView<Przedmiot> przedmiotTable;
@FXML
private TableColumn<Przedmiot, String> nazwaPrzedmiotuColumn;
@FXML
private TableColumn<Przedmiot, String> kategoriaPrzedmiotuColumn;
@FXML
private Label cenaLabel;
@FXML
private Label miejsceZakupuLabel;
@FXML
private Label dataZakupuLabel;
@FXML
private Label terminPrzydLabel;
@FXML
private Label waznoscGwarLabel;
@FXML
private Label ocenaLabel;
// Reference to the main application.
private MainApp mainApp;
/**
* The constructor.
* The constructor is called before the initialize() method.
*/
public MainWindowController() {
}
/**
* Initializes the controller class. This method is automatically called
* after the fxml file has been loaded.
*/
@FXML
private void initialize() {
// Initialize the person table with the two columns.
nazwaPrzedmiotuColumn.setCellValueFactory(cellData -> cellData.getValue().getNazwaPrzedmiotuProperty());
kategoriaPrzedmiotuColumn.setCellValueFactory(cellData -> cellData.getValue().getKategoriaPrzedmiotuProperty());
pokazSzczegolyPrzedmiotu(null);
przedmiotTable.getSelectionModel().selectedItemProperty().addListener(
(observable, oldValue, newValue)->pokazSzczegolyPrzedmiotu(newValue));
}
/**
* Is called by the main application to give a reference back to itself.
*
* @param mainApp
*/
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
// Add observable list data to the table
przedmiotTable.setItems(mainApp.getPrzedmiotData());
}
private void pokazSzczegolyPrzedmiotu(Przedmiot przedmiot){
if(przedmiot != null){
cenaLabel.setText(Double.toString(przedmiot.getCenaPrzedmiotu()));
miejsceZakupuLabel.setText(przedmiot.getMiejsceZakupu());
dataZakupuLabel.setText(przedmiot.getDataZakupu().toString());
terminPrzydLabel.setText(przedmiot.getTerminPrzydatnosci().toString());
waznoscGwarLabel.setText(przedmiot.getWaznoscGwarancji().toString());
ocenaLabel.setText(Integer.toString(przedmiot.getOcenaPrzedmiotu()));
}
else{
cenaLabel.setText("");
miejsceZakupuLabel.setText("");
dataZakupuLabel.setText("");
terminPrzydLabel.setText("");
waznoscGwarLabel.setText("");
}
}
@FXML
void handleDeletePrzedmiot(){
int selectedIndex = przedmiotTable.getSelectionModel().getSelectedIndex();
Przedmiot selectedPrzedmiot = przedmiotTable.getSelectionModel().getSelectedItem();
FinalRepozitory repo = mainApp.getRepozytorium();
if(selectedIndex >= 0){
repo.method().deletePrzedmiot(selectedPrzedmiot);
przedmiotTable.getItems().remove(selectedIndex);
}else{
Alert alert = new Alert(AlertType.WARNING);
alert.initOwner(mainApp.getPrimaryStage());
alert.setTitle("No Selection");
alert.setHeaderText("Nie wybrano przedmiotu");
alert.setContentText("Wybierz przedmiot do usuniecia");
alert.showAndWait();
}
}
@FXML
private void handleNewPrzedmiot() {
Przedmiot tempPrzedmiot = new Przedmiot();
FinalRepozitory repo = mainApp.getRepozytorium();
boolean okClicked = mainApp.showPrzedmiotEditDialog(tempPrzedmiot);
if (okClicked) {
mainApp.getPrzedmiotData().add(tempPrzedmiot);
repo.method().insertPrzedmiot(tempPrzedmiot);
mainApp.setDataFromDatabase();
pokazSzczegolyPrzedmiotu(tempPrzedmiot);
//testListy(); //metoda do przetesotwania listy z bazy
}
}
/**
* Called when the user clicks the edit button. Opens a dialog to edit
* details for the selected person.
*/
@FXML
private void handleEditPrzedmiot() {
przedmiotTable.setItems(mainApp.getPrzedmiotData());
Przedmiot selectedPrzedmiot = przedmiotTable.getSelectionModel().getSelectedItem();
FinalRepozitory repo = mainApp.getRepozytorium();
if (selectedPrzedmiot != null) {
boolean okClicked = mainApp.showPrzedmiotEditDialog(selectedPrzedmiot);
if (okClicked) {
pokazSzczegolyPrzedmiotu(selectedPrzedmiot);
repo.method().updatePrzedmiot(selectedPrzedmiot);
}
} else {
// Nothing selected.
Alert alert = new Alert(AlertType.WARNING);
alert.initOwner(mainApp.getPrimaryStage());
alert.setTitle("Brak przedmiotu");
alert.setHeaderText("Brak wybranego przedmiotu");
alert.setContentText("Prosze wybrac przedmiot do edycji.");
alert.showAndWait();
}
}
/*
void testListy(){
Repozytorium repo = mainApp.getRepozytorium();
List<Przedmiot> listaPrzed = repo.selectPrzedmioty();
for(Przedmiot przedmiot: listaPrzed){
System.out.println(przedmiot.getNazwaPrzedmiotu());
}
}
*/
@FXML
private void handleTrayButton(){
mainApp.goToTray();
}
}