4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.util.Enumeration;
8 import java.util.LinkedList;
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 businessLogic.BookingManager;
21 import domain.Booking;
24 import domain.RuralHouse;
26 public class listOfOffers extends JFrame {
31 private static final long serialVersionUID = 1L;
32 private JPanel contentPane;
35 private BookingManager bookM = new BookingManager();
36 private DefaultTableModel tableModel;
37 private Vector<Offer> offers = new Vector<Offer>();
42 public listOfOffers(Owner own) {
43 setTitle("Adding requests");
48 } catch (Exception e) {
53 private void init() throws Exception {
54 setBounds(100, 100, 600, 450);
55 contentPane = new JPanel();
56 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
57 setContentPane(contentPane);
58 contentPane.setLayout(null);
60 this.offers = this.owner.getAllOffers();
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 (this.offers.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[] { "Offer #",
84 "FirstDay", "LastDay", "Price" });
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) {
98 btnNewButton.setBounds(88, 396, 169, 25);
99 contentPane.add(btnNewButton);
101 JButton btnDenyAddition = new JButton("Deny Booking");
102 btnDenyAddition.addActionListener(new ActionListener() {
103 public void actionPerformed(ActionEvent arg0) {
104 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
109 btnDenyAddition.setBounds(300, 396, 169, 25);
110 contentPane.add(btnDenyAddition);
111 Enumeration<Offer> rhs = this.offers.elements();
112 while (rhs.hasMoreElements()) {
113 Offer of = rhs.nextElement();
114 Vector<Object> row = new Vector<Object>();
115 row.add(of.getOfferNumber());
116 row.add(of.getFirstDay());
117 row.add(of.getLastDay());
118 row.add(of.getPrice());
119 tableModel.addRow(row);