3 import java.awt.BorderLayout;
4 import java.awt.EventQueue;
8 import javax.swing.JFrame;
9 import javax.swing.JPanel;
10 import javax.swing.border.EmptyBorder;
11 import javax.swing.JLabel;
15 import javax.swing.JTextField;
16 import javax.swing.JScrollPane;
18 import java.awt.Rectangle;
20 import javax.swing.JTable;
21 import javax.swing.table.DefaultTableModel;
23 import java.awt.Component;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
27 import java.util.Enumeration;
28 import java.util.LinkedList;
29 import java.util.Vector;
31 import javax.swing.Box;
32 import javax.swing.JButton;
34 import businessLogic.AdminManager;
35 import businessLogic.HouseManager;
36 import businessLogic.HouseManagerInterface;
38 import java.awt.event.ActionListener;
39 import java.awt.event.ActionEvent;
41 public class listOfAdditionRequestsGUI extends JFrame {
43 private JPanel contentPane;
45 private DefaultTableModel tableModel;
46 private AdminManager am = new AdminManager();
47 private Vector<RuralHouse> houses;
51 public listOfAdditionRequestsGUI() {
53 this.houses= am.getAdditionRequests();
55 } catch (Exception e) {
60 private void init() throws Exception {
61 setBounds(100, 100, 600, 450);
62 contentPane = new JPanel();
63 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
64 setContentPane(contentPane);
65 contentPane.setLayout(null);
67 JLabel lblNewLabel = new JLabel();
68 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
69 lblNewLabel.setBounds(23, 41, 536, 33);
70 contentPane.add(lblNewLabel);
72 lblNewLabel.setText("There are not houses matching your search");
74 lblNewLabel.setText("List of houses that match your search:");
75 JScrollPane scrollPane = new JScrollPane();
76 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
77 scrollPane.setBounds(23, 113, 536, 271);
78 contentPane.add(scrollPane);
80 table = new JTable() {
81 private static final long serialVersionUID = 1L;
83 public boolean isCellEditable(int row, int column) {
87 scrollPane.setViewportView(table);
88 tableModel = new DefaultTableModel(null, new String[] {
89 "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
92 //Maybe there is a better way to avoid interaction.
93 //table.setEnabled(false);
94 table.setModel(tableModel);
96 JButton btnNewButton = new JButton("Confirm Addition");
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.registerNewHouse(rh);
105 am.removeHouseAdditionRequests(rh);
109 btnNewButton.setBounds(301, 394, 169, 25);
110 contentPane.add(btnNewButton);
111 Enumeration<RuralHouse> en = houses.elements();
114 while (en.hasMoreElements()) {
115 rh = en.nextElement();
116 Vector<Object> row = new Vector<Object>();
117 row.add(rh.getHouseName());
118 row.add(rh.getFeatures().getnRooms());
119 row.add(rh.getFeatures().getnKitchens());
120 row.add(rh.getFeatures().getnBaths());
121 row.add(rh.getFeatures().getnParkings());
122 row.add(rh.getFeatures().getnLivings());
123 tableModel.addRow(row);