+package gui;
+
+import java.awt.BorderLayout;
+import java.awt.EventQueue;
+
+import domain.*;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+import javax.swing.JLabel;
+
+import java.awt.Font;
+
+import javax.swing.JTextField;
+import javax.swing.JScrollPane;
+
+import java.awt.Rectangle;
+
+import javax.swing.JTable;
+import javax.swing.table.DefaultTableModel;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.sql.Date;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.Vector;
+
+import javax.swing.Box;
+
+import businessLogic.AdminManager;
+import businessLogic.HouseManager;
+import businessLogic.HouseManagerInterface;
+
+public class listOfRemovalRequestsGUI extends JFrame {
+
+ private JPanel contentPane;
+ private JTable table;
+ private DefaultTableModel tableModel;
+ private AdminManager am = new AdminManager();
+ private Vector<RuralHouse> houses;
+ /**
+ * Create the frame.
+ */
+ public listOfRemovalRequestsGUI() {
+ try {
+ this.houses= am.getDeletionRequests();
+ init();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void init() throws Exception {
+ setBounds(100, 100, 600, 450);
+ contentPane = new JPanel();
+ contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+ setContentPane(contentPane);
+ contentPane.setLayout(null);
+
+ JLabel lblNewLabel = new JLabel();
+ lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+ lblNewLabel.setBounds(23, 41, 536, 33);
+ contentPane.add(lblNewLabel);
+ if (houses.isEmpty())
+ lblNewLabel.setText("There are not houses matching your search");
+ else
+ lblNewLabel.setText("List of houses that match your search:");
+ JScrollPane scrollPane = new JScrollPane();
+ scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
+ scrollPane.setBounds(23, 113, 536, 271);
+ contentPane.add(scrollPane);
+
+ table = new JTable() {
+ private static final long serialVersionUID = 1L;
+
+ public boolean isCellEditable(int row, int column) {
+ return false;
+ };
+ };
+ scrollPane.setViewportView(table);
+ tableModel = new DefaultTableModel(null, new String[] {
+ "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
+ "Livings" });
+
+ //Maybe there is a better way to avoid interaction.
+ //table.setEnabled(false);
+ table.setModel(tableModel);
+ Enumeration<RuralHouse> en = houses.elements();
+ RuralHouse rh;
+ JButton btnNewButton = new JButton("Confirm Deletion");
+ btnNewButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (table.getRowCount()!=0) {
+ HouseManagerInterface hm = new HouseManager();
+ RuralHouse rh = houses.get(table.getSelectedRow());
+ //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
+ hm.removeHouse(rh, rh.getOwner());
+ houses.remove(rh);
+ am.removeHouseDeletionRequests(rh);
+ }
+ }
+ });
+ btnNewButton.setBounds(301, 394, 169, 25);
+ contentPane.add(btnNewButton);
+ while (en.hasMoreElements()) {
+ rh = en.nextElement();
+ Vector<Object> row = new Vector<Object>();
+ row.add(rh.getHouseName());
+ row.add(rh.getFeatures().getnRooms());
+ row.add(rh.getFeatures().getnKitchens());
+ row.add(rh.getFeatures().getnBaths());
+ row.add(rh.getFeatures().getnParkings());
+ row.add(rh.getFeatures().getnLivings());
+ tableModel.addRow(row);
+ }
+
+ }
+}