From 5761bc38726d885d816d437f153fdb076fd5ed54 Mon Sep 17 00:00:00 2001 From: camjan Date: Wed, 15 Apr 2015 17:27:07 +0200 Subject: [PATCH] Bugs when deleting houses and offers fixed and GUI's adapated for empty cases --- .../src/businessLogic/HouseManager.java | 55 +--- .../businessLogic/HouseManagerInterface.java | 18 +- .../src/businessLogic/OfferManager.java | 16 +- .../__ApplicationFacadeInterface.java | 56 ---- .../businessLogic/__FacadeImplementation.java | 109 -------- ruralHouses/src/dataAccess/DB4oManager.java | 120 +++------ ruralHouses/src/domain/RuralHouse.java | 14 +- ruralHouses/src/gui/AddOffersGUI.java | 3 +- ruralHouses/src/gui/CreateOfferGUI.java | 191 -------------- ruralHouses/src/gui/DeleteOfferGUI.java | 118 ++++----- ruralHouses/src/gui/HouseFeaturesGUI.java | 1 - .../src/gui/HousesRelatedOwnerGUI.java | 4 +- ruralHouses/src/gui/ModifyHouseGUI.java | 249 +++++++----------- ruralHouses/src/gui/ModifyOfferGUI.java | 179 ++++++++----- .../src/gui/OffersRelatedOwnerGUI.java | 2 +- .../src/gui/QueryAvailabilityGUI2.java | 47 ++-- 16 files changed, 356 insertions(+), 826 deletions(-) delete mode 100644 ruralHouses/src/businessLogic/__ApplicationFacadeInterface.java delete mode 100644 ruralHouses/src/businessLogic/__FacadeImplementation.java delete mode 100644 ruralHouses/src/gui/CreateOfferGUI.java diff --git a/ruralHouses/src/businessLogic/HouseManager.java b/ruralHouses/src/businessLogic/HouseManager.java index 02574fc..4601b88 100644 --- a/ruralHouses/src/businessLogic/HouseManager.java +++ b/ruralHouses/src/businessLogic/HouseManager.java @@ -21,56 +21,38 @@ public class HouseManager implements HouseManagerInterface { } - - @Override - public boolean registerNewHouse(String houseName, Owner owner, - String description, String district, int nRooms, int nKitchens, - int nBaths, int nLivings, int nParkings) { - - boolean stored = false; + private boolean suitsRegulations(int nKitchens, int nBaths, int nLivings) { if (nKitchens < 1 || nLivings < 3 || nBaths < 2) return false; - HouseFeatures feature = new HouseFeatures(nRooms, nKitchens, nBaths, - nLivings, nParkings); - RuralHouse rh = new RuralHouse(houseName, - owner, description, district, feature); - owner.getRuralHouses().add(rh); - stored = this.dbMngr.storeRuralHouses(rh); - return stored; + else + return true; } - - @Override + @Override public boolean registerNewHouse(RuralHouse rh) { - + boolean stored = false; - + if (!suitsRegulations(rh.getFeatures().getnKitchens(), rh.getFeatures() + .getnBaths(), rh.getFeatures().getnKitchens())) + return false; rh.getOwner().getRuralHouses().add(rh); stored = this.dbMngr.storeRuralHouses(rh); return stored; } - - public void removeHouse(RuralHouse rh , Owner owner) { - Vector temp = owner.getRuralHouses(); + public void removeHouse(RuralHouse rh, Owner owner) { + Vector temp = owner.getRuralHouses(); temp.remove(rh); this.dbMngr.removeHouse(rh, owner); } - @Override - public Vector getHousesByDistrict(String town) { - - return this.dbMngr.getRuralHousesByTown(town); - } - - public Vector getHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv) { - - return this.dbMngr.getRuralHouses(town, nBed, nKit, nBath, nPark, nLiv); - } - + public Vector getHouses(String name,String town, int nBed, int nKit, + int nBath, int nPark, int nLiv) { + return this.dbMngr.getRuralHouses(name ,town, nBed, nKit, nBath, nPark, nLiv); + } @Override public Vector getAllRuralHouses() throws RemoteException, @@ -80,15 +62,6 @@ public class HouseManager implements HouseManagerInterface { - @Override - public RuralHouse getHouseByName(String Name) { - return this.dbMngr.getRuralHouseByName(Name); - } - - - - - // For future implementation // @Override // public void modifyHouse(int houseName, Owner owner, String description, diff --git a/ruralHouses/src/businessLogic/HouseManagerInterface.java b/ruralHouses/src/businessLogic/HouseManagerInterface.java index e921da5..14708c0 100644 --- a/ruralHouses/src/businessLogic/HouseManagerInterface.java +++ b/ruralHouses/src/businessLogic/HouseManagerInterface.java @@ -8,12 +8,6 @@ import domain.RuralHouse; public interface HouseManagerInterface { - - - public boolean registerNewHouse(String houseName, Owner owner, - String description, String town, int nRooms, int nKitchens, - int nBaths, int nLivings, int nParkings); - // For future implementation // public void modifyHouse(int houseName, Owner owner, // String description, String town, int nRooms, int nKitchens, @@ -21,16 +15,8 @@ public interface HouseManagerInterface { public void removeHouse(RuralHouse rh, Owner owner); - public Vector getHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv) ; + public Vector getHouses(String name,String town,int nBed , int nKit, int nBath, int nPark, int nLiv) ; - /** - * @param district - * @return - */ - public Vector getHousesByDistrict(String district); - - - public RuralHouse getHouseByName(String Name); /** * This method retrieves the existing rural houses * @@ -39,6 +25,6 @@ public interface HouseManagerInterface { public Vector getAllRuralHouses()throws RemoteException, Exception; - boolean registerNewHouse(RuralHouse rh); + public boolean registerNewHouse(RuralHouse rh); } diff --git a/ruralHouses/src/businessLogic/OfferManager.java b/ruralHouses/src/businessLogic/OfferManager.java index 8286b54..4ac0255 100644 --- a/ruralHouses/src/businessLogic/OfferManager.java +++ b/ruralHouses/src/businessLogic/OfferManager.java @@ -61,7 +61,8 @@ public final class OfferManager { */ public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay, float price) throws OverlappingOfferExists, BadDates, RemoteException, Exception { - if (firstDay.compareTo(lastDay)>=0) throw new BadDates(); + if (firstDay.after(lastDay)||firstDay==null||lastDay==null) + throw new BadDates(); boolean b = dbMngr.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated if (!b) { @@ -71,19 +72,10 @@ public final class OfferManager { return null; } - public Offer modifyOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay, - float price, Offer offer) throws OverlappingOfferExists, BadDates, RemoteException, Exception { - if (firstDay.compareTo(lastDay)>=0) throw new BadDates(); - offer.setFirstDay(firstDay); - offer.setLastDay(lastDay); - offer.setPrice(price); - - return dbMngr.modifyOffer(offer); - - } + public void deleteOffer(RuralHouse rh, Offer o) throws RemoteException, Exception{ rh.offers.removeElement(o); - dbMngr.deleteOffer(rh, o); + dbMngr.deleteOffer( o); } } diff --git a/ruralHouses/src/businessLogic/__ApplicationFacadeInterface.java b/ruralHouses/src/businessLogic/__ApplicationFacadeInterface.java deleted file mode 100644 index edea314..0000000 --- a/ruralHouses/src/businessLogic/__ApplicationFacadeInterface.java +++ /dev/null @@ -1,56 +0,0 @@ -package businessLogic; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.sql.Date; -import java.util.Vector; - -import domain.Booking; -import domain.Offer; -import domain.Owner; -import domain.RuralHouse; -import exceptions.OfferCanNotBeBooked; - - -public interface __ApplicationFacadeInterface extends Remote { - - - /** - * This method creates an offer with a house number, first day, last day and price - * - * @param House - * number, start day, last day and price - * @return None - */ - - - Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay, - float price) throws RemoteException, Exception; - - /** - * This method creates a book with a corresponding parameters - * - * @param First - * day, last day, house number and telephone - * @return a book - */ - Booking createBooking(RuralHouse ruralHouse, Date firstDay, Date lastDay, - String telephoneNumber) throws RemoteException, - OfferCanNotBeBooked; - - - /** - * This method retrieves the existing owners - * - * @return a Set of owners - */ - public Vector getOwners() throws RemoteException, - Exception; - - - - public void close() throws RemoteException; - - - -} \ No newline at end of file diff --git a/ruralHouses/src/businessLogic/__FacadeImplementation.java b/ruralHouses/src/businessLogic/__FacadeImplementation.java deleted file mode 100644 index 9f377d7..0000000 --- a/ruralHouses/src/businessLogic/__FacadeImplementation.java +++ /dev/null @@ -1,109 +0,0 @@ -package businessLogic; - -import java.rmi.RemoteException; -import java.rmi.server.UnicastRemoteObject; -import java.sql.Date; -import java.sql.SQLException; -import java.util.Vector; - -import dataAccess.DB4oManager; -import domain.Booking; -import domain.Offer; -import domain.Owner; -import domain.RuralHouse; -import exceptions.BadDates; -import exceptions.DB4oManagerCreationException; -import exceptions.OfferCanNotBeBooked; -import exceptions.OverlappingOfferExists; - - -public class __FacadeImplementation extends UnicastRemoteObject implements __ApplicationFacadeInterface { - - /** - * - */ - private static final long serialVersionUID = 1L; - - Vector owners; - Vector ruralHouses; - DB4oManager dB4oManager; - - - public __FacadeImplementation() throws RemoteException, InstantiationException, - IllegalAccessException, ClassNotFoundException, SQLException, DB4oManagerCreationException { - owners=null; - ruralHouses=null; - try{ - dB4oManager=DB4oManager.getInstance(); - } - catch (com.db4o.ext.DatabaseFileLockedException e) { - System.out.println("Error in FacadeImplementation: "+e.toString()); - throw e; - } - catch (Exception e) { - System.out.println("Error in FacadeImplementation: "+e.toString()); - throw new DB4oManagerCreationException(); - } - } - - - /** - * This method creates an offer with a house number, first day, last day and price - * - * @param House - * number, start day, last day and price - * @return the created offer, or null, or an exception - */ - public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay, - float price) throws OverlappingOfferExists, BadDates, RemoteException, Exception { - if (firstDay.compareTo(lastDay)>=0) throw new BadDates(); - ruralHouses=null; - owners=null; - boolean b = dB4oManager.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated - if (!b) return dB4oManager.createOffer(ruralHouse,firstDay,lastDay,price); - return null; - } - - /** - * This method creates a book with a corresponding parameters - * - * @param First - * day, last day, house number and telephone - * @return a book - */ - public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber) - throws OfferCanNotBeBooked { - ruralHouses=null; - owners=null; - return dB4oManager.createBooking(ruralHouse,firstDate,lastDate,bookTelephoneNumber); - } - - - /** - * This method existing owners - * - */ - public Vector getOwners() throws RemoteException, - Exception { - - if (owners!=null) { System.out.println("Owners obtained directly from business logic layer"); - return owners; } - else return owners=dB4oManager.getOwners(); - } - - public Vector getAllRuralHouses() throws RemoteException, - Exception { - - if (ruralHouses!=null) { System.out.println("RuralHouses obtained directly from business logic layer"); - return ruralHouses; } - else return ruralHouses=dB4oManager.getAllRuralHouses(); - - } - - public void close() throws RemoteException{ - dB4oManager.close(); - - } - - } - diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 6e24ece..a2bcfde 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -4,9 +4,7 @@ import java.io.File; //import java.util.Enumeration; //import java.util.Vector; import java.rmi.RemoteException; -import java.util.Date; -import java.util.ListIterator; -import java.util.Vector; +import java.util.*; import com.db4o.Db4oEmbedded; import com.db4o.ObjectContainer; @@ -14,6 +12,7 @@ import com.db4o.ObjectSet; import com.db4o.config.EmbeddedConfiguration; import com.db4o.cs.Db4oClientServer; import com.db4o.cs.config.ClientConfiguration; +import com.db4o.query.Predicate; import configuration.ConfigXML; import domain.Account; @@ -112,20 +111,19 @@ public class DB4oManager { try { Owner jon = new Owner("Jon"); Owner alfredo = new Owner("Alfredo"); - jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Beatriz", 3, 3, 3, 3, - 3); - jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Guazate", 4, 4, 4, - 4, 4); + jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Beatriz", 3, 3, 3, + 3, 3); + jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Guazate", 4, 4, + 4, 4, 4); jon.setBankAccount("1349 5677 21 2133567777"); - alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Vegas", 5, - 5, 5, 5, 5); + alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Vegas", 5, 5, + 5, 5, 5); + alfredo.addRuralHouse("Murgoitz", "", "Cedro", 6, 6, 6, 6, 6); alfredo.setBankAccount("4144 0087 23 9700002133"); Account jonAcc = new Account("userJon", "passJon", jon); Account alfredoAcc = new Account("userAlfredo", "passAlfredo", alfredo); - db.store(jon); - db.store(alfredo); db.store(jonAcc); db.store(alfredoAcc); db.commit(); @@ -155,8 +153,6 @@ public class DB4oManager { db.close(); } } - - public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay, float price) throws RemoteException, Exception { @@ -171,7 +167,7 @@ public class DB4oManager { RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(), null, null, null, null); - ObjectSet result = db.queryByExample(proto); + ObjectSet result = db.queryByExample(proto); RuralHouse rh = (RuralHouse) result.next(); o = rh.createOffer(theDB4oManagerAux.offerNumber++, firstDay, lastDay, price); @@ -189,27 +185,8 @@ public class DB4oManager { return o; } - public Offer modifyOffer(Offer offer) throws RemoteException, Exception { - if (c.isDatabaseLocal() == false) - openSDB(); - else - openDB(); - - try { - - db.store(offer); - db.commit(); - - } catch (com.db4o.ext.ObjectNotStorableException e) { - System.out - .println("Error: com.db4o.ext.ObjectNotStorableException in createOffer"); - } finally { - db.close(); - } - return offer; - } - - public void deleteOffer(RuralHouse rh, Offer offer) throws RemoteException, + + public void deleteOffer(Offer offer) throws RemoteException, Exception { if (c.isDatabaseLocal() == false) openSDB(); @@ -217,9 +194,10 @@ public class DB4oManager { openDB(); try { - + ObjectSet of = db.queryByExample(offer); + RuralHouse rh =of.get(0).getRuralHouse(); + System.out.println(rh.offers.remove(of.get(0))); db.store(rh); - db.delete(offer); db.commit(); } catch (com.db4o.ext.ObjectNotStorableException e) { @@ -295,7 +273,7 @@ public class DB4oManager { try { Owner proto = new Owner(null, null); - ObjectSet result = db.queryByExample(proto); + ObjectSet result = db.queryByExample(proto); Vector owners = new Vector(); while (result.hasNext()) owners.add((Owner) result.next()); @@ -406,6 +384,11 @@ public class DB4oManager { db.store(rh); db.commit(); stored = true; + } else { + db.delete(result.get(0)); + db.store(rh); + db.commit(); + stored = true; } } finally { db.close(); @@ -420,12 +403,12 @@ public class DB4oManager { else openDB(); try { - ObjectSet result = db.queryByExample(rh); - if (!result.isEmpty()) { - RuralHouse found = (RuralHouse) result.get(0); - // db.delete(found.getOwner()); - db.store(owner); - db.delete(found); + ObjectSet result = db.queryByExample(owner); + ObjectSet rhs = db.queryByExample(rh); + if (!rhs.isEmpty()) { + Owner found = result.get(0); + found.getRuralHouses().remove(rhs.get(0)); + db.store(found); db.commit(); } } catch (Exception exc) { @@ -436,54 +419,11 @@ public class DB4oManager { } - public Vector getRuralHousesByTown(String town) { - RuralHouse rh = new RuralHouse(null, null, null, town, null); - - if (c.isDatabaseLocal() == false) - openSDB(); - else - openDB(); - - try { - ObjectSet result = db.queryByExample(rh); - Vector ruralHouses = new Vector(); - while (result.hasNext()) - ruralHouses.add(result.next()); - return ruralHouses; - } finally { - db.close(); - } - - } - - public RuralHouse getRuralHouseByName(String name) { - RuralHouse rh = new RuralHouse(name, null, null, null, null); - - if (c.isDatabaseLocal() == false) - openSDB(); - else - openDB(); - - try { - ObjectSet result = db.queryByExample(rh); - Vector ruralHouses = new Vector(); - while (result.hasNext()) - ruralHouses.add(result.next()); - db.close(); - if (!ruralHouses.isEmpty()) - return ruralHouses.get(0); - else - return null; - } catch (NullPointerException e) { - return null; - } - - } - public Vector getRuralHouses(String town, int nBed, int nKit, - int nBath, int nPark, int nLiv) { + public Vector getRuralHouses(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(null, null, null, town, fea); + RuralHouse rh = new RuralHouse(name, null, null, town, fea); if (c.isDatabaseLocal() == false) openSDB(); else diff --git a/ruralHouses/src/domain/RuralHouse.java b/ruralHouses/src/domain/RuralHouse.java index 423d5e7..081ef4c 100644 --- a/ruralHouses/src/domain/RuralHouse.java +++ b/ruralHouses/src/domain/RuralHouse.java @@ -97,18 +97,7 @@ public class RuralHouse implements Serializable { return false; return true; } - - public String getAccountNumber(int houseName) { - /*try { - dbMngr=DBManager.getInstance(); - return dbMngr.getOwner(houseName).getBankAccount(); - } catch (Exception e) { - System.out.println("Error, accessing to DB Manager: " - + e.toString()); - return null; - }*/ return null; - } /** * This method obtains available offers for a concrete house in a certain period @@ -166,7 +155,8 @@ public Offer overlapsWith( Date firstDay, Date lastDay) { Offer offer=null; while (e.hasNext()){ offer=e.next(); - if ( (offer.getFirstDay().compareTo(lastDay)<0) && (offer.getLastDay().compareTo(firstDay)>0)) + if ( (offer.getFirstDay().compareTo(lastDay)<0) + && (offer.getLastDay().compareTo(firstDay)>0)) return offer; } return null; diff --git a/ruralHouses/src/gui/AddOffersGUI.java b/ruralHouses/src/gui/AddOffersGUI.java index e93e775..12d501b 100644 --- a/ruralHouses/src/gui/AddOffersGUI.java +++ b/ruralHouses/src/gui/AddOffersGUI.java @@ -210,8 +210,7 @@ private static final long serialVersionUID = 1L; //Obtain the business logic from a StartWindow class (local or remote) OfferManager offerM = new OfferManager(); - Offer o = offerM.createOffer(ruralHouse, firstDay, lastDay, price); - System.out.println("Offer created: "+o.toString()); + offerM.createOffer(ruralHouse, firstDay, lastDay, price); jLabel5.setText("Offer created"); diff --git a/ruralHouses/src/gui/CreateOfferGUI.java b/ruralHouses/src/gui/CreateOfferGUI.java deleted file mode 100644 index 621a840..0000000 --- a/ruralHouses/src/gui/CreateOfferGUI.java +++ /dev/null @@ -1,191 +0,0 @@ -package gui; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.sql.Date; -import java.text.DateFormat; -import java.util.Calendar; -import java.util.Locale; -import java.util.Vector; - -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JTextField; - -import businessLogic.OfferManager; - -import com.toedter.calendar.JCalendar; - -import domain.RuralHouse; - -public class CreateOfferGUI extends JFrame { - - private static final long serialVersionUID = 1L; - - private JComboBox jComboBox1; - private JLabel jLabel1 = new JLabel(); - private JLabel jLabel2 = new JLabel(); - private JTextField jTextField1 = new JTextField(); - private JLabel jLabel3 = new JLabel(); - private JTextField jTextField2 = new JTextField(); - private JLabel jLabel4 = new JLabel(); - private JTextField jTextField3 = new JTextField(); - private JButton jButton1 = new JButton(); - // Code for JCalendar - private JCalendar jCalendar1 = new JCalendar(); - private JCalendar jCalendar2 = new JCalendar(); - private Calendar calendarInicio = null; - private Calendar calendarFin = null; - private JButton jButton2 = new JButton(); - private JLabel jLabel5 = new JLabel(); - - public CreateOfferGUI(Vector v) { - try { - jbInit(v); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - private void jbInit(Vector v) throws Exception { - this.getContentPane().setLayout(null); - this.setSize(new Dimension(513, 433)); - this.setTitle("Set availability"); - - jComboBox1 = new JComboBox(v); - jComboBox1.setBounds(new Rectangle(115, 30, 115, 20)); - jLabel1.setText("List of houses:"); - jLabel1.setBounds(new Rectangle(25, 30, 95, 20)); - jLabel2.setText("First day :"); - jLabel2.setBounds(new Rectangle(25, 75, 85, 25)); - jTextField1.setBounds(new Rectangle(25, 265, 220, 25)); - jTextField1.setEditable(false); - jLabel3.setText("Last day :"); - jLabel3.setBounds(new Rectangle(260, 75, 75, 25)); - jTextField2.setBounds(new Rectangle(260, 265, 220, 25)); - jTextField2.setEditable(false); - jLabel4.setText("Price:"); - jLabel4.setBounds(new Rectangle(260, 30, 75, 20)); - jTextField3.setBounds(new Rectangle(350, 30, 115, 20)); - jTextField3.setText("0"); - jButton1.setText("Accept"); - jButton1.setBounds(new Rectangle(100, 360, 130, 30)); - jTextField3.addFocusListener(new FocusListener() { - public void focusGained(FocusEvent e) {} - public void focusLost(FocusEvent e) { - jTextField3_focusLost(); - } - }); - jButton1.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - jButton1_actionPerformed(e); - } - }); - jButton2.setText("Cancel"); - jButton2.setBounds(new Rectangle(270, 360, 130, 30)); - jButton2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - jButton2_actionPerformed(e); - } - }); - jLabel5.setBounds(new Rectangle(100, 320, 300, 20)); - jLabel5.setForeground(Color.red); - jLabel5.setSize(new Dimension(305, 20)); - jCalendar1.setBounds(new Rectangle(25, 100, 220, 165)); - jCalendar2.setBounds(new Rectangle(260, 100, 220, 165)); - - // Code for JCalendar - this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent propertychangeevent) { - if (propertychangeevent.getPropertyName().equals("locale")) { - jCalendar1.setLocale((Locale) propertychangeevent.getNewValue()); - DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar1.getLocale()); - jTextField1.setText(dateformat.format(calendarInicio.getTime())); - } - else if (propertychangeevent.getPropertyName().equals("calendar")) { - calendarInicio = (Calendar) propertychangeevent.getNewValue(); - DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale()); - jTextField1.setText(dateformat1.format(calendarInicio.getTime())); - jCalendar1.setCalendar(calendarInicio); - } - } - }); - - this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent propertychangeevent) { - if (propertychangeevent.getPropertyName().equals("locale")) { - jCalendar2.setLocale((Locale) propertychangeevent.getNewValue()); - DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar2.getLocale()); - jTextField2.setText(dateformat.format(calendarFin.getTime())); - } - else if (propertychangeevent.getPropertyName().equals("calendar")) { - calendarFin = (Calendar) propertychangeevent.getNewValue(); - DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar2.getLocale()); - jTextField2.setText(dateformat1.format(calendarFin.getTime())); - jCalendar2.setCalendar(calendarFin); - } - } - }); - - this.getContentPane().add(jCalendar2, null); - this.getContentPane().add(jCalendar1, null); - this.getContentPane().add(jLabel5, null); - this.getContentPane().add(jButton2, null); - this.getContentPane().add(jButton1, null); - this.getContentPane().add(jTextField3, null); - this.getContentPane().add(jLabel4, null); - this.getContentPane().add(jTextField2, null); - this.getContentPane().add(jLabel3, null); - this.getContentPane().add(jTextField1, null); - this.getContentPane().add(jLabel2, null); - this.getContentPane().add(jLabel1, null); - this.getContentPane().add(jComboBox1, null); - } - - private void jButton1_actionPerformed(ActionEvent e) { - RuralHouse ruralHouse=((RuralHouse)jComboBox1.getSelectedItem()); - Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime()); - //Remove the hour:minute:second:ms from the date - firstDay=Date.valueOf(firstDay.toString()); - Date lastDay=new Date(jCalendar2.getCalendar().getTime().getTime()); - //Remove the hour:minute:second:ms from the date - lastDay=Date.valueOf(lastDay.toString()); - //It could be to trigger an exception if the introduced string is not a number - float price= Float.parseFloat(jTextField3.getText()); - try { - //Obtain the business logic from a StartWindow class (local or remote) - OfferManager offerM = new OfferManager(); - - offerM.createOffer(ruralHouse, firstDay, lastDay, price); - - this.setVisible(false); - } - catch (Exception e1) { - e1.printStackTrace(); - } - } - - private void jButton2_actionPerformed(ActionEvent e) { - this.setVisible(false); - } - - private void jTextField3_focusLost() { - try { - new Integer (jTextField3.getText()); - jLabel5.setText(""); - } - catch (NumberFormatException ex) { - jLabel5.setText("Error: Please introduce a number"); - } - } -} \ No newline at end of file diff --git a/ruralHouses/src/gui/DeleteOfferGUI.java b/ruralHouses/src/gui/DeleteOfferGUI.java index faa4f81..bed2cb7 100644 --- a/ruralHouses/src/gui/DeleteOfferGUI.java +++ b/ruralHouses/src/gui/DeleteOfferGUI.java @@ -20,6 +20,8 @@ import businessLogic.OfferManager; import domain.Offer; import domain.Owner; import domain.RuralHouse; +import javax.swing.LayoutStyle.ComponentPlacement; +import javax.swing.JTextField; public class DeleteOfferGUI extends JFrame { @@ -29,11 +31,11 @@ public class DeleteOfferGUI extends JFrame { private static final long serialVersionUID = 1L; private JPanel contentPane; private Owner owner; + private JLabel feedback; private JComboBox comboBox; private JComboBox comboBox_1; private JButton btnDelete; - /** * Create the frame. */ @@ -43,108 +45,94 @@ public class DeleteOfferGUI extends JFrame { contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); - + comboBox = new JComboBox(this.owner.getRuralHouses()); - - - + comboBox.setBounds(101, 38, 314, 20); + comboBox_1 = new JComboBox(); + comboBox_1.setBounds(101, 76, 314, 20); + Vector vo = ((RuralHouse) comboBox.getSelectedItem()).offers; + comboBox_1.removeAllItems(); + for (Offer of : vo) { + comboBox_1.addItem(of); + ; + } JRadioButton rdbtnIAmSure = new JRadioButton("I am sure"); - + rdbtnIAmSure.setBounds(101, 134, 71, 23); + btnDelete = new JButton("DELETE"); + btnDelete.setBounds(92, 226, 69, 23); btnDelete.setEnabled(false); - + comboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent arg0) { - Vector vo = ((RuralHouse)comboBox.getSelectedItem()).offers; + Vector vo = ((RuralHouse) comboBox.getSelectedItem()).offers; comboBox_1.removeAllItems(); - for (Offer of: vo){ - comboBox_1.addItem(of);; + for (Offer of : vo) { + comboBox_1.addItem(of); + ; } - + } - + }); - + rdbtnIAmSure.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { int state = e.getStateChange(); - if (state == ItemEvent.SELECTED){ - btnDelete.setEnabled(true); - } - else if (state == ItemEvent.DESELECTED){ + if (state == ItemEvent.SELECTED) { + if (comboBox_1.getSelectedItem() != null) + btnDelete.setEnabled(true); + } else if (state == ItemEvent.DESELECTED) { btnDelete.setEnabled(false); } } }); - + JLabel lblHouse = new JLabel("House:"); - + lblHouse.setBounds(25, 41, 68, 14); + JLabel lblOffer = new JLabel("Offer:"); - GroupLayout gl_contentPane = new GroupLayout(contentPane); - gl_contentPane.setHorizontalGroup( - gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(85) - .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) - .addComponent(btnDelete) - .addComponent(rdbtnIAmSure))) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(20) - .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false) - .addComponent(lblHouse, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(lblOffer, GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)) - .addGap(8) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false) - .addComponent(comboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(comboBox_1, 0, 314, Short.MAX_VALUE)))) - .addContainerGap(946, Short.MAX_VALUE)) - ); - gl_contentPane.setVerticalGroup( - gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(33) - .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) - .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(lblHouse)) - .addGap(18) - .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) - .addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(lblOffer)) - .addGap(43) - .addComponent(rdbtnIAmSure) - .addGap(47) - .addComponent(btnDelete) - .addContainerGap(493, Short.MAX_VALUE)) - ); - contentPane.setLayout(gl_contentPane); + lblOffer.setBounds(25, 79, 68, 14); + contentPane.setLayout(null); + contentPane.add(btnDelete); + contentPane.add(rdbtnIAmSure); + contentPane.add(lblHouse); + contentPane.add(lblOffer); + contentPane.add(comboBox); + contentPane.add(comboBox_1); + feedback = new JLabel(""); + feedback.setBounds(140, 178, 155, 23); + contentPane.add(feedback); + btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionListenerButton(arg0); - + } - }); } - - private void actionListenerButton(ActionEvent e){ - Offer toDel = (Offer)comboBox_1.getSelectedItem(); + private void actionListenerButton(ActionEvent e) { + + Offer toDel = (Offer) comboBox_1.getSelectedItem(); OfferManager oM = new OfferManager(); try { - oM.deleteOffer((RuralHouse)comboBox.getSelectedItem(),toDel); + oM.deleteOffer((RuralHouse) comboBox.getSelectedItem(), toDel); + comboBox_1.removeItem(toDel); + btnDelete.setEnabled(false); + feedback.setText("Offer correctly deleted"); } catch (Exception e1) { + feedback.setText("Imposible to delete the offer"); e1.printStackTrace(); } - comboBox.removeItem(toDel); + } } diff --git a/ruralHouses/src/gui/HouseFeaturesGUI.java b/ruralHouses/src/gui/HouseFeaturesGUI.java index ba912b1..0261832 100644 --- a/ruralHouses/src/gui/HouseFeaturesGUI.java +++ b/ruralHouses/src/gui/HouseFeaturesGUI.java @@ -50,7 +50,6 @@ public class HouseFeaturesGUI extends JFrame { private JTextField baths_f; private JTable table; private DefaultTableModel tableModel; - private DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer(); private RuralHouse rh; private JTextField telIn; private int row; diff --git a/ruralHouses/src/gui/HousesRelatedOwnerGUI.java b/ruralHouses/src/gui/HousesRelatedOwnerGUI.java index 95a654d..16884c3 100644 --- a/ruralHouses/src/gui/HousesRelatedOwnerGUI.java +++ b/ruralHouses/src/gui/HousesRelatedOwnerGUI.java @@ -32,7 +32,7 @@ public class HousesRelatedOwnerGUI extends JFrame { contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); - JButton btnCreateHouses = new JButton("Create Houses"); + JButton btnCreateHouses = new JButton("Create Request"); btnCreateHouses.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Frame a = new RequestNewHouseGUI(owner); @@ -50,7 +50,7 @@ public class HousesRelatedOwnerGUI extends JFrame { } }); - JButton btnDeleteHouses = new JButton("Delete Houses"); + JButton btnDeleteHouses = new JButton("Delete Request"); btnDeleteHouses.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Frame a = new RequestDeleteHouseGUI(owner); diff --git a/ruralHouses/src/gui/ModifyHouseGUI.java b/ruralHouses/src/gui/ModifyHouseGUI.java index 34f94c2..0fc99a9 100644 --- a/ruralHouses/src/gui/ModifyHouseGUI.java +++ b/ruralHouses/src/gui/ModifyHouseGUI.java @@ -18,6 +18,7 @@ import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; import businessLogic.HouseManager; +import domain.HouseFeatures; import domain.Owner; import domain.RuralHouse; @@ -31,6 +32,7 @@ public class ModifyHouseGUI extends JFrame { private Owner owner; private JLabel lblDistrict; private JTextField District_f; + private JLabel feedback; private JLabel lblDescription; private JTextField description_f; private JLabel lblKitchen; @@ -47,7 +49,6 @@ public class ModifyHouseGUI extends JFrame { private JComboBox houseBox; private RuralHouse rh; - /** * Create the frame. */ @@ -58,190 +59,142 @@ public class ModifyHouseGUI extends JFrame { contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); - + JLabel lblCode = new JLabel("House Name:"); + lblCode.setBounds(15, 88, 64, 14); lblCode.setHorizontalAlignment(SwingConstants.RIGHT); - + lblDistrict = new JLabel("District:"); + lblDistrict.setBounds(39, 119, 70, 14); lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT); - + District_f = new JTextField(); + District_f.setBounds(127, 116, 86, 20); District_f.setColumns(10); - + lblDescription = new JLabel("Description:"); + lblDescription.setBounds(231, 88, 90, 14); lblDescription.setHorizontalAlignment(SwingConstants.RIGHT); - + description_f = new JTextField(); + description_f.setBounds(241, 113, 178, 129); description_f.setColumns(10); - + lblKitchen = new JLabel("Kitchens:"); + lblKitchen.setBounds(230, 316, 70, 14); lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT); - + kitchens_f = new JTextField(); + kitchens_f.setBounds(318, 313, 86, 20); kitchens_f.setColumns(10); - + lblRooms = new JLabel("Rooms:"); + lblRooms.setBounds(39, 316, 70, 14); lblRooms.setHorizontalAlignment(SwingConstants.RIGHT); - + rooms_f = new JTextField(); + rooms_f.setBounds(127, 313, 86, 20); rooms_f.setColumns(10); - + lblLivings = new JLabel("Living rooms:"); + lblLivings.setBounds(237, 354, 63, 14); lblLivings.setHorizontalAlignment(SwingConstants.RIGHT); - + lRooms_f = new JTextField(); + lRooms_f.setBounds(318, 351, 86, 20); lRooms_f.setColumns(10); - + lblParkings = new JLabel("Parkings:"); + lblParkings.setBounds(39, 404, 70, 14); lblParkings.setHorizontalAlignment(SwingConstants.RIGHT); - + parkings_f = new JTextField(); + parkings_f.setBounds(127, 401, 86, 20); parkings_f.setColumns(10); - + lblBaths = new JLabel("Baths:"); + lblBaths.setBounds(39, 354, 70, 14); lblBaths.setHorizontalAlignment(SwingConstants.RIGHT); - + baths_f = new JTextField(); + baths_f.setBounds(127, 351, 86, 20); baths_f.setColumns(10); - + btnConfirm = new JButton("Confirm"); + btnConfirm.setBounds(145, 462, 69, 23); btnConfirm.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - - + + RuralHouse newRh = new RuralHouse(rh.getHouseName(), owner, + description_f.getText(), District_f.getText(), + new HouseFeatures(new Integer(rooms_f.getText()), + new Integer(kitchens_f.getText()), new Integer( + baths_f.getText()), new Integer( + lRooms_f.getText()), new Integer( + parkings_f.getText()))); HouseManager hm = new HouseManager(); - hm.removeHouse(rh, owner); - hm.registerNewHouse(rh.getHouseName(), - owner, - description_f.getText(), - District_f.getText(), - new Integer(rooms_f.getText()), - new Integer(kitchens_f.getText()), - new Integer(baths_f.getText()), - new Integer(lRooms_f.getText()), - new Integer(parkings_f.getText()) - ); + if (hm.registerNewHouse(newRh)) { + feedback.setText("House properly modified"); + } else + feedback.setText("Imposible to modify the house"); + } }); - + houseBox = new JComboBox(o.getRuralHouses()); - + if (!o.getRuralHouses().isEmpty()) { + rh = (RuralHouse) houseBox.getSelectedItem(); + District_f.setText(rh.getDistrict()); + description_f.setText(rh.getDescription()); + kitchens_f.setText(Integer + .toString(rh.getFeatures().getnKitchens())); + rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); + lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings())); + parkings_f.setText(Integer + .toString(rh.getFeatures().getnParkings())); + baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); + houseBox.setBounds(89, 85, 124, 20); + }else{ + feedback.setText("Not available houses"); + } houseBox.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - rh = (RuralHouse)houseBox.getSelectedItem(); - District_f.setText(rh.getDistrict()); - description_f.setText(rh.getDescription()); - kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens())); - rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); - lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings())); - parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings())); - baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); - - } - }); - - GroupLayout gl_contentPane = new GroupLayout(contentPane); - gl_contentPane.setHorizontalGroup( - gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addContainerGap() - .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblCode) - .addPreferredGap(ComponentPlacement.UNRELATED) - .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblDistrict, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(17) - .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblLivings) - .addGap(18) - .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGroup(gl_contentPane.createSequentialGroup() - .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE) - .addGap(18) - .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(18) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(10) - .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE)) - .addComponent(lblDescription, GroupLayout.PREFERRED_SIZE, 90, GroupLayout.PREFERRED_SIZE))))) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(140) - .addComponent(btnConfirm))) - .addContainerGap()) - ); - gl_contentPane.setVerticalGroup( - gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(20) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(60) - .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) - .addComponent(lblCode) - .addComponent(houseBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(ComponentPlacement.UNRELATED) - .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) - .addComponent(District_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(lblDistrict))) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(63) - .addComponent(lblDescription) - .addPreferredGap(ComponentPlacement.UNRELATED) - .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 129, GroupLayout.PREFERRED_SIZE))) - .addGap(71) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(3) - .addComponent(lblRooms)) - .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(3) - .addComponent(lblKitchen)) - .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(18) - .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(3) - .addComponent(lblBaths)) - .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE) - .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) - .addComponent(lblLivings))) - .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(30) - .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(3) - .addComponent(lblParkings)) - .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(41) - .addComponent(btnConfirm) - .addGap(54)) - ); - contentPane.setLayout(gl_contentPane); + @Override + public void itemStateChanged(ItemEvent e) { + rh = (RuralHouse) houseBox.getSelectedItem(); + District_f.setText(rh.getDistrict()); + description_f.setText(rh.getDescription()); + kitchens_f.setText(Integer.toString(rh.getFeatures() + .getnKitchens())); + rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); + lRooms_f.setText(Integer.toString(rh.getFeatures() + .getnLivings())); + parkings_f.setText(Integer.toString(rh.getFeatures() + .getnParkings())); + baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); + + } + }); + contentPane.setLayout(null); + contentPane.add(lblParkings); + contentPane.add(parkings_f); + contentPane.add(lblRooms); + contentPane.add(rooms_f); + contentPane.add(lblCode); + contentPane.add(houseBox); + contentPane.add(lblBaths); + contentPane.add(baths_f); + contentPane.add(lblDistrict); + contentPane.add(District_f); + contentPane.add(lblLivings); + contentPane.add(lRooms_f); + contentPane.add(lblKitchen); + contentPane.add(kitchens_f); + contentPane.add(description_f); + contentPane.add(lblDescription); + contentPane.add(btnConfirm); + + feedback = new JLabel(""); + feedback.setBounds(189, 510, 195, 23); + contentPane.add(feedback); } } diff --git a/ruralHouses/src/gui/ModifyOfferGUI.java b/ruralHouses/src/gui/ModifyOfferGUI.java index b5fc2af..eb6308f 100644 --- a/ruralHouses/src/gui/ModifyOfferGUI.java +++ b/ruralHouses/src/gui/ModifyOfferGUI.java @@ -29,9 +29,11 @@ import com.toedter.calendar.JCalendar; import domain.Offer; import domain.RuralHouse; +import exceptions.BadDates; +import exceptions.OverlappingOfferExists; + +public class ModifyOfferGUI extends JFrame { -public class ModifyOfferGUI extends JFrame { - private static final long serialVersionUID = 1L; private JComboBox jComboBox1; @@ -53,11 +55,10 @@ public class ModifyOfferGUI extends JFrame { private final JLabel jLabel1_o = new JLabel(); private JComboBox comboBox_o; - public ModifyOfferGUI(Vector v) { - try { + public ModifyOfferGUI(Vector v) { + try { jbInit(v); - } - catch (Exception e) { + } catch (Exception e) { e.printStackTrace(); } } @@ -68,13 +69,29 @@ public class ModifyOfferGUI extends JFrame { this.setTitle("Set availability"); jComboBox1 = new JComboBox(v); - - comboBox_o = new JComboBox(((RuralHouse)jComboBox1.getSelectedItem()).getAllOffers()); - - DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale()); - jTextField1.setText(dateformat1.format(((Offer) comboBox_o.getSelectedItem()).getFirstDay())); - jTextField2.setText(dateformat1.format(((Offer) comboBox_o.getSelectedItem()).getLastDay())); - + + comboBox_o = new JComboBox( + ((RuralHouse) jComboBox1.getSelectedItem()).getAllOffers()); + DateFormat dateformat1 = DateFormat.getDateInstance(1, + jCalendar1.getLocale()); + if (!((RuralHouse) jComboBox1.getSelectedItem()).getAllOffers() + .isEmpty()) { + jTextField1.setText(dateformat1.format(((Offer) comboBox_o + .getSelectedItem()).getFirstDay())); + jTextField2.setText(dateformat1.format(((Offer) comboBox_o + .getSelectedItem()).getLastDay())); + jLabel4.setText(Float.toString(((Offer) comboBox_o + .getSelectedItem()).getPrice())); + jTextField3.setText(Float.toString(((Offer) comboBox_o + .getSelectedItem()).getPrice())); + } else { + jLabel5.setText("There are no offers for the selected rural house"); + jCalendar1.setEnabled(false); + jCalendar2.setEnabled(false); + jButton1.setEnabled(false); + comboBox_o.setEnabled(false); + jTextField3.setEnabled(false); + } jComboBox1.setBounds(new Rectangle(115, 12, 115, 20)); jLabel1.setText("List of houses:"); jLabel1.setBounds(new Rectangle(25, 12, 95, 20)); @@ -93,40 +110,59 @@ public class ModifyOfferGUI extends JFrame { jButton1.setText("Accept"); jButton1.setBounds(new Rectangle(100, 360, 130, 30)); jTextField3.addFocusListener(new FocusListener() { - public void focusGained(FocusEvent e) {} + public void focusGained(FocusEvent e) { + } + public void focusLost(FocusEvent e) { jTextField3_focusLost(); } }); - + jComboBox1.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent arg0) { - Vector vo = ((RuralHouse)jComboBox1.getSelectedItem()).offers; + Vector vo = ((RuralHouse) jComboBox1.getSelectedItem()).offers; comboBox_o.removeAllItems(); - for (Offer of: vo){ - comboBox_o.addItem(of); + if (!((RuralHouse) jComboBox1.getSelectedItem()).offers + .isEmpty()) { + jCalendar1.setEnabled(true); + jCalendar2.setEnabled(true); + jButton1.setEnabled(true); + comboBox_o.setEnabled(true); + jTextField3.setEnabled(true); + jLabel5.setText(""); + for (Offer of : vo) { + comboBox_o.addItem(of); + } + } else { + jLabel5.setText("There are no offers for the selected rural house"); + jCalendar1.setEnabled(false); + jCalendar2.setEnabled(false); + jButton1.setEnabled(false); + comboBox_o.setEnabled(false); + jTextField3.setEnabled(false); + } - } - + }); - + comboBox_o.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent arg0) { - if(arg0.getStateChange() == ItemEvent.SELECTED){ + if (arg0.getStateChange() == ItemEvent.SELECTED) { Offer of = (Offer) comboBox_o.getSelectedItem(); - DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale()); + DateFormat dateformat1 = DateFormat.getDateInstance(1, + jCalendar1.getLocale()); jTextField1.setText(dateformat1.format(of.getFirstDay())); jTextField2.setText(dateformat1.format(of.getLastDay())); } } - + }); - + jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); @@ -149,33 +185,43 @@ public class ModifyOfferGUI extends JFrame { this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertychangeevent) { if (propertychangeevent.getPropertyName().equals("locale")) { - jCalendar1.setLocale((Locale) propertychangeevent.getNewValue()); - DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar1.getLocale()); - jTextField1.setText(dateformat.format(calendarInicio.getTime())); - } - else if (propertychangeevent.getPropertyName().equals("calendar")) { - calendarInicio = (Calendar) propertychangeevent.getNewValue(); - DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale()); - jTextField1.setText(dateformat1.format(calendarInicio.getTime())); + jCalendar1.setLocale((Locale) propertychangeevent + .getNewValue()); + DateFormat dateformat = DateFormat.getDateInstance(1, + jCalendar1.getLocale()); + jTextField1.setText(dateformat.format(calendarInicio + .getTime())); + } else if (propertychangeevent.getPropertyName().equals( + "calendar")) { + calendarInicio = (Calendar) propertychangeevent + .getNewValue(); + DateFormat dateformat1 = DateFormat.getDateInstance(1, + jCalendar1.getLocale()); + jTextField1.setText(dateformat1.format(calendarInicio + .getTime())); jCalendar1.setCalendar(calendarInicio); } - } + } }); this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertychangeevent) { if (propertychangeevent.getPropertyName().equals("locale")) { - jCalendar2.setLocale((Locale) propertychangeevent.getNewValue()); - DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar2.getLocale()); + jCalendar2.setLocale((Locale) propertychangeevent + .getNewValue()); + DateFormat dateformat = DateFormat.getDateInstance(1, + jCalendar2.getLocale()); jTextField2.setText(dateformat.format(calendarFin.getTime())); - } - else if (propertychangeevent.getPropertyName().equals("calendar")) { + } else if (propertychangeevent.getPropertyName().equals( + "calendar")) { calendarFin = (Calendar) propertychangeevent.getNewValue(); - DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar2.getLocale()); - jTextField2.setText(dateformat1.format(calendarFin.getTime())); + DateFormat dateformat1 = DateFormat.getDateInstance(1, + jCalendar2.getLocale()); + jTextField2.setText(dateformat1.format(calendarFin + .getTime())); jCalendar2.setCalendar(calendarFin); } - } + } }); this.getContentPane().add(jCalendar2, null); @@ -194,47 +240,56 @@ public class ModifyOfferGUI extends JFrame { jLabel1_o.setText("List of offers:"); jLabel1_o.setBounds(new Rectangle(25, 30, 95, 20)); jLabel1_o.setBounds(25, 44, 95, 20); - + getContentPane().add(jLabel1_o); comboBox_o.setBounds(new Rectangle(115, 30, 115, 20)); comboBox_o.setBounds(115, 44, 115, 20); - + getContentPane().add(comboBox_o); } private void jButton1_actionPerformed(ActionEvent e) { - RuralHouse ruralHouse=((RuralHouse)jComboBox1.getSelectedItem()); - Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime()); - //Remove the hour:minute:second:ms from the date - firstDay=Date.valueOf(firstDay.toString()); - Date lastDay=new Date(jCalendar2.getCalendar().getTime().getTime()); - //Remove the hour:minute:second:ms from the date - lastDay=Date.valueOf(lastDay.toString()); - //It could be to trigger an exception if the introduced string is not a number - float price= Float.parseFloat(jTextField3.getText()); + RuralHouse ruralHouse = ((RuralHouse) jComboBox1.getSelectedItem()); + Date firstDay = new Date(jCalendar1.getCalendar().getTime().getTime()); + // Remove the hour:minute:second:ms from the date + firstDay = Date.valueOf(firstDay.toString()); + Date lastDay = new Date(jCalendar2.getCalendar().getTime().getTime()); + // Remove the hour:minute:second:ms from the date + lastDay = Date.valueOf(lastDay.toString()); + + try { - //Obtain the business logic from a StartWindow class (local or remote) + + // It could be to trigger an exception if the introduced string is + // not a number + float price = Float.parseFloat(jTextField3.getText()); + + // Obtain the business logic from a StartWindow class (local or + // remote) OfferManager offerM = new OfferManager(); - offerM.deleteOffer(ruralHouse, (Offer)comboBox_o.getSelectedItem()); - offerM.createOffer(ruralHouse, firstDay, lastDay, price); + offerM.deleteOffer(ruralHouse, (Offer) comboBox_o.getSelectedItem()); + offerM.createOffer(ruralHouse, firstDay, lastDay, price); - this.setVisible(false); - } - catch (Exception e1) { + jLabel5.setText("Offer modified"); + + } catch (java.lang.NumberFormatException e1) { + jLabel5.setText(jTextField3.getText() + " is not a valid price"); + } catch (BadDates e1) { + jLabel5.setText("Last day is before first day in the offer"); + } catch (Exception e1) { e1.printStackTrace(); } } - + private void jButton2_actionPerformed(ActionEvent e) { this.setVisible(false); } private void jTextField3_focusLost() { try { - new Integer (jTextField3.getText()); + new Integer(jTextField3.getText()); jLabel5.setText(""); - } - catch (NumberFormatException ex) { + } catch (NumberFormatException ex) { jLabel5.setText("Error: Please introduce a number"); } } diff --git a/ruralHouses/src/gui/OffersRelatedOwnerGUI.java b/ruralHouses/src/gui/OffersRelatedOwnerGUI.java index bbe48be..dc28320 100644 --- a/ruralHouses/src/gui/OffersRelatedOwnerGUI.java +++ b/ruralHouses/src/gui/OffersRelatedOwnerGUI.java @@ -35,7 +35,7 @@ public class OffersRelatedOwnerGUI extends JFrame { JButton btnCreateOffers = new JButton("Create Offers"); btnCreateOffers.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - Frame a = new CreateOfferGUI(owner.getRuralHouses()); + Frame a = new AddOffersGUI(owner.getRuralHouses()); a.setVisible(true); } }); diff --git a/ruralHouses/src/gui/QueryAvailabilityGUI2.java b/ruralHouses/src/gui/QueryAvailabilityGUI2.java index fef5d2a..40cfe1c 100644 --- a/ruralHouses/src/gui/QueryAvailabilityGUI2.java +++ b/ruralHouses/src/gui/QueryAvailabilityGUI2.java @@ -209,7 +209,7 @@ public class QueryAvailabilityGUI2 extends JFrame { popupMenu.add(lblNumberOfLivings); popupMenu.add(nLivings); - + this.getContentPane().add(jCalendar2, null); this.getContentPane().add(jCalendar1, null); this.getContentPane().add(jLabel5, null); @@ -286,7 +286,7 @@ public class QueryAvailabilityGUI2 extends JFrame { private void jButton1_actionPerformed(ActionEvent e) { if (this.district.isSelected()) { - Vector houses = houseMan.getHouses(jComboBox1 + Vector houses = houseMan.getHouses(null, jComboBox1 .getSelectedItem().toString(), Integer.parseInt(nBedrooms .getText()), Integer.parseInt(nKitchens.getText()), Integer .parseInt(nBaths.getText()), Integer.parseInt(nParkings @@ -294,22 +294,34 @@ public class QueryAvailabilityGUI2 extends JFrame { listOfHousesGUI list = new listOfHousesGUI(houses); list.setVisible(true); } else if (this.ruralHouseName.isSelected()) { - RuralHouse rh = houseMan.getHouseByName(jTextField3.getText()); - // The next instruction creates a java.sql.Date object from the date selected in the JCalendar object - Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime()); - // The next instruction removes the hour, minute, second and ms from the date - // This has to be made because the date will be stored in db4o as a java.util.Date object - // that would store those data, and that would give problems when comparing dates later - firstDay=Date.valueOf(firstDay.toString()); - - - Date lastDay=new Date(jCalendar2.getCalendar().getTime().getTime()); - //Remove the hour:minute:second:ms from the date - lastDay=Date.valueOf(lastDay.toString()); - if (rh != null) { - HouseFeaturesGUI hou = new HouseFeaturesGUI(rh,firstDay,lastDay); + try { + RuralHouse rh = houseMan.getHouses(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 + Date firstDay = new Date(jCalendar1.getCalendar().getTime() + .getTime()); + // The next instruction removes the hour, minute, second and ms + // from the date + // This has to be made because the date will be stored in db4o + // as a java.util.Date object + // that would store those data, and that would give problems + // when comparing dates later + firstDay = Date.valueOf(firstDay.toString()); + + Date lastDay = new Date(jCalendar2.getCalendar().getTime() + .getTime()); + // Remove the hour:minute:second:ms from the date + lastDay = Date.valueOf(lastDay.toString()); + if(firstDay!=null&&lastDay!=null&&firstDay.before(lastDay)){ + HouseFeaturesGUI hou = new HouseFeaturesGUI(rh, firstDay, + lastDay); hou.setVisible(true); - } else { + }else{ + feedback.setText("Wrong Dates"); + } + + } catch (Exception e1) { feedback.setText("Not matching houses"); } } @@ -318,7 +330,6 @@ public class QueryAvailabilityGUI2 extends JFrame { private void jButton2_actionPerformed(ActionEvent e) { this.setVisible(false); } - private static void addPopup(Component component, final JPopupMenu popup) { component.addMouseListener(new MouseAdapter() { -- 2.20.1