Merged the two branches, DB separated
[RRRRHHHH_Code] / ruralHouses / src / gui / QueryAvailabilityGUI2.java
index 40cfe1c..6f4358e 100644 (file)
@@ -12,6 +12,8 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
 import java.sql.Date;
 import java.text.DateFormat;
 import java.util.Calendar;
@@ -32,17 +34,17 @@ import javax.swing.JRadioButton;
 import javax.swing.JTextField;
 import javax.swing.SwingConstants;
 
-import businessLogic.HouseManager;
-
 import com.toedter.calendar.JCalendar;
+import common.HouseInterface;
 
+import configuration.___IntNames;
 import domain.Districs;
 import domain.RuralHouse;
 
 public class QueryAvailabilityGUI2 extends JFrame {
        private static final long serialVersionUID = 1L;
 
-       private JComboBox jComboBox1;
+       private JComboBox<String> jComboBox1;
        private JLabel jLabel2 = new JLabel();
        private JTextField jTextField1 = new JTextField();
        private JLabel jLabel3 = new JLabel();
@@ -75,12 +77,20 @@ public class QueryAvailabilityGUI2 extends JFrame {
        private final JTextField nBaths = new JTextField();
        private final JLabel lblParkings = new JLabel("Parking slots:");
        private final JTextField nParkings = new JTextField();
-       private HouseManager houseMan = new HouseManager();
+       private HouseInterface houseMan = null;
        private final JLabel lblNumberOfLivings = new JLabel("Number of Livings:");
        private final JTextField nLivings = new JTextField();
        private final JLabel feedback = new JLabel("");
 
        public QueryAvailabilityGUI2() {
+               
+               try {
+                       houseMan =  (HouseInterface) Naming
+                                       .lookup(___IntNames.HouseManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
                nLivings.setText("0");
                nLivings.setColumns(10);
                nParkings.setText("0");
@@ -99,7 +109,7 @@ public class QueryAvailabilityGUI2 extends JFrame {
                this.setSize(new Dimension(550, 500));
                this.setTitle("Query Availability");
 
-               jComboBox1 = new JComboBox(new DefaultComboBoxModel(
+               jComboBox1 = new JComboBox<String>(new DefaultComboBoxModel<String>(
                                Districs.longNames()));
                jComboBox1.setEnabled(false);
                jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
@@ -286,16 +296,22 @@ public class QueryAvailabilityGUI2 extends JFrame {
 
        private void jButton1_actionPerformed(ActionEvent e) {
                if (this.district.isSelected()) {
-                       Vector<RuralHouse> houses = houseMan.getHouses(null, jComboBox1
-                                       .getSelectedItem().toString(), Integer.parseInt(nBedrooms
-                                       .getText()), Integer.parseInt(nKitchens.getText()), Integer
-                                       .parseInt(nBaths.getText()), Integer.parseInt(nParkings
-                                       .getText()), Integer.parseInt(nLivings.getText()));
+                       Vector<RuralHouse> houses = null;
+                       try {
+                               houses = houseMan.getHouses(null, null, jComboBox1
+                                               .getSelectedItem().toString(), Integer.parseInt(nBedrooms
+                                               .getText()), Integer.parseInt(nKitchens.getText()), Integer
+                                               .parseInt(nBaths.getText()), Integer.parseInt(nParkings
+                                               .getText()), Integer.parseInt(nLivings.getText()));
+                       } catch (NumberFormatException | RemoteException e1) {
+                               // TODO Auto-generated catch block
+                               e1.printStackTrace();
+                       }
                        listOfHousesGUI list = new listOfHousesGUI(houses);
                        list.setVisible(true);
                } else if (this.ruralHouseName.isSelected()) {
                        try {
-                               RuralHouse rh = houseMan.getHouses(jTextField3.getText(), null,
+                               RuralHouse rh = houseMan.getHouses(null, jTextField3.getText(), null,
                                                0, 0, 0, 0, 0).get(0);
                                // The next instruction creates a java.sql.Date object from the
                                // date selected in the JCalendar object