Started creating the booking interface for the owners.
[RRRRHHHH_Code] / ruralHouses / src / gui / listOfRemovalRequestsGUI.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.Vector;
9
10 import javax.swing.JButton;
11 import javax.swing.JFrame;
12 import javax.swing.JLabel;
13 import javax.swing.JPanel;
14 import javax.swing.JScrollPane;
15 import javax.swing.JTable;
16 import javax.swing.border.EmptyBorder;
17 import javax.swing.table.DefaultTableModel;
18
19 import businessLogic.AdminManager;
20 import businessLogic.HouseManager;
21 import businessLogic.HouseManagerInterface;
22 import domain.Administrator;
23 import domain.RuralHouse;
24
25 public class listOfRemovalRequestsGUI extends JFrame {
26
27         /**
28          * 
29          */
30         private static final long serialVersionUID = 1L;
31         private JPanel contentPane;
32         private JTable table;
33         private DefaultTableModel tableModel;
34         private AdminManager am = new AdminManager();
35         private Vector<RuralHouse> houses;
36
37         /**
38          * Create the frame.
39          */
40         public listOfRemovalRequestsGUI() {
41                 setTitle("Deleting requests");
42                 try {
43                         this.houses = am.getDeletionRequests();
44                         init();
45                 } catch (Exception e) {
46                         e.printStackTrace();
47                 }
48         }
49
50         private void init() throws Exception {
51                 setBounds(100, 100, 600, 450);
52                 contentPane = new JPanel();
53                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
54                 setContentPane(contentPane);
55                 contentPane.setLayout(null);
56
57                 JLabel lblNewLabel = new JLabel();
58                 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
59                 lblNewLabel.setBounds(23, 41, 536, 33);
60                 contentPane.add(lblNewLabel);
61                 if (houses.isEmpty())
62                         lblNewLabel.setText("There are not houses to be deleted");
63                 else
64                         lblNewLabel.setText("List of houses to be deleted:");
65                 JScrollPane scrollPane = new JScrollPane();
66                 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
67                 scrollPane.setBounds(23, 113, 536, 271);
68                 contentPane.add(scrollPane);
69
70                 table = new JTable() {
71                         private static final long serialVersionUID = 1L;
72
73                         public boolean isCellEditable(int row, int column) {
74                                 return false;
75                         };
76                 };
77                 scrollPane.setViewportView(table);
78                 tableModel = new DefaultTableModel(null, new String[] { "House Name",
79                                 "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" });
80
81                 table.setModel(tableModel);
82                 Enumeration<RuralHouse> en = houses.elements();
83                 RuralHouse rh;
84                 JButton btnNewButton = new JButton("Confirm Deletion");
85                 btnNewButton.addActionListener(new ActionListener() {
86                         public void actionPerformed(ActionEvent e) {
87                                 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
88                                         HouseManagerInterface hm = new HouseManager();
89                                         RuralHouse rh = houses.get(table.getSelectedRow());
90                                         ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
91                                                 hm.removeHouse(rh, rh.getOwner());
92                                                 houses.remove(rh);
93                                                 am.removeHouseDeletionRequests(rh);
94                                                 Administrator.saveInstance();
95
96                                         
97                                 }
98                         }
99                 });
100                 btnNewButton.setBounds(90, 396, 169, 25);
101                 contentPane.add(btnNewButton);
102                 
103                 JButton btnNewButton_1 = new JButton("Deny Deletion");
104                 btnNewButton_1.addActionListener(new ActionListener() {
105                         public void actionPerformed(ActionEvent e) {
106                                 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
107                                         RuralHouse rh = houses.get(table.getSelectedRow());
108                                         ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
109                                                 houses.remove(rh);
110                                                 am.removeHouseDeletionRequests(rh);
111                                                 Administrator.saveInstance();
112
113                                         
114                                 }
115                         }
116                 });
117                 btnNewButton_1.setBounds(291, 396, 169, 25);
118                 contentPane.add(btnNewButton_1);
119                 while (en.hasMoreElements()) {
120                         rh = en.nextElement();
121                         Vector<Object> row = new Vector<Object>();
122                         row.add(rh.getHouseName());
123                         row.add(rh.getFeatures().getnRooms());
124                         row.add(rh.getFeatures().getnKitchens());
125                         row.add(rh.getFeatures().getnBaths());
126                         row.add(rh.getFeatures().getnParkings());
127                         row.add(rh.getFeatures().getnLivings());
128                         tableModel.addRow(row);
129                 }
130
131         }
132 }