4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.rmi.Naming;
8 import java.rmi.RemoteException;
9 import java.util.Enumeration;
10 import java.util.Vector;
12 import javax.swing.JButton;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
16 import javax.swing.JScrollPane;
17 import javax.swing.JTable;
18 import javax.swing.border.EmptyBorder;
19 import javax.swing.table.DefaultTableModel;
21 import common.AdminInterface;
22 import common.HouseInterface;
24 import configuration.___IntNames;
25 import domain.RuralHouse;
27 public class listOfRemovalRequestsGUI extends JFrame {
32 private static final long serialVersionUID = 1L;
33 private JPanel contentPane;
35 private DefaultTableModel tableModel;
36 private AdminInterface am = null;
37 private Vector<RuralHouse> houses;
42 public listOfRemovalRequestsGUI() {
44 am = (AdminInterface) Naming
45 .lookup(___IntNames.AdminManager);
46 } catch (Exception e1) {
47 System.out.println("Error accessing remote authentication: "
50 setTitle("Deleting requests");
52 this.houses = am.getDeletionRequests();
54 } catch (Exception e) {
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);
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);
71 lblNewLabel.setText("There are not houses to be deleted");
73 lblNewLabel.setText("List of houses to be deleted:");
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);
79 table = new JTable() {
80 private static final long serialVersionUID = 1L;
82 public boolean isCellEditable(int row, int column) {
86 scrollPane.setViewportView(table);
87 tableModel = new DefaultTableModel(null, new String[] { "House Name",
88 "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" });
90 table.setModel(tableModel);
91 Enumeration<RuralHouse> en = houses.elements();
93 JButton btnNewButton = new JButton("Confirm Deletion");
94 btnNewButton.addActionListener(new ActionListener() {
95 public void actionPerformed(ActionEvent e) {
96 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
97 HouseInterface hm= null;
99 hm = (HouseInterface) Naming
100 .lookup(___IntNames.HouseManager);
101 } catch (Exception e1) {
102 System.out.println("Error accessing remote authentication: "
105 RuralHouse rh = houses.get(table.getSelectedRow());
106 ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
108 hm.removeHouse(rh, rh.getOwner());
109 am.removeHouseDeletionRequests(rh);
111 } catch (RemoteException e1) {
112 // TODO Auto-generated catch block
113 e1.printStackTrace();
122 btnNewButton.setBounds(90, 396, 169, 25);
123 contentPane.add(btnNewButton);
125 JButton btnNewButton_1 = new JButton("Deny Deletion");
126 btnNewButton_1.addActionListener(new ActionListener() {
127 public void actionPerformed(ActionEvent e) {
128 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
129 RuralHouse rh = houses.get(table.getSelectedRow());
130 ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
133 am.removeHouseDeletionRequests(rh);
135 } catch (RemoteException e1) {
136 // TODO Auto-generated catch block
137 e1.printStackTrace();
145 btnNewButton_1.setBounds(291, 396, 169, 25);
146 contentPane.add(btnNewButton_1);
147 while (en.hasMoreElements()) {
148 rh = en.nextElement();
149 Vector<Object> row = new Vector<Object>();
150 row.add(rh.getHouseName());
151 row.add(rh.getFeatures().getnRooms());
152 row.add(rh.getFeatures().getnKitchens());
153 row.add(rh.getFeatures().getnBaths());
154 row.add(rh.getFeatures().getnParkings());
155 row.add(rh.getFeatures().getnLivings());
156 tableModel.addRow(row);