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;
26 import configuration.___IntNames;
27 import domain.Booking;
30 public class listOfBookingRequestsGUI extends JFrame {
35 private static final long serialVersionUID = 1L;
36 private JPanel contentPane;
39 private BookingInterface bookM = null;
40 private DefaultTableModel tableModel;
41 private Vector<Booking> bookings = new Vector<Booking>();
46 public listOfBookingRequestsGUI(Offer of) {
47 setTitle("Adding requests");
53 } catch (Exception e) {
58 private void init() throws Exception {
59 setBounds(100, 100, 600, 500);
60 contentPane = new JPanel();
61 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
62 setContentPane(contentPane);
63 contentPane.setLayout(null);
65 BookingInterface bm = null;
68 bm = (BookingInterface) Naming
69 .lookup(___IntNames.BookingManager);
71 } catch (Exception e1) {
72 System.out.println("Error accessing remote authentication: "
76 this.bookings = bm.getOffersbookings(this.off);
77 } catch (RemoteException e1) {
81 JLabel lblNewLabel = new JLabel();
82 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
83 lblNewLabel.setBounds(23, 41, 536, 33);
84 contentPane.add(lblNewLabel);
85 JScrollPane scrollPane = new JScrollPane();
86 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
87 scrollPane.setBounds(23, 113, 536, 271);
88 contentPane.add(scrollPane);
90 table = new JTable() {
91 private static final long serialVersionUID = 1L;
93 public boolean isCellEditable(int row, int column) {
97 scrollPane.setViewportView(table);
98 tableModel = new DefaultTableModel(null,
99 new String[] { "Booking Number", "Booking Date", "Name",
100 "E-mail", "Telephone" });
102 table.setModel(tableModel);
104 JButton btnNewButton = new JButton("Confirm Booking");
105 btnNewButton.addActionListener(new ActionListener() {
106 public void actionPerformed(ActionEvent e) {
108 bookM = (BookingInterface) Naming
109 .lookup(___IntNames.BookingManager);
110 } catch (Exception e1) {
112 .println("Error accessing remote authentication: "
115 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
116 if (table.getRowCount() != 0
117 && table.getSelectedRow() != -1) {
118 Booking book = bookings.get(table.getSelectedRow());
120 bookM.acceptBooking(book);
121 } catch (RemoteException e1) {
122 e1.printStackTrace();
124 contentPane.setVisible(false);
131 btnNewButton.setBounds(33, 396, 169, 25);
132 contentPane.add(btnNewButton);
134 JButton btnDenyAddition = new JButton("Deny Booking");
135 btnDenyAddition.addActionListener(new ActionListener() {
136 public void actionPerformed(ActionEvent arg0) {
138 bookM = (BookingInterface) Naming
139 .lookup(___IntNames.BookingManager);
140 } catch (Exception e1) {
142 .println("Error accessing remote authentication: "
145 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
146 Booking book = bookings.get(table.getSelectedRow());
148 bookM.denyBooking(book);
149 } catch (RemoteException e) {
152 ((DefaultTableModel) table.getModel()).removeRow(table
154 bookings.remove(book);
159 if (bookings.isEmpty())
161 .setText("There are not bookings to be confirmed or denied");
163 lblNewLabel.setText("List of bookings:");
164 if (this.bookings.get(0).getOffer().isBooked()) {
165 btnDenyAddition.setEnabled(false);
166 btnNewButton.setEnabled(false);
170 btnDenyAddition.setBounds(390, 395, 169, 25);
171 contentPane.add(btnDenyAddition);
173 Enumeration<Booking> en = this.bookings.elements();
175 while (en.hasMoreElements()) {
176 book = en.nextElement();
177 Vector<Object> row = new Vector<Object>();
178 row.add(book.getBookNumber());
179 row.add(book.getBookDate());
180 row.add(book.getClient().getName());
181 row.add(book.getClient().getMailAccount());
182 row.add(book.getClient().getTelephone());
183 tableModel.addRow(row);
185 table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
189 private static final long serialVersionUID = 1L;
192 public Component getTableCellRendererComponent(JTable table,
193 Object value, boolean isSelected, boolean hasFocus,
196 super.getTableCellRendererComponent(table, value, isSelected,
199 if (!bookings.get(row).getOffer().isBooked()) {
200 setBackground(Color.RED);
201 setForeground(Color.BLACK);
203 setBackground(Color.GREEN);
204 setForeground(Color.BLACK);