4 import java.awt.Component;
6 import java.awt.Rectangle;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.rmi.Naming;
10 import java.rmi.RemoteException;
11 import java.util.Enumeration;
12 import java.util.Vector;
14 import javax.swing.JButton;
15 import javax.swing.JFrame;
16 import javax.swing.JLabel;
17 import javax.swing.JPanel;
18 import javax.swing.JScrollPane;
19 import javax.swing.JTable;
20 import javax.swing.border.EmptyBorder;
21 import javax.swing.table.DefaultTableCellRenderer;
22 import javax.swing.table.DefaultTableModel;
24 import common.BookingInterface;
25 import common.HouseInterface;
26 import common.OfferInterface;
27 import configuration.___IntNames;
28 import domain.Booking;
31 public class listOfBookingRequestsGUI extends JFrame {
36 private static final long serialVersionUID = 1L;
37 private JPanel contentPane;
40 private BookingInterface bookM = null;
41 private DefaultTableModel tableModel;
42 private Vector<Booking> bookings = new Vector<Booking>();
47 public listOfBookingRequestsGUI(Offer of) {
48 setTitle("Adding requests");
54 } catch (Exception e) {
59 private void init() throws Exception {
60 setBounds(100, 100, 600, 500);
61 contentPane = new JPanel();
62 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
63 setContentPane(contentPane);
64 contentPane.setLayout(null);
66 BookingInterface bm = null;
69 bm = (BookingInterface) Naming
70 .lookup(___IntNames.BookingManager);
72 } catch (Exception e1) {
73 System.out.println("Error accessing remote authentication: "
77 this.bookings = bm.getOffersbookings(this.off);
78 } catch (RemoteException e1) {
82 JLabel lblNewLabel = new JLabel();
83 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
84 lblNewLabel.setBounds(23, 41, 536, 33);
85 contentPane.add(lblNewLabel);
86 JScrollPane scrollPane = new JScrollPane();
87 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
88 scrollPane.setBounds(23, 113, 536, 271);
89 contentPane.add(scrollPane);
91 table = new JTable() {
92 private static final long serialVersionUID = 1L;
94 public boolean isCellEditable(int row, int column) {
98 scrollPane.setViewportView(table);
99 tableModel = new DefaultTableModel(null,
100 new String[] { "Booking Number", "Booking Date", "Name",
101 "E-mail", "Telephone" });
103 table.setModel(tableModel);
105 JButton btnNewButton = new JButton("Confirm Booking");
106 btnNewButton.addActionListener(new ActionListener() {
107 public void actionPerformed(ActionEvent e) {
109 bookM = (BookingInterface) Naming
110 .lookup(___IntNames.BookingManager);
111 } catch (Exception e1) {
113 .println("Error accessing remote authentication: "
116 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
117 if (table.getRowCount() != 0
118 && table.getSelectedRow() != -1) {
119 Booking book = bookings.get(table.getSelectedRow());
121 bookM.acceptBooking(book);
122 } catch (RemoteException e1) {
123 e1.printStackTrace();
125 contentPane.setVisible(false);
132 btnNewButton.setBounds(33, 396, 169, 25);
133 contentPane.add(btnNewButton);
135 JButton btnDenyAddition = new JButton("Deny Booking");
136 btnDenyAddition.addActionListener(new ActionListener() {
137 public void actionPerformed(ActionEvent arg0) {
139 bookM = (BookingInterface) Naming
140 .lookup(___IntNames.BookingManager);
141 } catch (Exception e1) {
143 .println("Error accessing remote authentication: "
146 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
147 Booking book = bookings.get(table.getSelectedRow());
149 bookM.denyBooking(book);
150 } catch (RemoteException e) {
153 ((DefaultTableModel) table.getModel()).removeRow(table
155 bookings.remove(book);
160 if (bookings.isEmpty())
162 .setText("There are not bookings to be confirmed or denied");
164 lblNewLabel.setText("List of bookings:");
165 if (this.bookings.get(0).getOffer().isBooked()) {
166 btnDenyAddition.setEnabled(false);
167 btnNewButton.setEnabled(false);
171 btnDenyAddition.setBounds(390, 395, 169, 25);
172 contentPane.add(btnDenyAddition);
174 Enumeration<Booking> en = this.bookings.elements();
176 while (en.hasMoreElements()) {
177 book = en.nextElement();
178 Vector<Object> row = new Vector<Object>();
179 row.add(book.getBookNumber());
180 row.add(book.getBookDate());
181 row.add(book.getClient().getName());
182 row.add(book.getClient().getMailAccount());
183 row.add(book.getClient().getTelephone());
184 tableModel.addRow(row);
186 table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
190 private static final long serialVersionUID = 1L;
193 public Component getTableCellRendererComponent(JTable table,
194 Object value, boolean isSelected, boolean hasFocus,
197 super.getTableCellRendererComponent(table, value, isSelected,
200 if (!bookings.get(row).getOffer().isBooked()) {
201 setBackground(Color.RED);
202 setForeground(Color.BLACK);
204 setBackground(Color.GREEN);
205 setForeground(Color.BLACK);