-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCancellationPanel.java
More file actions
74 lines (57 loc) · 2.34 KB
/
CancellationPanel.java
File metadata and controls
74 lines (57 loc) · 2.34 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
package flightscheduleryjw5018.gui;
import flightscheduleryjw5018.data.Booking;
import flightscheduleryjw5018.services.DateUtils;
import flightscheduleryjw5018.services.SchedulingService;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.util.Collection;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class CancellationPanel extends JPanel implements DayUpdateListener {
private SchedulingService schedulingService;
private final JTextField customer = new JTextField("", 20);
private final JComboBox dayList = new JComboBox();
public CancellationPanel() {
}
public void init() {
setLayout(new FlowLayout());
add(new JLabel("Customer"));
add(customer);
add(new JLabel("Date"));
add(dayList);
JButton bookButton = new JButton("Cancel");
bookButton.addActionListener((ActionEvent e) -> {
Date day = DateUtils.parseDate((String) dayList.getSelectedItem());
String customerName = customer.getText();
boolean booked = false;
Collection<Booking> newBookings = schedulingService.cancelFlight(customerName, day);
String msg = customerName + " has been successfully cancelled for all flights on " + DateUtils.formatDate(day) + ".\n";
for (Booking booking : newBookings) {
msg += "Previously waitlisted customer " + booking.getCustomer() + " has been booked for flight " + booking.getFlight() + " on " + DateUtils.formatDate(booking.getDate()) + ".\n";
}
JOptionPane.showMessageDialog(null, msg);
});
add(bookButton);
updateDayList();
}
public void updateDayList() {
dayList.removeAllItems();
Collection<Date> days = schedulingService.getDays();
for (Date day : days) {
String d = DateUtils.formatDate(day);
dayList.addItem(d);
}
}
@Override
public void dayUpdated() {
updateDayList();
}
public void setSchedulingService(SchedulingService schedulingService) {
this.schedulingService = schedulingService;
}
}