Villatripas de arriba districs added and the option of searching houses with diferent...
authorcamjan <jcampos004@ikasle.ehu.es>
Wed, 25 Mar 2015 16:43:35 +0000 (17:43 +0100)
committercamjan <jcampos004@ikasle.ehu.es>
Wed, 25 Mar 2015 16:43:35 +0000 (17:43 +0100)
ruralHouses/src/businessLogic/HouseManager.java
ruralHouses/src/businessLogic/HouseManagerInterface.java
ruralHouses/src/dataAccess/DB4oManager.java
ruralHouses/src/domain/Districs.java [new file with mode: 0644]
ruralHouses/src/domain/HouseFeatures.java
ruralHouses/src/gui/QueryAvailabilityGUI2.java
ruralHouses/src/gui/listOfHousesGUI.java

index ba1aed7..70e8985 100644 (file)
@@ -58,6 +58,11 @@ public class HouseManager implements HouseManagerInterface {
                
                return this.dbMngr.getRuralHousesByTown(town);
        }
+       
+       public Vector<RuralHouse> getHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv) {
+               
+               return this.dbMngr.getRuralHouses(town, nBed, nKit, nBath, nPark, nLiv);
+       }
 
 
 
index 35670d9..321b82e 100644 (file)
@@ -23,6 +23,7 @@ public interface HouseManagerInterface {
 
        public void removeHouse(RuralHouse rh, Owner owner);
 
+       public Vector<RuralHouse> getHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv) ;
 
        /**
         * @param district
index eff779f..5dabd6f 100644 (file)
@@ -18,6 +18,7 @@ import com.db4o.cs.config.ClientConfiguration;
 import configuration.ConfigXML;
 import domain.Account;
 import domain.Booking;
+import domain.HouseFeatures;
 import domain.Offer;
 //import dataModel.Offer;
 import domain.Owner;
@@ -36,6 +37,7 @@ public class DB4oManager {
        private static DB4oManager theDB4oManager = null;
 
        private static DB4oManagerAux theDB4oManagerAux;
+       
        static ConfigXML c;
 
        private DB4oManager() throws Exception {
@@ -478,5 +480,28 @@ public class DB4oManager {
                
                
                
+       }
+       
+       public Vector<RuralHouse> getRuralHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv){
+               HouseFeatures fea = new HouseFeatures(nBed,nKit,nBath,nLiv,nPark);
+               RuralHouse rh = new RuralHouse(null,null,null,town,fea);
+               if (c.isDatabaseLocal() == false)
+                       openSDB();
+               else
+                       openDB();
+               
+               try{
+                       ObjectSet<RuralHouse> result = db.queryByExample(rh);
+                       Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
+                       while(result.hasNext())
+                               ruralHouses.add(result.next());
+                       db.close();
+                       return ruralHouses;
+               } catch (NullPointerException e){
+                       return null;
+               }
+               
+               
+               
        }
 }
diff --git a/ruralHouses/src/domain/Districs.java b/ruralHouses/src/domain/Districs.java
new file mode 100644 (file)
index 0000000..fa2fee5
--- /dev/null
@@ -0,0 +1,25 @@
+package domain;
+
+public enum Districs {
+       BEA("Beatriz"), GUA("Guazate"), VEG("Vegas"), FAR("Farallón"), CED("Cedro"), MOT(
+                       "Monte LLano"), RIN("Rincón"), PUE("Pueblo"), QUA("Quebrada Arriba"), QEB(
+                       "Quebrada Abajo"), TOI("Toita"), MAB("Matón Abajo"), MAA(
+                       "Matón Arriba"), PIE("Piedras"), PAV("Pasto Viejo"), PEA(
+                       "PedroAvila"), SUM("Sumido"), LAP("Lapa"), CER("Cercadillo"), JAJ(
+                       "JájomeAlto"), CUL("CulebrasAbajo");
+
+       private final String longName;
+
+       Districs(String longName) {
+               this.longName = longName;
+       }
+
+       public static String[] longNames() {
+               String[] result = new String[Districs.values().length];
+               for (Districs d : Districs.values()) {
+                       result[d.ordinal()] = d.longName;
+               }
+               return result;
+
+       }
+}
index c26de8a..2327608 100644 (file)
@@ -11,10 +11,50 @@ public class HouseFeatures {
        public HouseFeatures(int nRooms, int nKitchens, int nBaths, int nLivings,
                        int nParkings) {
                super();
+               this.setnRooms(nRooms);
+               this.setnKitchens(nKitchens);
+               this.setnBaths(nBaths);
+               this.setnLivings(nLivings);
+               this.setnParkings(nParkings);
+       }
+
+       public int getnRooms() {
+               return nRooms;
+       }
+
+       public void setnRooms(int nRooms) {
                this.nRooms = nRooms;
+       }
+
+       public int getnKitchens() {
+               return nKitchens;
+       }
+
+       public void setnKitchens(int nKitchens) {
                this.nKitchens = nKitchens;
+       }
+
+       public int getnBaths() {
+               return nBaths;
+       }
+
+       public void setnBaths(int nBaths) {
                this.nBaths = nBaths;
+       }
+
+       public int getnLivings() {
+               return nLivings;
+       }
+
+       public void setnLivings(int nLivings) {
                this.nLivings = nLivings;
+       }
+
+       public int getnParkings() {
+               return nParkings;
+       }
+
+       public void setnParkings(int nParkings) {
                this.nParkings = nParkings;
        }
 
index d95dcfe..a12ad16 100644 (file)
@@ -7,6 +7,7 @@ import java.util.*;
 
 import javax.swing.*;
 
+
 import java.awt.*;
 import java.awt.event.*;
 
@@ -15,6 +16,7 @@ import businessLogic.OfferManager;
 
 import com.toedter.calendar.JCalendar;
 
+import domain.Districs;
 import domain.Offer;
 import domain.RuralHouse;
 import exceptions.OverlappingOfferExists;
@@ -42,7 +44,7 @@ public class QueryAvailabilityGUI2 extends JFrame {
        private final JLabel lblNewLabel = new JLabel("");
        private final JRadioButton ruralHouseName = new JRadioButton(
                        "Use RuralHouse name");
-       private final   JRadioButton district = new JRadioButton("Use district name");
+       private final JRadioButton district = new JRadioButton("Use district name");
        private final ButtonGroup buttonGroup = new ButtonGroup();
        private final JMenuBar menuBar = new JMenuBar();
        private final JMenu mnMoreOptions = new JMenu("Search Options");
@@ -57,10 +59,15 @@ public class QueryAvailabilityGUI2 extends JFrame {
        private final JLabel lblParkings = new JLabel("Parking slots:");
        private final JTextField nParkings = new JTextField();
        private HouseManager houseMan = new HouseManager();
+       private final JLabel lblNumberOfLivings = new JLabel("Number of Livings:");
+       private final JTextField nLivings = new JTextField();
 
        public QueryAvailabilityGUI2() {
-               nParkings.setText("");
+               nLivings.setText("0");
+               nLivings.setColumns(10);
+               nParkings.setText("0");
                nParkings.setColumns(10);
+               nBaths.setText("0");
                nBaths.setColumns(10);
                try {
                        jbInit();
@@ -72,10 +79,10 @@ public class QueryAvailabilityGUI2 extends JFrame {
        private void jbInit() throws Exception {
                this.getContentPane().setLayout(null);
                this.setSize(new Dimension(550, 500));
-               this.setTitle("Set availability");
+               this.setTitle("Query Availability");
 
-               //TODO here we should add the districts of villatripas this is just for testing purposes
-               jComboBox1 = new JComboBox(this.houseMan.getAllRuralHouses());
+               jComboBox1 = new JComboBox(new DefaultComboBoxModel(
+                               Districs.longNames()));
                jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
                jLabel2.setText("First day :");
                jLabel2.setBounds(new Rectangle(20, 134, 85, 25));
@@ -152,33 +159,39 @@ public class QueryAvailabilityGUI2 extends JFrame {
                        }
                });
                popupMenu.setBounds(75, 125, 58, 16);
-               
+
                addPopup(getContentPane(), popupMenu);
                lblExtraFeatures.setHorizontalAlignment(SwingConstants.CENTER);
-               
+
                popupMenu.add(lblExtraFeatures);
-               
+
                popupMenu.add(lblNewLabel_1);
-               
+
                nBedrooms = new JTextField();
+               nBedrooms.setText("0");
                popupMenu.add(nBedrooms);
                nBedrooms.setColumns(10);
-               
+
                JLabel lblNumberOfKitchens = new JLabel("Number of kitchens:");
                popupMenu.add(lblNumberOfKitchens);
-               
+
                nKitchens = new JTextField();
+               nKitchens.setText("0");
                popupMenu.add(nKitchens);
                nKitchens.setColumns(10);
-               
+
                popupMenu.add(lblNumberOfBaths);
-               
+
                popupMenu.add(nBaths);
-               
+
                popupMenu.add(lblParkings);
-               
+
                popupMenu.add(nParkings);
 
+               popupMenu.add(lblNumberOfLivings);
+
+               popupMenu.add(nLivings);
+
                this.getContentPane().add(jCalendar2, null);
                this.getContentPane().add(jCalendar1, null);
                this.getContentPane().add(jLabel5, null);
@@ -195,7 +208,8 @@ public class QueryAvailabilityGUI2 extends JFrame {
 
                getContentPane().add(lblNewLabel);
 
-               district.setSelected(true);;
+               district.setSelected(true);
+               ;
                district.setBounds(20, 69, 128, 20);
                getContentPane().add(district);
                buttonGroup.add(ruralHouseName);
@@ -212,7 +226,7 @@ public class QueryAvailabilityGUI2 extends JFrame {
                                }
                        }
                });
-               
+
                ruralHouseName.addItemListener(new ItemListener() {
                        @Override
                        public void itemStateChanged(ItemEvent e) {
@@ -225,35 +239,43 @@ public class QueryAvailabilityGUI2 extends JFrame {
                        }
                });
                getContentPane().add(ruralHouseName);
-               
+
                JLabel lblNewLabel_2 = new JLabel("District name:");
                lblNewLabel_2.setBounds(20, 30, 85, 17);
                getContentPane().add(lblNewLabel_2);
-               
+
                setJMenuBar(menuBar);
-               
+
                menuBar.add(mnMoreOptions);
                PopUpM.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
-                               popupMenu.show(QueryAvailabilityGUI2.this,popupMenu.getX(), popupMenu.getY());
+                               popupMenu.show(QueryAvailabilityGUI2.this, popupMenu.getX(),
+                                               popupMenu.getY());
                        }
                });
-               
+
                mnMoreOptions.add(PopUpM);
        }
 
        private void jButton1_actionPerformed(ActionEvent e) {
-               if(this.district.isSelected()){
-                       //show list of houses GUI
-               }
-               else if(this.ruralHouseName.isSelected()){
-                       //show features of specific house
+               if (this.district.isSelected()) {
+                       Vector<RuralHouse> houses = houseMan.getHouses(jComboBox1
+                                       .getSelectedItem().toString(), Integer.parseInt(nBedrooms
+                                       .getText()), Integer.parseInt(nKitchens.getText()), Integer
+                                       .parseInt(nBaths.getText()), Integer.parseInt(nParkings
+                                       .getText()), Integer.parseInt(nLivings.getText()));
+                       listOfHousesGUI list = new listOfHousesGUI(houses);
+                       list.setVisible(true);
+               } else if (this.ruralHouseName.isSelected()) {
+                       // show features of specific house
+                       // TODO
                }
        }
 
        private void jButton2_actionPerformed(ActionEvent e) {
                this.setVisible(false);
        }
+
        private static void addPopup(Component component, final JPopupMenu popup) {
                component.addMouseListener(new MouseAdapter() {
                        public void mousePressed(MouseEvent e) {
@@ -261,11 +283,13 @@ public class QueryAvailabilityGUI2 extends JFrame {
                                        showMenu(e);
                                }
                        }
+
                        public void mouseReleased(MouseEvent e) {
                                if (e.isPopupTrigger()) {
                                        showMenu(e);
                                }
                        }
+
                        private void showMenu(MouseEvent e) {
                                popup.show(e.getComponent(), e.getX(), e.getY());
                        }
index 726f738..d610030 100644 (file)
@@ -3,6 +3,8 @@ package gui;
 import java.awt.BorderLayout;
 import java.awt.EventQueue;
 
+import domain.*;
+
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.border.EmptyBorder;
@@ -19,6 +21,10 @@ import javax.swing.JTable;
 import javax.swing.table.DefaultTableModel;
 
 import java.awt.Component;
+import java.sql.Date;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.Vector;
 
 import javax.swing.Box;
 
@@ -27,31 +33,31 @@ public class listOfHousesGUI extends JFrame {
        private JPanel contentPane;
        private JTextField textField;
        private JTable table;
+       private DefaultTableModel tableModel;
 
        /**
         * Create the frame.
         */
