9ca453719ce7c9920aa0fafa1a51fba31ce69657
[RRRRHHHH_Code] / ruralHouses / src / gui / listOfOffers.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.util.Enumeration;
8 import java.util.LinkedList;
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 businessLogic.BookingManager;
21 import domain.Booking;
22 import domain.Offer;
23 import domain.Owner;
24 import domain.RuralHouse;
25
26 public class listOfOffers extends JFrame {
27
28         /**
29          * 
30          */
31         private static final long serialVersionUID = 1L;
32         private JPanel contentPane;
33         private JTable table;
34         private Owner owner;
35         private BookingManager bookM = new BookingManager();
36         private DefaultTableModel tableModel;
37         private Vector<Offer> offers = new Vector<Offer>();
38
39         /**
40          * Create the frame.
41          */
42         public listOfOffers(Owner own) {
43                 setTitle("Adding requests");
44                 this.owner = own;
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, 450);
55                 contentPane = new JPanel();
56                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
57                 setContentPane(contentPane);
58                 contentPane.setLayout(null);
59
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())
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[] { "Offer #",
84                                 "FirstDay", "LastDay", "Price" });
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
95                                 }
96                         }
97                 });
98                 btnNewButton.setBounds(88, 396, 169, 25);
99                 contentPane.add(btnNewButton);
100
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) {
105
106                                 }
107                         }
108                 });
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);
120
121                 }
122
123         }
124 }