}
-
- @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<RuralHouse> temp = owner.getRuralHouses();
+ public void removeHouse(RuralHouse rh, Owner owner) {
+ Vector<RuralHouse> temp = owner.getRuralHouses();
temp.remove(rh);
this.dbMngr.removeHouse(rh, owner);
}
- @Override
- public Vector<RuralHouse> getHousesByDistrict(String town) {
-
- 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);
- }
-
+ public Vector<RuralHouse> 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<RuralHouse> getAllRuralHouses() throws RemoteException,
- @Override
- public RuralHouse getHouseByName(String Name) {
- return this.dbMngr.getRuralHouseByName(Name);
- }
-
-
-
-
-
// For future implementation
// @Override
// public void modifyHouse(int houseName, Owner owner, String description,
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,
public void removeHouse(RuralHouse rh, Owner owner);
- public Vector<RuralHouse> getHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv) ;
+ public Vector<RuralHouse> getHouses(String name,String town,int nBed , int nKit, int nBath, int nPark, int nLiv) ;
- /**
- * @param district
- * @return
- */
- public Vector<RuralHouse> getHousesByDistrict(String district);
-
-
- public RuralHouse getHouseByName(String Name);
/**
* This method retrieves the existing rural houses
*
public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
Exception;
- boolean registerNewHouse(RuralHouse rh);
+ public boolean registerNewHouse(RuralHouse rh);
}
*/
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) {
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);
}
}
//import java.util.Enumeration;
//import java.util.Vector;
import java.rmi.RemoteException;
+
+
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
+
import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
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);
+
Account admin = new Account("admin","admin", true);
db.store(Administrator.giveAdmin());
db.store(jon);
db.close();
}
}
-
-
public Offer createOffer(RuralHouse ruralHouse, Date firstDay,
Date lastDay, float price) throws RemoteException, Exception {
RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(), null,
null, null, null);
- ObjectSet result = db.queryByExample(proto);
+ ObjectSet<RuralHouse> result = db.queryByExample(proto);
RuralHouse rh = (RuralHouse) result.next();
o = rh.createOffer(theDB4oManagerAux.offerNumber++, firstDay,
lastDay, price);
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();
openDB();
try {
-
+ ObjectSet<Offer> 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) {
try {
Owner proto = new Owner(null, null);
- ObjectSet result = db.queryByExample(proto);
+ ObjectSet<Owner> result = db.queryByExample(proto);
Vector<Owner> owners = new Vector<Owner>();
while (result.hasNext())
owners.add((Owner) result.next());
db.store(rh);
db.commit();
stored = true;
+ } else {
+ db.delete(result.get(0));
+ db.store(rh);
+ db.commit();
+ stored = true;
}
} finally {
db.close();
else
openDB();
try {
- ObjectSet<RuralHouse> result = db.queryByExample(rh);
- if (!result.isEmpty()) {
- RuralHouse found = (RuralHouse) result.get(0);
- // db.delete(found.getOwner());
- db.store(owner);
- db.delete(found);
+ ObjectSet<Owner> result = db.queryByExample(owner);
+ ObjectSet<RuralHouse> 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) {
}
- public Vector<RuralHouse> getRuralHousesByTown(String town) {
- RuralHouse rh = new RuralHouse(null, null, null, town, null);
-
- 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());
- 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<RuralHouse> result = db.queryByExample(rh);
- Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
- 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<RuralHouse> getRuralHouses(String town, int nBed, int nKit,
- int nBath, int nPark, int nLiv) {
+ public Vector<RuralHouse> 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
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
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;
//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");
+++ /dev/null
-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<RuralHouse> v) {
- try {
- jbInit(v);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private void jbInit(Vector<RuralHouse> 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
import domain.Offer;
import domain.Owner;
import domain.RuralHouse;
+import javax.swing.LayoutStyle.ComponentPlacement;
+import javax.swing.JTextField;
public class DeleteOfferGUI extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private Owner owner;
+ private JLabel feedback;
private JComboBox<RuralHouse> comboBox;
private JComboBox<Offer> comboBox_1;
private JButton btnDelete;
-
/**
* Create the frame.
*/
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
-
+
comboBox = new JComboBox<RuralHouse>(this.owner.getRuralHouses());
-
-
-
+ comboBox.setBounds(101, 38, 314, 20);
+
comboBox_1 = new JComboBox<Offer>();
+ comboBox_1.setBounds(101, 76, 314, 20);
+ Vector<Offer> 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<Offer> vo = ((RuralHouse)comboBox.getSelectedItem()).offers;
+ Vector<Offer> 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);
+
}
}
private JTextField baths_f;
private JTable table;
private DefaultTableModel tableModel;
- private DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer();
private RuralHouse rh;
private JTextField telIn;
private int row;
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);
}
});
- 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);
import javax.swing.border.EmptyBorder;
import businessLogic.HouseManager;
+import domain.HouseFeatures;
import domain.Owner;
import domain.RuralHouse;
private Owner owner;
private JLabel lblDistrict;
private JTextField District_f;
+ private JLabel feedback;
private JLabel lblDescription;
private JTextField description_f;
private JLabel lblKitchen;
private JComboBox<RuralHouse> houseBox;
private RuralHouse rh;
-
/**
* Create the frame.
*/
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);
- //TODO registernewhouse must check before if the house is created to delete it before creating it.
- 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<RuralHouse>(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);
}
}
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<RuralHouse> jComboBox1;
private final JLabel jLabel1_o = new JLabel();
private JComboBox<Offer> comboBox_o;
- public ModifyOfferGUI(Vector<RuralHouse> v) {
- try {
+ public ModifyOfferGUI(Vector<RuralHouse> v) {
+ try {
jbInit(v);
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
}
}
this.setTitle("Set availability");
jComboBox1 = new JComboBox<RuralHouse>(v);
-
- comboBox_o = new JComboBox<Offer>(((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<Offer>(
+ ((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));
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<Offer> vo = ((RuralHouse)jComboBox1.getSelectedItem()).offers;
+ Vector<Offer> 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);
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);
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");
}
}
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);
}
});
popupMenu.add(lblNumberOfLivings);
popupMenu.add(nLivings);
-
+
this.getContentPane().add(jCalendar2, null);
this.getContentPane().add(jCalendar1, null);
this.getContentPane().add(jLabel5, null);
private void jButton1_actionPerformed(ActionEvent e) {
if (this.district.isSelected()) {
- Vector<RuralHouse> houses = houseMan.getHouses(jComboBox1
+ Vector<RuralHouse> houses = houseMan.getHouses(null, jComboBox1
.getSelectedItem().toString(), Integer.parseInt(nBedrooms
.getText()), Integer.parseInt(nKitchens.getText()), Integer
.parseInt(nBaths.getText()), Integer.parseInt(nParkings
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");
}
}
private void jButton2_actionPerformed(ActionEvent e) {
this.setVisible(false);
}
-
private static void addPopup(Component component, final JPopupMenu popup) {
component.addMouseListener(new MouseAdapter() {