-       public listOfHousesGUI() {
+       public listOfHousesGUI(Vector<RuralHouse> houses) {
                try {
-                       init();
+                       init(houses);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
-       
-       private void init() throws Exception
-         {
+
+       private void init(Vector<RuralHouse> houses) throws Exception {
                setBounds(100, 100, 600, 450);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
                contentPane.setLayout(null);
-               
+
                JLabel lblNewLabel = new JLabel("List of available houses in:");
                lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
                lblNewLabel.setBounds(23, 41, 325, 33);
                contentPane.add(lblNewLabel);
-               
+
                textField = new JTextField();
                textField.setEnabled(false);
                textField.setEditable(false);
@@ -59,20 +65,38 @@ public class listOfHousesGUI extends JFrame {
                textField.setBounds(373, 41, 152, 33);
                contentPane.add(textField);
                textField.setColumns(10);
-               
+               if (houses.isEmpty())
+                       textField.setText("No houses Matching");
+               else
+                       textField.setText(houses.get(0).getTown());
                JScrollPane scrollPane = new JScrollPane();
                scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
                scrollPane.setBounds(23, 113, 536, 271);
                contentPane.add(scrollPane);
-               
+
                table = new JTable();
                scrollPane.setViewportView(table);
-               table.setModel(new DefaultTableModel(
-                       new Object[][] {
-                       },
-                       new String[] {
-                               "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings"
-                       }
-               ));
-         }
+               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);
+               table.setModel(tableModel);
+               Enumeration<RuralHouse> en = houses.elements();
+               RuralHouse rh;
+
+               while (en.hasMoreElements()) {
+                       rh = en.nextElement();
+                       Vector<Object> row = new Vector<Object>();
+                       row.add(rh.getHouseName());
+                       row.add(rh.getFeatures().getnRooms());
+                       row.add(rh.getFeatures().getnKitchens());
+                       row.add(rh.getFeatures().getnBaths());
+                       row.add(rh.getFeatures().getnParkings());
+                       row.add(rh.getFeatures().getnLivings());
+                       System.out.println(rh.getFeatures().getnLivings());
+                       tableModel.addRow(row);
+               }
+
+       }
 }