Model modified so that owners now request for a new house insetion or a house removal...
[RRRRHHHH_Code] / ruralHouses / src / gui / listOfRemovalRequestsGUI.java
1 package gui;
2
3 import java.awt.BorderLayout;
4 import java.awt.EventQueue;
5
6 import domain.*;
7
8 import javax.swing.JButton;
9 import javax.swing.JFrame;
10 import javax.swing.JPanel;
11 import javax.swing.border.EmptyBorder;
12 import javax.swing.JLabel;
13
14 import java.awt.Font;
15
16 import javax.swing.JTextField;
17 import javax.swing.JScrollPane;
18
19 import java.awt.Rectangle;
20
21 import javax.swing.JTable;
22 import javax.swing.table.DefaultTableModel;
23
24 import java.awt.Component;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.MouseAdapter;
28 import java.awt.event.MouseEvent;
29 import java.sql.Date;
30 import java.util.Enumeration;
31 import java.util.LinkedList;
32 import java.util.Vector;
33
34 import javax.swing.Box;
35
36 import businessLogic.AdminManager;
37 import businessLogic.HouseManager;
38 import businessLogic.HouseManagerInterface;
39
40 public class listOfRemovalRequestsGUI extends JFrame {
41
42         private JPanel contentPane;
43         private JTable table;
44         private DefaultTableModel tableModel;
45         private AdminManager am = new AdminManager();
46         private Vector<RuralHouse> houses;
47         /**
48          * Create the frame.
49          */
50         public listOfRemovalRequestsGUI() {
51                 try {
52                         this.houses= am.getDeletionRequests();
53                         init();
54                 } catch (Exception e) {
55                         e.printStackTrace();
56                 }
57         }
58
59         private void init() throws Exception {
60                 setBounds(100, 100, 600, 450);
61                 contentPane = new JPanel();
62                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
63                 setContentPane(contentPane);
64                 contentPane.setLayout(null);
65
66                 JLabel lblNewLabel = new JLabel();
67                 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
68                 lblNewLabel.setBounds(23, 41, 536, 33);
69                 contentPane.add(lblNewLabel);
70                 if (houses.isEmpty())
71                         lblNewLabel.setText("There are not houses matching your search");
72                 else
73                         lblNewLabel.setText("List of houses that match your search:");
74                 JScrollPane scrollPane = new JScrollPane();
75                 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
76                 scrollPane.setBounds(23, 113, 536, 271);
77                 contentPane.add(scrollPane);
78
79                 table = new JTable() {
80                 private static final long serialVersionUID = 1L;
81
82                 public boolean isCellEditable(int row, int column) {                
83                         return false;               
84                 };
85             };
86                 scrollPane.setViewportView(table);
87                 tableModel = new DefaultTableModel(null, new String[] {
88                                 "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
89                                 "Livings" });
90                 
91                 //Maybe there is a better way to avoid interaction.
92                 //table.setEnabled(false);
93                 table.setModel(tableModel);
94                 Enumeration<RuralHouse> en = houses.elements();
95                 RuralHouse rh;
96                 JButton btnNewButton = new JButton("Confirm Deletion");
97                 btnNewButton.addActionListener(new ActionListener() {
98                         public void actionPerformed(ActionEvent e) {
99                                 if (table.getRowCount()!=0) {
100                                         HouseManagerInterface hm = new HouseManager();
101                                         RuralHouse rh = houses.get(table.getSelectedRow());
102                                         //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
103                                         hm.removeHouse(rh, rh.getOwner());
104                                         houses.remove(rh);
105                                         am.removeHouseDeletionRequests(rh);
106                                 }
107                         }
108                 });
109                 btnNewButton.setBounds(301, 394, 169, 25);
110                 contentPane.add(btnNewButton);
111                 while (en.hasMoreElements()) {
112                         rh = en.nextElement();
113                         Vector<Object> row = new Vector<Object>();
114                         row.add(rh.getHouseName());
115                         row.add(rh.getFeatures().getnRooms());
116                         row.add(rh.getFeatures().getnKitchens());
117                         row.add(rh.getFeatures().getnBaths());
118                         row.add(rh.getFeatures().getnParkings());
119                         row.add(rh.getFeatures().getnLivings());
120                         tableModel.addRow(row);
121                 }
122
123         }
124 }