1df8f2a69c6ef8c2e08b2287af2586891286827e
[RRRRHHHH_Code] / ruralHouses client / src / gui / listOfBookingRequestsGUI.java
1 package gui;
2
3 import java.awt.Font;
4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.rmi.RemoteException;
8 import java.util.Enumeration;
9 import java.util.Vector;
10
11 import javax.swing.JButton;
12 import javax.swing.JFrame;
13 import javax.swing.JLabel;
14 import javax.swing.JPanel;
15 import javax.swing.JScrollPane;
16 import javax.swing.JTable;
17 import javax.swing.border.EmptyBorder;
18 import javax.swing.table.DefaultTableModel;
19
20 import common.BookingInterface;
21
22 import domain.Booking;
23 import domain.Offer;
24
25 public class listOfBookingRequestsGUI extends JFrame {
26
27         /**
28          * 
29          */
30         private static final long serialVersionUID = 1L;
31         private JPanel contentPane;
32         private JTable table;
33         private Offer off;
34         private BookingInterface bookM =null;
35         private DefaultTableModel tableModel;
36         private Vector<Booking> bookings = new Vector<Booking>();
37
38         /**
39          * Create the frame.
40          */
41         public listOfBookingRequestsGUI(Offer of) {
42                 setTitle("Adding requests");
43                 this.off = of;
44
45                 try {
46
47                         init();
48                 } catch (Exception e) {
49                         e.printStackTrace();
50                 }
51         }
52
53         private void init() throws Exception {
54                 setBounds(100, 100, 600, 500);
55                 contentPane = new JPanel();
56                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
57                 setContentPane(contentPane);
58                 contentPane.setLayout(null);
59                 
60                 this.bookings= this.off.getBookings();
61                 JLabel lblNewLabel = new JLabel();
62                 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
63                 lblNewLabel.setBounds(23, 41, 536, 33);
64                 contentPane.add(lblNewLabel);
65                 if (bookings.isEmpty())
66                         lblNewLabel
67                                         .setText("There are not bookings to be confirmed or denied");
68                 else
69                         lblNewLabel.setText("List of bookings:");
70                 JScrollPane scrollPane = new JScrollPane();
71                 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
72                 scrollPane.setBounds(23, 113, 536, 271);
73                 contentPane.add(scrollPane);
74
75                 table = new JTable() {
76                         private static final long serialVersionUID = 1L;
77
78                         public boolean isCellEditable(int row, int column) {
79                                 return false;
80                         };
81                 };
82                 scrollPane.setViewportView(table);
83                 tableModel = new DefaultTableModel(null, new String[] {
84                                 "Booking Number", "Is paid", "Booking Date","Name","E-mail", "Telephone" });
85
86                 // Maybe there is a better way to avoid interaction.
87                 // table.setEnabled(false);
88                 table.setModel(tableModel);
89
90                 JButton btnNewButton = new JButton("Confirm Booking");
91                 btnNewButton.addActionListener(new ActionListener() {
92                         public void actionPerformed(ActionEvent e) {
93                                 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
94                                         if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
95                                                 Booking book = bookings.get(table.getSelectedRow());
96                                                 try {
97                                                         bookM.acceptBooking(book);
98                                                 } catch (RemoteException e1) {
99                                                         e1.printStackTrace();
100                                                 }
101                                         }
102
103                                 }
104                         }
105                 });
106                 btnNewButton.setBounds(33, 396, 169, 25);
107                 contentPane.add(btnNewButton);
108
109                 JButton btnDenyAddition = new JButton("Deny Booking");
110                 btnDenyAddition.addActionListener(new ActionListener() {
111                         public void actionPerformed(ActionEvent arg0) {
112                                 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
113                                         Booking book = bookings.get(table.getSelectedRow());
114                                         try {
115                                                 bookM.removeDenyBooking(book);
116                                         } catch (RemoteException e) {
117                                                 e.printStackTrace();
118                                         }
119
120                                 }
121                         }
122                 });
123                 btnDenyAddition.setBounds(390, 395, 169, 25);
124                 contentPane.add(btnDenyAddition);
125                 
126                 JButton btnSetAsPaid = new JButton("Set as paid");
127                 btnSetAsPaid.setBounds(239, 395, 89, 23);
128                 btnSetAsPaid.addActionListener(new ActionListener() {
129                         public void actionPerformed(ActionEvent arg0) {
130                                 
131                         }
132                 });
133                 contentPane.add(btnSetAsPaid);
134                 Enumeration<Booking> en = this.bookings.elements();
135                 Booking book;
136                 while (en.hasMoreElements()) {
137                         book = en.nextElement();
138                         Vector<Object> row = new Vector<Object>();
139                         row.add(book.getBookNumber());
140                         row.add(book.isPaid());
141                         row.add(book.getBookDate());
142                         row.add(book.getClient().getName());
143                         row.add(book.getClient().getMailAccount());
144                         row.add(book.getClient().getTelephone());
145                         tableModel.addRow(row);
146                 }
147
148         }
149 }