Separate DB almost fixed
authorcamjan <jcampos004@ikasle.ehu.es>
Thu, 21 May 2015 10:41:31 +0000 (12:41 +0200)
committercamjan <jcampos004@ikasle.ehu.es>
Thu, 21 May 2015 10:41:31 +0000 (12:41 +0200)
ruralHouses client/src/gui/DeleteOfferGUI.java
ruralHouses client/src/gui/HouseFeaturesGUI.java
ruralHouses client/src/gui/ModifyOfferGUI.java
ruralHouses client/src/gui/listOfBookingRequestsGUI.java
ruralHouses client/src/gui/listOfOffers.java
ruralHouses/src/businessLogic/HouseManager.java
ruralHouses/src/dataAccess/DB4oManager.java
ruralHousesDB/src/dataAccess/DB4oManager.java

index d9f5ab8..2f9dda7 100644 (file)
@@ -43,8 +43,7 @@ public class DeleteOfferGUI extends JFrame {
         */
        public DeleteOfferGUI(Owner o) {
                try {
         */
        public DeleteOfferGUI(Owner o) {
                try {
-                       hm = (HouseInterface) Naming
-                                       .lookup(___IntNames.HouseManager);
+                       hm = (HouseInterface) Naming.lookup(___IntNames.HouseManager);
                } catch (Exception e1) {
                        System.out.println("Error accessing remote authentication: "
                                        + e1.toString());
                } catch (Exception e1) {
                        System.out.println("Error accessing remote authentication: "
                                        + e1.toString());
@@ -53,7 +52,7 @@ public class DeleteOfferGUI extends JFrame {
                        Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0);
                } catch (RemoteException e1) {
                        e1.printStackTrace();
                        Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0);
                } catch (RemoteException e1) {
                        e1.printStackTrace();
-               }       
+               }
                setBounds(100, 100, 450, 300);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setBounds(100, 100, 450, 300);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
@@ -64,7 +63,8 @@ public class DeleteOfferGUI extends JFrame {
 
                comboBox_1 = new JComboBox<Offer>();
                comboBox_1.setBounds(101, 76, 314, 20);
 
                comboBox_1 = new JComboBox<Offer>();
                comboBox_1.setBounds(101, 76, 314, 20);
-               Vector<Offer> vo = ((RuralHouse) comboBox.getSelectedItem()).getAllOffers();
+               Vector<Offer> vo = ((RuralHouse) comboBox.getSelectedItem())
+                               .getAllOffers();
                comboBox_1.removeAllItems();
                for (Offer of : vo) {
                        comboBox_1.addItem(of);
                comboBox_1.removeAllItems();
                for (Offer of : vo) {
                        comboBox_1.addItem(of);
@@ -82,7 +82,8 @@ public class DeleteOfferGUI extends JFrame {
 
                        @Override
                        public void itemStateChanged(ItemEvent arg0) {
 
                        @Override
                        public void itemStateChanged(ItemEvent arg0) {
-                               Vector<Offer> vo = ((RuralHouse) comboBox.getSelectedItem()).getAllOffers();
+                               Vector<Offer> vo = ((RuralHouse) comboBox.getSelectedItem())
+                                               .getAllOffers();
                                comboBox_1.removeAllItems();
                                for (Offer of : vo) {
                                        comboBox_1.addItem(of);
                                comboBox_1.removeAllItems();
                                for (Offer of : vo) {
                                        comboBox_1.addItem(of);
@@ -92,7 +93,31 @@ public class DeleteOfferGUI extends JFrame {
                        }
 
                });
                        }
 
                });
+               comboBox_1.addItemListener(new ItemListener() {
+
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+                               if (((Offer) comboBox_1.getSelectedItem()).isBooked()) {
+                                       feedback.setText("This offer is already booked.");
+                                       btnDelete.setEnabled(false);
+                               }
+
+                       }
+
+               });
+               comboBox_1.addItemListener(new ItemListener() {
 
 
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+                               if (comboBox_1.getSelectedItem() != null) {
+                                       if (!((Offer) comboBox_1.getSelectedItem()).isBooked()) {
+                                               feedback.setText("");
+                                               btnDelete.setEnabled(true);
+                                       }
+                               }
+                       }
+
+               });
                rdbtnIAmSure.addItemListener(new ItemListener() {
 
                        @Override
                rdbtnIAmSure.addItemListener(new ItemListener() {
 
                        @Override
@@ -119,11 +144,14 @@ public class DeleteOfferGUI extends JFrame {
                contentPane.add(lblOffer);
                contentPane.add(comboBox);
                contentPane.add(comboBox_1);
                contentPane.add(lblOffer);
                contentPane.add(comboBox);
                contentPane.add(comboBox_1);
-               
+
                feedback = new JLabel("");
                feedback.setBounds(140, 178, 202, 23);
                contentPane.add(feedback);
                feedback = new JLabel("");
                feedback.setBounds(140, 178, 202, 23);
                contentPane.add(feedback);
-
+               if (((Offer) comboBox_1.getSelectedItem()).isBooked()) {
+                       feedback.setText("This offer is already booked.");
+                       btnDelete.setEnabled(false);
+               }
                btnDelete.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
                                actionListenerButton(arg0);
                btnDelete.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
                                actionListenerButton(arg0);
@@ -138,13 +166,12 @@ public class DeleteOfferGUI extends JFrame {
                Offer toDel = (Offer) comboBox_1.getSelectedItem();
                OfferInterface oM = null;
                try {
                Offer toDel = (Offer) comboBox_1.getSelectedItem();
                OfferInterface oM = null;
                try {
-                       oM = (OfferInterface) Naming
-                                       .lookup(___IntNames.OfferManager);
+                       oM = (OfferInterface) Naming.lookup(___IntNames.OfferManager);
                } catch (Exception e1) {
                        System.out.println("Error accessing remote authentication: "
                                        + e1.toString());
                }
                } catch (Exception e1) {
                        System.out.println("Error accessing remote authentication: "
                                        + e1.toString());
                }
-               
+
                try {
                        oM.deleteOffer((RuralHouse) comboBox.getSelectedItem(), toDel);
                        comboBox_1.removeItem(toDel);
                try {
                        oM.deleteOffer((RuralHouse) comboBox.getSelectedItem(), toDel);
                        comboBox_1.removeItem(toDel);
@@ -154,6 +181,6 @@ public class DeleteOfferGUI extends JFrame {
                        feedback.setText("Imposible to delete the offer");
                        e1.printStackTrace();
                }
                        feedback.setText("Imposible to delete the offer");
                        e1.printStackTrace();
                }
-               
+
        }
 }
        }
 }
index 39d0bc9..c4bb654 100644 (file)
@@ -301,6 +301,7 @@ public class HouseFeaturesGUI extends JFrame {
                        Vector<Booking> book = null;
                        try {
                                if (table.getRowCount() != 0) {
                        Vector<Booking> book = null;
                        try {
                                if (table.getRowCount() != 0) {
+                                       row = table.getSelectedRow();
                                        Client cl = new Client(nameField.getText(),
                                                        mailField.getText(), telIn.getText());
                                        book = bookingM.createBooking(rh, offers.get(row)
                                        Client cl = new Client(nameField.getText(),
                                                        mailField.getText(), telIn.getText());
                                        book = bookingM.createBooking(rh, offers.get(row)
index 1f082d0..73230bb 100644 (file)
@@ -26,9 +26,9 @@ import javax.swing.JLabel;
 import javax.swing.JTextField;
 
 import com.toedter.calendar.JCalendar;
 import javax.swing.JTextField;
 
 import com.toedter.calendar.JCalendar;
+
 import common.HouseInterface;
 import common.OfferInterface;
 import common.HouseInterface;
 import common.OfferInterface;
-
 import configuration.___IntNames;
 import domain.Offer;
 import domain.Owner;
 import configuration.___IntNames;
 import domain.Offer;
 import domain.Owner;
@@ -252,7 +252,28 @@ public class ModifyOfferGUI extends JFrame {
                                }
                        }
                });
                                }
                        }
                });
-
+               if(((Offer) comboBox_o.getSelectedItem()).isBooked()){
+                       jLabel5.setText("This offer is already booked.");
+                       jButton1.setEnabled(false);                                     
+               }
+               comboBox_o.addItemListener(new ItemListener() {
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+                               if(((Offer) comboBox_o.getSelectedItem()).isBooked()){
+                                       jLabel5.setText("This offer is already booked.");
+                                       jButton1.setEnabled(false);                                     
+                               }
+                       }
+               });
+               comboBox_o.addItemListener(new ItemListener() {
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+                               if(!((Offer) comboBox_o.getSelectedItem()).isBooked()){
+                                       jLabel5.setText("");;
+                                       jButton1.setEnabled(true);                                      
+                               }
+                       }
+               });
                this.getContentPane().add(jCalendar2, null);
                this.getContentPane().add(jCalendar1, null);
                this.getContentPane().add(jLabel5, null);
                this.getContentPane().add(jCalendar2, null);
                this.getContentPane().add(jCalendar1, null);
                this.getContentPane().add(jLabel5, null);
index aab2736..025c1fe 100644 (file)
@@ -113,19 +113,11 @@ public class listOfBookingRequestsGUI extends JFrame {
                                                } catch (RemoteException e1) {
                                                        e1.printStackTrace();
                                                }
                                                } catch (RemoteException e1) {
                                                        e1.printStackTrace();
                                                }
-                                               int rows = table.getModel().getRowCount(); 
-                                               for(int i = rows - 1; i >=0; i--){
+                                               int rows = table.getModel().getRowCount();
+                                               for (int i = rows - 1; i >= 0; i--) {
                                                        ((DefaultTableModel) table.getModel()).removeRow(i);
                                                }
                                                        ((DefaultTableModel) table.getModel()).removeRow(i);
                                                }
-                                               Vector<Object> row = new Vector<Object>();
-                                               row.add(book.getBookNumber());
-                                               row.add(book.getBookDate());
-                                               row.add(book.getClient().getName());
-                                               row.add(book.getClient().getMailAccount());
-                                               row.add(book.getClient().getTelephone());
-                                               tableModel.addRow(row);
-                                               btnNewButton.setEnabled(false);
-                                               btnDenyAddition.setEnabled(false);
+
                                        }
 
                                }
                                        }
 
                                }
