-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmpl.java
More file actions
213 lines (163 loc) · 7.21 KB
/
Copy pathEmpl.java
File metadata and controls
213 lines (163 loc) · 7.21 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package c;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Font;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.util.Callback;
import m.Dept;
import m.EmplOperations;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by Bettayeb on 5/4/2017.
*/
public class Empl implements Initializable {
@FXML
public static TableView emplTv;
@FXML
public Button btnUpdateEmpl;
public static m.Empl employeeToUpdate;
public static String addOrEdit;
TableColumn cId,cFname,cLname,cIdDept;
@Override
public void initialize(URL location, ResourceBundle resources) {
btnUpdateEmpl.setDisable(true);
new Thread(()->{
//System.out.println(getClass().getResource("../v/EmplStyle.css").toExternalForm());
Platform.runLater(()->{
emplTv.getParent().getStylesheets().add(getClass().getResource("../v/EmplStyle.css").toExternalForm());
emplTv.setVisible(true);
Label l=new Label("Loading...");
l.setFont(new Font("Arial",35.0));
emplTv.setPlaceholder(l);
cId=new TableColumn("ID");
cFname=new TableColumn("First Name");
cLname=new TableColumn("Last Name");
cIdDept=new TableColumn("Departement");
emplTv.getColumns().add(cId);
emplTv.getColumns().add(cFname);
emplTv.getColumns().add(cLname);
emplTv.getColumns().add(cIdDept);
emplTv.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.out.println(emplTv.getSelectionModel().getSelectedIndex());
System.out.println(((m.Empl)emplTv.getSelectionModel().getSelectedItem()).getFname());
}
});
});
ObservableList<m.Empl> data = FXCollections.observableArrayList();
EmplOperations emplOperations=new EmplOperations();
data.addAll(emplOperations.getAll());
// for (m.Empl e:emplOperations.getAll()) {
// System.out.println(e.getId());
// }
cId.setCellValueFactory(new PropertyValueFactory<m.Empl,Integer>("id"));
cFname.setCellValueFactory(new PropertyValueFactory<m.Empl,String>("fname"));
cLname.setCellValueFactory(new PropertyValueFactory<m.Empl,String>("lname"));
// cIdDept.setCellValueFactory(new PropertyValueFactory<m.Empl, Dept>("dept"));
Platform.runLater(()->{
emplTv.setItems(data);
TableColumn cIdDeptId=new TableColumn("ID");
TableColumn cIdDeptLabel=new TableColumn("Label");
cIdDept.getColumns().addAll(cIdDeptId,cIdDeptLabel);
cIdDeptId.setCellValueFactory(new PropertyValueFactory<m.Empl, Dept>("id_dept"));
cIdDeptLabel.setCellValueFactory(new PropertyValueFactory<m.Empl, Dept>("label_dept"));
cIdDeptId.setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn param) {
return new TableCell(){
@Override
protected void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
if(empty) return;
if(Integer.parseInt(item.toString())>=2){
getStyleClass().add("c1");
}
setText(item.toString());
}
};
}
});
emplTv.setRowFactory(new Callback<TableView, TableRow>() {
@Override
public TableRow call(TableView param) {
return new TableRow<m.Empl>(){
@Override
protected void updateItem(m.Empl item, boolean empty) {
super.updateItem(item, empty);
if(empty==true) return;
if (getIndex() % 2==0) {
getStyleClass().add("t2");
} else {
getStyleClass().add("t1");
}
}
};
}
});
});
}).start();
emplTv.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
if(emplTv.getSelectionModel().getSelectedItem()==null){
btnUpdateEmpl.setDisable(true);
}else{
btnUpdateEmpl.setDisable(false);
}
}
});
}
public static Stage primaryStage=new Stage();
public void btnUpdateEmplClick() throws Exception{
if(emplTv.getSelectionModel().getSelectedItem()==null){
Tooltip t=new Tooltip("Hello");
btnUpdateEmpl.setTooltip(t);
return ;
}
m.Empl employee = (m.Empl) emplTv.getSelectionModel().getSelectedItem();
System.out.println("You want to update the employee: ");
System.out.println("{\n"+employee.getId());
System.out.println(employee.getFname());
System.out.println(employee.getLname());
System.out.println(employee.getDept().getId());
System.out.println(employee.getDept().getLabel()+"}");
this.employeeToUpdate=employee;
addOrEdit="EDIT";
Parent root = FXMLLoader.load(getClass().getResource("../v/empl_update.fxml"));
primaryStage.setTitle("Update the selected employee - Departements Management System");
//primaryStage.setMaximized(true);
try{
primaryStage.initModality(Modality.APPLICATION_MODAL);
}catch (Exception e){
}
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public void btnAddEmplClick() throws Exception{
addOrEdit="ADD";
Parent root = FXMLLoader.load(getClass().getResource("../v/empl_update.fxml"));
primaryStage.setTitle("Add a new employee - Departements Management System");
//primaryStage.setMaximized(true);
try{
primaryStage.initModality(Modality.APPLICATION_MODAL);
}catch (Exception e){
}
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
}