Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard

Diff Revisions d7fd17 ... vs 0f75b2 ... for ruralHouses/src/gui/listOfBookingRequestsGUI.java

Diff revisions: vs.
  @@ -5,6 +5,7 @@
5 5 import java.awt.event.ActionEvent;
6 6 import java.awt.event.ActionListener;
7 7 import java.util.Enumeration;
8 + import java.util.LinkedList;
8 9 import java.util.Vector;
9 10
10 11 import javax.swing.JButton;
  @@ -16,10 +17,10 @@
16 17 import javax.swing.border.EmptyBorder;
17 18 import javax.swing.table.DefaultTableModel;
18 19
19 - import businessLogic.AdminManager;
20 - import businessLogic.HouseManager;
21 - import businessLogic.HouseManagerInterface;
22 - import domain.Administrator;
20 + import businessLogic.BookingManager;
21 + import domain.Booking;
22 + import domain.Offer;
23 + import domain.Owner;
23 24 import domain.RuralHouse;
24 25
25 26 public class listOfBookingRequestsGUI extends JFrame {
  @@ -30,16 +31,19 @@
30 31 private static final long serialVersionUID = 1L;
31 32 private JPanel contentPane;
32 33 private JTable table;
34 + private Owner own;
35 + private BookingManager bookM = new BookingManager();
33 36 private DefaultTableModel tableModel;
34 - private AdminManager am = new AdminManager();
35 - private Vector<RuralHouse> houses;
36 - /**
37 + private Vector<Booking> bookings = new Vector<Booking>();
38 +
39 + /**
37 40 * Create the frame.
38 41 */
39 - public listOfBookingRequestsGUI() {
40 - setTitle("Adding requests");
42 + public listOfBookingRequestsGUI(Owner own) {
43 + setTitle("Adding requests");
44 + this.own = own;
41 45 try {
42 - this.houses= am.getAdditionRequests();
46 +
43 47 init();
44 48 } catch (Exception e) {
45 49 e.printStackTrace();
  @@ -52,80 +56,69 @@
52 56 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
53 57 setContentPane(contentPane);
54 58 contentPane.setLayout(null);
55 -
59 +
60 + this.bookings= this.bookM.getAllBookings(own);
56 61 JLabel lblNewLabel = new JLabel();
57 62 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
58 63 lblNewLabel.setBounds(23, 41, 536, 33);
59 64 contentPane.add(lblNewLabel);
60 - if (houses.isEmpty())
61 - lblNewLabel.setText("There are not houses to be added");
65 + if (bookings.isEmpty())
66 + lblNewLabel
67 + .setText("There are not bookings to be confirmed or denied");
62 68 else
63 - lblNewLabel.setText("List of houses to be added:");
69 + lblNewLabel.setText("List of bookings:");
64 70 JScrollPane scrollPane = new JScrollPane();
65 71 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
66 72 scrollPane.setBounds(23, 113, 536, 271);
67 73 contentPane.add(scrollPane);
68 74
69 75 table = new JTable() {
70 - private static final long serialVersionUID = 1L;
76 + private static final long serialVersionUID = 1L;
71 77
72 - public boolean isCellEditable(int row, int column) {
73 - return false;
74 - };
75 - };
78 + public boolean isCellEditable(int row, int column) {
79 + return false;
80 + };
81 + };
76 82 scrollPane.setViewportView(table);
77 83 tableModel = new DefaultTableModel(null, new String[] {
78 - "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
79 - "Livings" });
80 -
81 - //Maybe there is a better way to avoid interaction.
82 - //table.setEnabled(false);
84 + "Booking Number", "Is paid", "Booking Date", "Telephone",
85 + "Offer" });
86 +
87 + // Maybe there is a better way to avoid interaction.
88 + // table.setEnabled(false);
83 89 table.setModel(tableModel);
84 -
85 - JButton btnNewButton = new JButton("Confirm Addition");
90 +
91 + JButton btnNewButton = new JButton("Confirm Booking");
86 92 btnNewButton.addActionListener(new ActionListener() {
87 93 public void actionPerformed(ActionEvent e) {
88 - if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
89 - HouseManagerInterface hm = new HouseManager();
90 - RuralHouse rh = houses.get(table.getSelectedRow());
91 - //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
92 - hm.registerNewHouse(rh);
93 - am.removeHouseAdditionRequests(rh);
94 - Administrator.saveInstance();
95 - ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
96 - houses.remove(rh);
94 + if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
95 +
97 96 }
98 97 }
99 98 });
100 99 btnNewButton.setBounds(88, 396, 169, 25);
101 100 contentPane.add(btnNewButton);
102 -
103 - JButton btnDenyAddition = new JButton("Deny Addition");
101 +
102 + JButton btnDenyAddition = new JButton("Deny Booking");
104 103 btnDenyAddition.addActionListener(new ActionListener() {
105 104 public void actionPerformed(ActionEvent arg0) {
106 - if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
107 - RuralHouse rh = houses.get(table.getSelectedRow());
108 - am.removeHouseAdditionRequests(rh);
109 - Administrator.saveInstance();
110 - ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
111 - houses.remove(rh);
105 + if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
106 +
112 107 }
113 108 }
114 109 });
115 110 btnDenyAddition.setBounds(300, 396, 169, 25);
116 111 contentPane.add(btnDenyAddition);
117 - Enumeration<RuralHouse> en = houses.elements();
118 - RuralHouse rh;
119 -
112 + Enumeration<Booking> en = this.bookings.elements();
113 + Booking book;
120 114 while (en.hasMoreElements()) {
121 - rh = en.nextElement();
115 + book = en.nextElement();
122 116 Vector<Object> row = new Vector<Object>();
123 - row.add(rh.getHouseName());
124 - row.add(rh.getFeatures().getnRooms());
125 - row.add(rh.getFeatures().getnKitchens());
126 - row.add(rh.getFeatures().getnBaths());
127 - row.add(rh.getFeatures().getnParkings());
128 - row.add(rh.getFeatures().getnLivings());
117 + row.add(book.getBookNumber());
118 + row.add(book.isPaid());
119 + row.add(book.getBookDate());
120 + row.add(book.getTelephone());
121 + row.add(book.getOffer());
129 122 tableModel.addRow(row);
130 123 }
131 124