index 4d065bb..3674c59 100644 (file)
@@ -21,7 +21,6 @@ import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.DefaultTableModel;
 
 import common.HouseInterface;
 import javax.swing.table.DefaultTableModel;
 
 import common.HouseInterface;
-import common.OfferInterface;
 
 import configuration.___IntNames;
 import domain.Offer;
 
 import configuration.___IntNames;
 import domain.Offer;
@@ -111,7 +110,6 @@ public class listOfOffers extends JFrame {
                        @Override
                        public void mouseClicked(MouseEvent arg0) {
                                int row = table.getSelectedRow();
                        @Override
                        public void mouseClicked(MouseEvent arg0) {
                                int row = table.getSelectedRow();
-                               System.out.println(row);
                                listOfBookingRequestsGUI feat = new listOfBookingRequestsGUI(offers.get(row));
                                feat.setVisible(true);
                        }
                                listOfBookingRequestsGUI feat = new listOfBookingRequestsGUI(offers.get(row));
                                feat.setVisible(true);
                        }
index 0233811..c2b624c 100644 (file)
@@ -59,6 +59,8 @@ public class HouseManager extends UnicastRemoteObject implements HouseInterface
 
                return this.dbMngr.getRuralHouses( ow, name ,town, nBed, nKit, nBath, nPark, nLiv);
        }
 
                return this.dbMngr.getRuralHouses( ow, name ,town, nBed, nKit, nBath, nPark, nLiv);
        }
