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;
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;
20 import common.BookingInterface;
22 import domain.Booking;
25 public class listOfBookingRequestsGUI extends JFrame {
30 private static final long serialVersionUID = 1L;
31 private JPanel contentPane;
34 private BookingInterface bookM =null;
35 private DefaultTableModel tableModel;
36 private Vector<Booking> bookings = new Vector<Booking>();
41 public listOfBookingRequestsGUI(Offer of) {
42 setTitle("Adding requests");
48 } catch (Exception e) {
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);
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())
67 .setText("There are not bookings to be confirmed or denied");
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);
75 table = new JTable() {
76 private static final long serialVersionUID = 1L;
78 public boolean isCellEditable(int row, int column) {
82 scrollPane.setViewportView(table);
83 tableModel = new DefaultTableModel(null, new String[] {
84 "Booking Number", "Is paid", "Booking Date","Name","E-mail", "Telephone" });
86 // Maybe there is a better way to avoid interaction.
87 // table.setEnabled(false);
88 table.setModel(tableModel);
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());
97 bookM.acceptBooking(book);
98 } catch (RemoteException e1) {
106 btnNewButton.setBounds(33, 396, 169, 25);
107 contentPane.add(btnNewButton);
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());
115 bookM.removeDenyBooking(book);
116 } catch (RemoteException e) {
123 btnDenyAddition.setBounds(390, 395, 169, 25);
124 contentPane.add(btnDenyAddition);
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) {
133 contentPane.add(btnSetAsPaid);
134 Enumeration<Booking> en = this.bookings.elements();
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);