Newer
Older
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.*;
@FXML
BorderPane myBorderPane;
@FXML
VBox leftSideButtons;
@FXML
TextArea employees;
@FXML
private TextField addFirstName;
@FXML
private TextField addLastName;
@FXML
private TextField removeID;
@FXML
Button addShiftSubmitButton;
@FXML
DatePicker addShiftDatePicker;
@FXML
TextField addShiftStartTime;
@FXML
TextField addShiftEndTime;
@FXML
ComboBox addShiftEmployeeBox;
@FXML
HBox addShiftEmployeeHBox;
@FXML
ComboBox addShiftStartTimeBox;
@FXML
ComboBox addShiftEndTimeBox;
@FXML
Label loggedIn;
@FXML
Label viewing;
@FXML
Label loginWarning;
ArktikHunter
committed
DailyView dailyView;
WeeklyView weeklyView;
EmployeeView employeeView;
ArktikHunter
committed
BorderPane root;
Parent header;
Parent sideSchedulePanel;
ArktikHunter
committed
Parent bottomPanel;
Parent paystubView;
Parent editEmployeeView;
Parent addEmployeeView;
Parent staffPanel;
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
// login methods, initializes views too
public void attemptLogin(MouseEvent e) throws IOException {
if (!model.hasEmployee(Integer.parseInt(loginField.getText()))) {
loginWarning.setText("Invalid id");
}
else {
login(e);
}
}
public void login(MouseEvent e) throws IOException {
//set this employee and manager privileges as appropriate
int thisEmployee = Integer.parseInt(loginField.getText());
model.setThisEmployee(thisEmployee);
model.setSelectedEmployee(thisEmployee);
model.setIsManager(model.getEmployee(thisEmployee).isManager());
//load everything
loadEverything();
//set up for initial daily schedule view
root.setTop(header);
viewSchedule();
Stage stage = (Stage)((Node)e.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
//set variable text
currentDateText.setText("Current Date: " + model.date);
loggedIn.setText("Logged In: " + model.getEmployeeByID(model.getThisEmployee()));
//set manager specific text
if (model.getIsManager()){
viewing.setText("Viewing: " + model.getEmployeeByID(model.getSelectedEmployee()));
}
// add components here to be loaded once
public void loadEverything() throws IOException {
root = new BorderPane();
dailyView = new DailyView();
dailyView.setModel(model);
model.addSubscriber(dailyView);
weeklyView = new WeeklyView();
weeklyView.setModel(model);
model.addSubscriber(weeklyView);
employeeView = new EmployeeView();
employeeView.setModel(model);
model.addSubscriber(employeeView);
availabilityView = new AvailabilityView();
availabilityView.setModel(model);
model.addSubscriber(availabilityView);
//fxml views
loadHeader();
loadScheduleSide();
loadScheduleBottom();
loadPaystubView();
loadEditEmployee();
loadStaffPanel();
}
//load header
public void loadHeader() throws IOException {
if (model.getIsManager()){ //load manager header
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
header = headerLoader.load();
}
else { //load employee header
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("employeeHeader.fxml"));
//FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml")); //for now
headerLoader.setController(this);
header = headerLoader.load();
}
}
public void loadPaystubView() throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(ScheduleApp.class.getResource("paystubView.fxml"));
fxmlLoader.setController(this);
paystubView = fxmlLoader.load();
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
// show schedule, default to daily
public void viewSchedule(){
root.setLeft(sideSchedulePanel);
root.setBottom(bottomPanel);
root.setCenter(dailyView);
}
// load weekly view from schedule daily
public void viewScheduleWeekly(){
root.setCenter(weeklyView);
}
public void viewScheduleDaily(){
root.setCenter(dailyView);
}
// load pickups from schedule todo
public void viewPickups(){
//root.setCenter();
}
public void loadScheduleSide() throws IOException {
//same for both
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("schedSidePanel.fxml"));
sideLoader.setController(this);
sideSchedulePanel = sideLoader.load();
}
public void loadScheduleBottom() throws IOException {
if (model.getIsManager()){
FXMLLoader bottomLoader = new FXMLLoader(this.getClass().getResource("schedBottomPanelManager.fxml"));
bottomLoader.setController(this);
bottomPanel = bottomLoader.load();
}
else {
FXMLLoader bottomLoader = new FXMLLoader(this.getClass().getResource("employeeSchedBottomPanel.fxml"));
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
bottomLoader.setController(this);
bottomPanel = bottomLoader.load();
}
}
public void loadEditEmployee() throws IOException{
FXMLLoader gridLoader = new FXMLLoader(this.getClass().getResource("editEmployee.fxml"));
gridLoader.setController(this);
editEmployeeView = gridLoader.load();
}
public void viewPaystub() throws IOException {
root.setCenter(paystubView);
}
public void viewPayroll() {
System.out.println("todo: display payroll");
}
public void viewRequests() {
System.out.println("todo: display requests");
}
public void viewEditEmployee(){
root.setCenter(editEmployeeView);
}
public void viewAvailability() {
public void timeoffButtonClicked () {
System.out.println("timeoff button clicked");
}
// manager clicked on Employee tab
public void viewStaff(){
root.setLeft(staffPanel);
root.setCenter(employeeView);
root.setBottom(null);
public void loadStaffPanel() throws IOException {
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("staffManagerSidePanel.fxml"));
sideLoader.setController(this);
staffPanel = sideLoader.load();
public void pickupsButtonClicked () {
System.out.println("pickups button clicked");
}
public void prevButtonClicked (MouseEvent event) throws Exception {
System.out.println("prev button clicked");
ArktikHunter
committed
model.datePrev();
public void jumpButtonClicked (MouseEvent event) throws Exception {
System.out.println("jump button clicked");
ArktikHunter
committed
//model.dateJump();
public void nextButtonClicked (MouseEvent event) throws Exception {
System.out.println("next button clicked");
ArktikHunter
committed
model.dateNext();
public void addShiftClicked() throws IOException {
FXMLLoader popupLoader = new FXMLLoader(this.getClass().getResource("addShiftPopup.fxml"));
popupLoader.setController(this);
popupScene = new Scene(popupLoader.load(),500,500);
popupStage = new Stage();
popupStage.setScene(popupScene);
popupStage.show();
public void populateEmployeeBox(MouseEvent event) {
ObservableList<String> list = FXCollections.observableArrayList();
ComboBox test = (ComboBox) event.getSource();
test.setItems(list);
public void populatePositionBox(MouseEvent event) {
ArrayList<String> aList = model.returnPositions();
ObservableList<String> list = FXCollections.observableArrayList();
list.addAll(aList);
ComboBox test = (ComboBox) event.getSource();
test.setItems(list);
}
public void cancelClicked(MouseEvent e){
((Node)e.getSource()).getScene().getWindow().hide();
}
System.out.println("submit clicked");
int index = addShiftEmployeeBox.getSelectionModel().getSelectedIndex();
String startTime = (String) addShiftStartTimeBox.getValue();
String endTime = (String) addShiftEndTimeBox.getValue();
String result = model.addShift(model.getIDbyIndex(index),date.toString(),Integer.parseInt(startTime),Integer.parseInt(endTime));
System.out.println(result);
//todo: show result to user?
public void addShiftTimeBoxClicked(MouseEvent event){
System.out.println("add shift time box clicked");
ArrayList<String> times = new ArrayList<>();
for (int i = 8; i < 24; i++){
String j = i + "00";
String k = i + "30";
if (i < 10) {
j = "0" + j;
k = "0" + k;
}
times.add(j);
times.add(k);
}
ComboBox box = (ComboBox) event.getSource();
ObservableList<String> list = FXCollections.observableArrayList(times);
box.setItems(list);
public void updateCurrentDate(MouseEvent event) throws Exception {
if(currentDateText == null){
currentDateText = new Label();
}
currentDateText.setText("Current Date: " + model.date.toString());
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
public void employeePickupClicked() throws IOException {
System.out.println("employee pickup clicked");
FXMLLoader pickupLoader = new FXMLLoader(getClass().getResource("employeePickup.fxml"));
pickupLoader.setController(this);
root.setCenter(pickupLoader.load());
root.setBottom(null);
}
public void employeeAvailabilityClicked() throws IOException {
System.out.println("employee availability clicked");
FXMLLoader availabilityLoader = new FXMLLoader(getClass().getResource("employeeAvailability.fxml"));
availabilityLoader.setController(this);
FXMLLoader availabilityFooterLoader = new FXMLLoader(getClass().getResource("employeeAvailabilityFooter.fxml"));
availabilityFooterLoader.setController(this);
root.setCenter(availabilityLoader.load());
root.setLeft(null);
root.setBottom(availabilityFooterLoader.load());
}
public void employeePaystubClicked() throws IOException {
System.out.println("employee paystub clicked");
FXMLLoader paystubLoader = new FXMLLoader(getClass().getResource("employeePaystub.fxml"));
paystubLoader.setController(this);
root.setCenter(paystubLoader.load());
root.setLeft(null);
root.setBottom(bottomPanel);
}
public void employeeNextButtonClicked(){
System.out.println("employee next clicked");
}
public void employeePrevButtonClicked(){
System.out.println("employee prev clicked");
}
public void employeeJumpButtonClicked(){
System.out.println("employee jump clicked");
public void logoutClicked(MouseEvent mouseEvent) throws IOException {
FXMLLoader loginLoader = new FXMLLoader(this.getClass().getResource("login.fxml"));
loginLoader.setController(this);
Parent root = loginLoader.load();
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
// Staff Section
// Switch to Staff Page
public void staffManagerClicked(MouseEvent mouseEvent) throws IOException {
BorderPane root = new BorderPane();
FXMLLoader gridLoader = new FXMLLoader(this.getClass().getResource("addEmployee.fxml"));
gridLoader.setController(this);
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
Parent header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("staffManagerSidePanel.fxml"));
sideLoader.setController(this);
Parent sidePanel = sideLoader.load();
root.setTop(header);
root.setLeft(sidePanel);
root.setCenter(grid);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
// Side Panel
// Switch to Edit Employee
public void editStaffSidePanelClicked(MouseEvent mouseEvent) throws IOException {
BorderPane root = new BorderPane();
FXMLLoader gridLoader = new FXMLLoader(this.getClass().getResource("editEmployee.fxml"));
gridLoader.setController(this);
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
Parent header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("staffManagerSidePanel.fxml"));
sideLoader.setController(this);
Parent sidePanel = sideLoader.load();
root.setTop(header);
root.setLeft(sidePanel);
root.setCenter(grid);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
}
// Switch to Remove Employee
public void removeStaffSidePanelClicked(MouseEvent mouseEvent) throws IOException {
FXMLLoader gridLoader = new FXMLLoader(this.getClass().getResource("removeEmployee.fxml"));
gridLoader.setController(this);
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
Parent header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("staffManagerSidePanel.fxml"));
sideLoader.setController(this);
Parent sidePanel = sideLoader.load();
root.setTop(header);
root.setLeft(sidePanel);
root.setCenter(grid);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
}
// Switch to View Employees
public void viewStaffSidePanelClicked(MouseEvent mouseEvent) throws IOException {
BorderPane root = new BorderPane();
FXMLLoader gridLoader = new FXMLLoader(this.getClass().getResource("viewEmployees.fxml"));
gridLoader.setController(this);
FXMLLoader headerLoader = new FXMLLoader(this.getClass().getResource("headerManager.fxml"));
headerLoader.setController(this);
Parent header = headerLoader.load();
FXMLLoader sideLoader = new FXMLLoader(this.getClass().getResource("staffManagerSidePanel.fxml"));
sideLoader.setController(this);
Parent sidePanel = sideLoader.load();
root.setTop(header);
root.setLeft(sidePanel);
root.setCenter(grid);
Stage stage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow();
Scene scene = new Scene(root, 800, 600);
stage.setTitle("Scheduler App");
stage.setScene(scene);
stage.show();
}
// Add, Edit, Remove Functions
// Add Employee
public void addEmployeeClicked(MouseEvent mouseEvent) {
String firstName = addFirstName.getText();
String lastName = addLastName.getText();
model.addEmployee(firstName, lastName);
System.out.println("Employee " + firstName + " " + lastName + " added to Staff. Welcome "
+ firstName + "!");
}
public void editEmployeeClicked(MouseEvent mouseEvent) {
public void removeEmployeeClicked(MouseEvent mouseEvent) {
int index = removeEmployeeBox.getSelectionModel().getSelectedIndex();
String id = String.valueOf(model.getIDbyIndex(index));
model.removeEmployee(id);
removeEmployeeBox.getSelectionModel().clearSelection();
public void setModel(Model model) {
this.model = model;
}