-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBookingsView.java
245 lines (189 loc) · 6.93 KB
/
BookingsView.java
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import Basic.Facility;
import Basic.Member;
import Basic.TimeSlot;
import Basic.Transaction;
public class BookingsView extends JFrame{
private Admin admin;
//private AdminController controller;
private JPanel panel;
private JButton submitButton, cancelButton;
private JLabel label0, label1;
private JTextField input0, input1;
private AdminView controller;
private DataPool dp;
private JComboBox facilityType;
private JTable table;
private ButtonGroup selectedBooking;
private static final Object[][] rowData = {};
private static final Object[] columnNames = {"ID","Date","Member","Facility","TimeSlot","PaxCount","Price"};
private JPanel searchResult;
private JTable table_1;
private JButton btnUpdate;
private JButton btnDelete;
private JLabel label;
public BookingsView(AdminView controller){
//
dp = new DataPool();
ArrayList<String> listOfType = new ArrayList<String>();
listOfType.add("All");
listOfType.add("Restaurant");
listOfType.add("Ktv");
listOfType.add("Billiard");
listOfType.add("Bbq pit");
setBounds(100, 100, 450, 300);
this.controller=controller;
panel = new JPanel();
panel.setBorder(new EmptyBorder(5, 5, 5, 5));
panel.setLayout(null);
facilityType = new JComboBox();
for(String f: listOfType){
facilityType.addItem(f);
}
facilityType.setBounds(173, 11, 151, 27);
panel.add(facilityType);
JLabel filterLabel = new JLabel("Filter");
filterLabel.setBounds(108, 23, 54, 16);
panel.add(filterLabel);
//panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
panel.setBorder(BorderFactory.createTitledBorder("Booking"));
//panel.setLayout(new GridLayout(3,2));
panel.setBackground(Color.white);
JButton btnCancel = new JButton("Cancel");
btnCancel.setBounds(324, 11, 100, 26);
btnCancel.addActionListener(new ButtonListener());
panel.add(btnCancel);
getContentPane().add(panel);
searchResult = new JPanel();
searchResult.setBounds(6, 49, 418, 181);
panel.add(searchResult);
searchResult.setLayout(null);
btnDelete = new JButton("Book");
btnDelete.setBounds(212, 235, 117, 29);
btnDelete.addActionListener(new ButtonDeactivateListener());
panel.add(btnDelete);
label = new JLabel("");
label.setBounds(6, 248, 205, 16);
panel.add(label);
}
private class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
controller.mainMenu();
}
}
private class ButtonUpdateListener implements ActionListener{
public void actionPerformed(ActionEvent e){
// label.setText(selectedFacility.getSelection().getActionCommand());
int idToUpdate = Integer.parseInt(selectedBooking.getSelection().getActionCommand());
controller.frameUpdateFacility(idToUpdate);
}
}
private class ButtonDeactivateListener_ implements ActionListener{
public void actionPerformed(ActionEvent e){
String facility = (String) facilityType.getSelectedItem();
ArrayList<Transaction> fList = dp.getTransactionList();
DefaultTableModel listTableModel;
listTableModel = new DefaultTableModel(rowData, columnNames);
int resultCount = 0;
JRadioButton bt;
for (Transaction f: fList) {
if (!(facility.equalsIgnoreCase("all"))){
if (f.getFacility().getType().toLowerCase().contains(facility.toLowerCase())){
bt = new JRadioButton();
bt.setActionCommand(String.valueOf(f.getID()));
resultCount++;
// {"ID","Date","Member","Facility","TimeSlot","PaxCount","Price"};
listTableModel.addRow(new Object[]{f.getID(), f.getDate(), f.getUser().getfName() + f.getUser().getlName(),
f.getTimeSlot().toString(), f.getPaxCount(),f.getPrice(), f.getStatus()});
}
} else {
bt = new JRadioButton();
bt.setActionCommand(String.valueOf(f.getID()));
resultCount++;
listTableModel.addRow(new Object[]{f.getID(), f.getDate(), f.getUser().getfName() + f.getUser().getlName(),
f.getTimeSlot().toString(), f.getPaxCount(),f.getPrice(), f.getStatus()});
}
}
label.setText("Found "+resultCount+(resultCount==1?" booking.":" bookings."));
table = new JTable(listTableModel){
public void tableChanged(TableModelEvent e) {
super.tableChanged(e);
repaint();
}
};
selectedBooking = new ButtonGroup();
for (int i = 0; i < resultCount; i++){
selectedBooking.add((JRadioButton) listTableModel.getValueAt(i, 5));
}
table.getColumn("Select").setCellRenderer(
new RadioButtonRenderer());
table.getColumn("Select").setCellEditor(
new RadioButtonEditor(new JCheckBox()));
//table = new JTable();
table.setBounds(6, 6, 426, 177);
System.out.println(table.toString());
//JScrollPane scroll = new JScrollPane(table);
searchResult.removeAll();
searchResult.add(table);
searchResult.revalidate();
searchResult.repaint();
//JScrollPane scroll = new JScrollPane(table);
//getContentPane().add(scroll);
//controller.createFacility(name, facility, pricePeak, priceNonPeak, cap);
//JOptionPane.showMessageDialog(panel, "Player Created","Information", JOptionPane.PLAIN_MESSAGE);
// } catch (CreateMemberException e1) {
// JOptionPane.showMessageDialog(panel, e1.getMessage(),"Information", JOptionPane.PLAIN_MESSAGE);
// }
}
}
class RadioButtonRenderer implements TableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (value == null)
return null;
return (Component) value;
}
}
private class ButtonDeactivateListener implements ActionListener{
public void actionPerformed(ActionEvent e){
int idToDeactivate = Integer.parseInt(selectedBooking.getSelection().getActionCommand());
int n = JOptionPane.showConfirmDialog(panel, "The selected Booking will be deactivated. Confirm?","Warning", JOptionPane.OK_CANCEL_OPTION);
if (n == JOptionPane.YES_OPTION) {
dp.deactivateBooking(idToDeactivate);
searchResult.removeAll();
searchResult.revalidate();
searchResult.repaint();
} else if (n == JOptionPane.NO_OPTION) {
} else {
}
}
}
class RadioButtonEditor extends DefaultCellEditor implements ItemListener {
private JRadioButton button;
public RadioButtonEditor(JCheckBox checkBox) {
super(checkBox);
}
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
if (value == null)
return null;
button = (JRadioButton) value;
button.addItemListener(this);
return (Component) value;
}
public Object getCellEditorValue() {
button.removeItemListener(this);
return button;
}
public void itemStateChanged(ItemEvent e) {
super.fireEditingStopped();
}
}
}