cleaning
[RRRRHHHH_Code] / ruralHouses / src / gui / listOfRemovalRequestsGUI.java
index 53cb7e6..62daded 100644 (file)
@@ -4,6 +4,8 @@ import java.awt.Font;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
 import java.util.Enumeration;
 import java.util.Vector;
 
@@ -16,10 +18,10 @@ import javax.swing.JTable;
 import javax.swing.border.EmptyBorder;
 import javax.swing.table.DefaultTableModel;
 
-import businessLogic.AdminManager;
-import businessLogic.HouseManager;
-import businessLogic.HouseManagerInterface;
-import domain.Administrator;
+import common.AdminInterface;
+import common.HouseInterface;
+
+import configuration.___IntNames;
 import domain.RuralHouse;
 
 public class listOfRemovalRequestsGUI extends JFrame {
@@ -31,13 +33,20 @@ public class listOfRemovalRequestsGUI extends JFrame {
        private JPanel contentPane;
        private JTable table;
        private DefaultTableModel tableModel;
-       private AdminManager am = new AdminManager();
+       private AdminInterface am = null;
        private Vector<RuralHouse> houses;
 
        /**
         * Create the frame.
         */
        public listOfRemovalRequestsGUI() {
+               try {
+                       am = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
                setTitle("Deleting requests");
                try {
                        this.houses = am.getDeletionRequests();
@@ -84,21 +93,57 @@ public class listOfRemovalRequestsGUI extends JFrame {
                JButton btnNewButton = new JButton("Confirm Deletion");
                btnNewButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
-                               if (table.getRowCount() != 0) {
-                                       HouseManagerInterface hm = new HouseManager();
+                               if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+                                       HouseInterface hm= null;
+                                       try {
+                                               hm = (HouseInterface) Naming
+                                                               .lookup(___IntNames.HouseManager);
+                                       } catch (Exception e1) {
+                                               System.out.println("Error accessing remote authentication: "
+                                                               + e1.toString());
+                                       }
                                        RuralHouse rh = houses.get(table.getSelectedRow());
                                        ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
-                                               hm.removeHouse(rh, rh.getOwner());
+                                               try {
+                                                       hm.removeHouse(rh, rh.getOwner());
+                                                       am.removeHouseDeletionRequests(rh);
+                                                       am.saveInstance();
+                                               } catch (RemoteException e1) {
+                                                       // TODO Auto-generated catch block
+                                                       e1.printStackTrace();
+                                               }
                                                houses.remove(rh);
-                                               am.removeHouseDeletionRequests(rh);
-                                               Administrator.saveInstance();
+                                               
 
                                        
                                }
                        }
                });
-               btnNewButton.setBounds(301, 394, 169, 25);
+               btnNewButton.setBounds(90, 396, 169, 25);
                contentPane.add(btnNewButton);
+               
+               JButton btnNewButton_1 = new JButton("Deny Deletion");
+               btnNewButton_1.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+                                       RuralHouse rh = houses.get(table.getSelectedRow());
+                                       ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
+                                               houses.remove(rh);
+                                               try {
+                                                       am.removeHouseDeletionRequests(rh);
+                                                       am.saveInstance();
+                                               } catch (RemoteException e1) {
+                                                       // TODO Auto-generated catch block
+                                                       e1.printStackTrace();
+                                               }
+                                               
+
+                                       
+                               }
+                       }
+               });
+               btnNewButton_1.setBounds(291, 396, 169, 25);
+               contentPane.add(btnNewButton_1);
                while (en.hasMoreElements()) {
                        rh = en.nextElement();
                        Vector<Object> row = new Vector<Object>();