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