Merge branch 'master' of ssh://xp-dev.com/RRRRHHHH_Code
[RRRRHHHH_Code] / ruralHouses / src / gui / listOfRemovalRequestsGUI.java
index acad7bf..a85c246 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,24 +18,37 @@ import javax.swing.JTable;
 import javax.swing.border.EmptyBorder;
 import javax.swing.table.DefaultTableModel;
 
-import businessLogic.AdminManager;
-import businessLogic.HouseManager;
-import businessLogic.HouseManagerInterface;
+import common.AdminInterface;
+import common.HouseInterface;
+
+import configuration.___IntNames;
 import domain.RuralHouse;
 
 public class listOfRemovalRequestsGUI extends JFrame {
 
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
        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 {
-                       this.houses= am.getDeletionRequests();
+                       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();
                        init();
                } catch (Exception e) {
                        e.printStackTrace();
@@ -52,46 +67,81 @@ public class listOfRemovalRequestsGUI extends JFrame {
                lblNewLabel.setBounds(23, 41, 536, 33);
                contentPane.add(lblNewLabel);
                if (houses.isEmpty())
-                       lblNewLabel.setText("There are not houses matching your search");
+                       lblNewLabel.setText("There are not houses to be deleted");
                else
-                       lblNewLabel.setText("List of houses that match your search:");
+                       lblNewLabel.setText("List of houses to be deleted:");
                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;
+                       private static final long serialVersionUID = 1L;
 
-               public boolean isCellEditable(int row, int column) {                
-                       return false;               
-               };
-           };
+                       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);
+               tableModel = new DefaultTableModel(null, new String[] { "House Name",
+                               "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" });
+
                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();
+                               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());
-                                       //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());
+
+                                       try {
+                                               hm.removeHouse(rh, rh.getOwner());
+                                               am.removeHouseDeletionRequests(rh);
+                                               am.saveInstance();
+                                       } catch (RemoteException e1) {
+                                               e1.printStackTrace();
+                                       }
+                                       ((DefaultTableModel) table.getModel()).removeRow(houses
+                                                       .indexOf(rh));
                                        houses.remove(rh);
-                                       am.removeHouseDeletionRequests(rh);
+
                                }
                        }
                });
-               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>();