62daded5f1ea23ad5fef7d17ffcb0eb6778ec70d
[RRRRHHHH_Code] / ruralHouses client / 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.rmi.Naming;
8 import java.rmi.RemoteException;
9 import java.util.Enumeration;
10 import java.util.Vector;
11
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;
20
21 import common.AdminInterface;
22 import common.HouseInterface;
23
24 import configuration.___IntNames;
25 import domain.RuralHouse;
26
27 public class listOfRemovalRequestsGUI extends JFrame {
28
29         /**
30          * 
31          */
32         private static final long serialVersionUID = 1L;
33         private JPanel contentPane;
34         private JTable table;
35         private DefaultTableModel tableModel;
36         private AdminInterface am = null;
37         private Vector<RuralHouse> houses;
38
39         /**
40          * Create the frame.
41          */
42         public listOfRemovalRequestsGUI() {
43                 try {
44                         am = (AdminInterface) Naming
45                                         .lookup(___IntNames.AdminManager);
46                 } catch (Exception e1) {
47                         System.out.println("Error accessing remote authentication: "
48                                         + e1.toString());
49                 }
50                 setTitle("Deleting requests");
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 to be deleted");
72                 else
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);
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[] { "House Name",
88                                 "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" });
89
90                 table.setModel(tableModel);
91                 Enumeration<RuralHouse> en = houses.elements();
92                 RuralHouse rh;
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;
98                                         try {
99                                                 hm = (HouseInterface) Naming
100                                                                 .lookup(___IntNames.HouseManager);
101                                         } catch (Exception e1) {
102                                                 System.out.println("Error accessing remote authentication: "
103                                                                 + e1.toString());
104                                         }
105                                         RuralHouse rh = houses.get(table.getSelectedRow());
106                                         ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
107                                                 try {
108                                                         hm.removeHouse(rh, rh.getOwner());
109                                                         am.removeHouseDeletionRequests(rh);
110                                                         am.saveInstance();
111                                                 } catch (RemoteException e1) {
112                                                         // TODO Auto-generated catch block
113                                                         e1.printStackTrace();
114                                                 }
115                                                 houses.remove(rh);
116                                                 
117
118                                         
119                                 }
120                         }
121                 });
122                 btnNewButton.setBounds(90, 396, 169, 25);
123                 contentPane.add(btnNewButton);
124                 
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));
131                                                 houses.remove(rh);
132                                                 try {
133                                                         am.removeHouseDeletionRequests(rh);
134                                                         am.saveInstance();
135                                                 } catch (RemoteException e1) {
136                                                         // TODO Auto-generated catch block
137                                                         e1.printStackTrace();
138                                                 }
139                                                 
140
141                                         
142                                 }
143                         }
144                 });
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);
157                 }
158
159         }
160 }