Merged the two branches, DB separated
[RRRRHHHH_Code] / ruralHouses / src / gui / RequestNewHouseGUI.java
index ba4eca9..e22a4f2 100644 (file)
@@ -3,6 +3,8 @@ package gui;
 import java.awt.Color;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
 
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.GroupLayout;
@@ -17,7 +19,9 @@ import javax.swing.LayoutStyle.ComponentPlacement;
 import javax.swing.SwingConstants;
 import javax.swing.border.EmptyBorder;
 
-import businessLogic.AdminManager;
+import common.AdminInterface;
+
+import configuration.___IntNames;
 import domain.Districs;
 import domain.HouseFeatures;
 import domain.Owner;
@@ -48,7 +52,7 @@ public class RequestNewHouseGUI extends JFrame {
        private JLabel lblBaths;
        private JTextField baths_f;
        private JButton btnRegister;
-       private AdminManager am;
+       private AdminInterface am = null;
        private JComboBox<String> comboBox;
 
 
@@ -58,7 +62,13 @@ public class RequestNewHouseGUI extends JFrame {
        public RequestNewHouseGUI(Owner o) {
                comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
                                Districs.longNames()));
-               am  = new AdminManager();
+               try {
+                       am = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
                this.setTitle("New House");
                setBackground(Color.WHITE);
                this.getContentPane().setLayout(null);
@@ -123,21 +133,27 @@ public class RequestNewHouseGUI extends JFrame {
                                        //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
                                        rh = new RuralHouse(Code_f.getText(),
                                                                owner, description_f.getText(),
-                                                               (String) comboBox.getSelectedItem() ,new HouseFeatures(Integer.parseInt(rooms_f.getText()),
+                                                               (String) comboBox.getSelectedItem()new HouseFeatures(Integer.parseInt(rooms_f.getText()),
                                                                                Integer.parseInt(kitchens_f.getText()),
                                                                                Integer.parseInt(baths_f.getText()),
                                                                                Integer.parseInt(lRooms_f.getText()),
                                                                                Integer.parseInt(parkings_f.getText())) );
                                
                                }
-                               catch(NumberFormatException e ){
+                               catch(NumberFormatException e){
                                        e.printStackTrace();
                                }
                                
-                               if(am.addAdditionRequest(rh)){
-                                       feedback.setText("Request sended");
-                               }else{
-                                       feedback.setText("Request cannot be sended(Already added)");
+                               try {
+                                       if(am.addAdditionRequest(rh)){
+                                               am.saveInstance();
+                                               feedback.setText("Request sended");
+                                       }else{
+                                               feedback.setText("Request cannot be sended(Already added)");
+                                       }
+                               } catch (RemoteException e) {
+                                       // TODO Auto-generated catch block
+                                       e.printStackTrace();
                                }
                        }
                });