+       
+       
 
 
 }
 
 
 }
index 403c916..a424473 100644 (file)
@@ -516,7 +516,14 @@ public class DB4oManager {
        public Vector<RuralHouse> getRuralHouses(Owner ow, String name,
                        String town, int nBed, int nKit, int nBath, int nPark, int nLiv) {
                HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark);
        public Vector<RuralHouse> getRuralHouses(Owner ow, String name,
                        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(name, ow, null, town, fea);
+               RuralHouse rh;
+               if (ow != null) {
+                       Owner own = new Owner(ow.getName(), ow.getBankAccount(),
+                                       ow.getMailAccount());
+                       rh = new RuralHouse(name, own, null, town, fea);
+               }else{
+                       rh = new RuralHouse(name, ow, null, town, fea);
+               }
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
                if (c.isDatabaseLocal() == false)
                        openSDB();
                else
@@ -632,7 +639,9 @@ public class DB4oManager {
 
                try {
                        Offer of = (Offer) db.queryByExample(
 
                try {
                        Offer of = (Offer) db.queryByExample(
-                                       new Offer(0, o.getRuralHouse(), null, null, 0)).get(0);
+                                       new Offer(o.getOfferNumber(), new RuralHouse(o
+                                                       .getRuralHouse().getHouseName(), null, null, null,
+                                                       null), null, null, 0)).get(0);
                        Booking proto = new Booking(0, of, null, null);
                        ObjectSet<Booking> result = db.queryByExample(proto);
                        return new Vector<Booking>(result);
                        Booking proto = new Booking(0, of, null, null);
                        ObjectSet<Booking> result = db.queryByExample(proto);
                        return new Vector<Booking>(result);
index 1c6bdba..ea6bc69 100644 (file)
@@ -4,6 +4,8 @@ package dataAccess;
 public class DB4oManager {
        
 
 public class DB4oManager {
        
 
+       private static DB4oManagerAux theDB4oManagerAux;
+       
        class DB4oManagerAux {
                int bookingNumber;
                int offerNumber;
        class DB4oManagerAux {
                int bookingNumber;
                int offerNumber;