|
@@ -29,12 +29,14 @@ |
29 |
29 |
|
private DefaultTableModel tableModel; |
30 |
30 |
|
private AdminManager am = new AdminManager(); |
31 |
31 |
|
private Vector<RuralHouse> houses; |
32 |
|
- |
/** |
|
32 |
+ |
|
|
33 |
+ |
/** |
33 |
34 |
|
* Create the frame. |
34 |
35 |
|
*/ |
35 |
36 |
|
public listOfRemovalRequestsGUI() { |
|
37 |
+ |
setTitle("Deleting requests"); |
36 |
38 |
|
try { |
37 |
|
- |
this.houses= am.getDeletionRequests(); |
|
39 |
+ |
this.houses = am.getDeletionRequests(); |
38 |
40 |
|
init(); |
39 |
41 |
|
} catch (Exception e) { |
40 |
42 |
|
e.printStackTrace(); |
|
@@ -53,42 +55,41 @@ |
53 |
55 |
|
lblNewLabel.setBounds(23, 41, 536, 33); |
54 |
56 |
|
contentPane.add(lblNewLabel); |
55 |
57 |
|
if (houses.isEmpty()) |
56 |
|
- |
lblNewLabel.setText("There are not houses matching your search"); |
|
58 |
+ |
lblNewLabel.setText("There are not houses to be deleted"); |
57 |
59 |
|
else |
58 |
|
- |
lblNewLabel.setText("List of houses that match your search:"); |
|
60 |
+ |
lblNewLabel.setText("List of houses to be deleted:"); |
59 |
61 |
|
JScrollPane scrollPane = new JScrollPane(); |
60 |
62 |
|
scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); |
61 |
63 |
|
scrollPane.setBounds(23, 113, 536, 271); |
62 |
64 |
|
contentPane.add(scrollPane); |
63 |
65 |
|
|
64 |
66 |
|
table = new JTable() { |
65 |
|
- |
private static final long serialVersionUID = 1L; |
|
67 |
+ |
private static final long serialVersionUID = 1L; |
66 |
68 |
|
|
67 |
|
- |
public boolean isCellEditable(int row, int column) { |
68 |
|
- |
return false; |
69 |
|
- |
}; |
70 |
|
- |
}; |
|
69 |
+ |
public boolean isCellEditable(int row, int column) { |
|
70 |
+ |
return false; |
|
71 |
+ |
}; |
|
72 |
+ |
}; |
71 |
73 |
|
scrollPane.setViewportView(table); |
72 |
|
- |
tableModel = new DefaultTableModel(null, new String[] { |
73 |
|
- |
"House Name", "Bedrooms", "Kitchens", "Baths", "Parkings", |
74 |
|
- |
"Livings" }); |
75 |
|
- |
|
76 |
|
- |
//Maybe there is a better way to avoid interaction. |
77 |
|
- |
//table.setEnabled(false); |
|
74 |
+ |
tableModel = new DefaultTableModel(null, new String[] { "House Name", |
|
75 |
+ |
"Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" }); |
|
76 |
+ |
|
78 |
77 |
|
table.setModel(tableModel); |
79 |
78 |
|
Enumeration<RuralHouse> en = houses.elements(); |
80 |
79 |
|
RuralHouse rh; |
81 |
80 |
|
JButton btnNewButton = new JButton("Confirm Deletion"); |
82 |
81 |
|
btnNewButton.addActionListener(new ActionListener() { |
83 |
82 |
|
public void actionPerformed(ActionEvent e) { |
84 |
|
- |
if (table.getRowCount()!=0) { |
|
83 |
+ |
if (table.getRowCount() != 0) { |
85 |
84 |
|
HouseManagerInterface hm = new HouseManager(); |
86 |
85 |
|
RuralHouse rh = houses.get(table.getSelectedRow()); |
87 |
|
- |
//TODO when the house is not added show a warning to the user. Method below returns a boolean stating that. |
88 |
|
- |
hm.removeHouse(rh, rh.getOwner()); |
89 |
|
- |
houses.remove(rh); |
90 |
|
- |
am.removeHouseDeletionRequests(rh); |
91 |
|
- |
Administrator.saveInstance(); |
|
86 |
+ |
((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); |
|
87 |
+ |
hm.removeHouse(rh, rh.getOwner()); |
|
88 |
+ |
houses.remove(rh); |
|
89 |
+ |
am.removeHouseDeletionRequests(rh); |
|
90 |
+ |
Administrator.saveInstance(); |
|
91 |
+ |
|
|
92 |
+ |
|
92 |
93 |
|
} |
93 |
94 |
|
} |
94 |
95 |
|
}); |