import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
import java.sql.Date;
import java.text.DateFormat;
import java.util.Calendar;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
-import businessLogic.HouseManager;
-
import com.toedter.calendar.JCalendar;
+import common.HouseInterface;
+import configuration.___IntNames;
import domain.Districs;
import domain.RuralHouse;
public class QueryAvailabilityGUI2 extends JFrame {
private static final long serialVersionUID = 1L;
- private JComboBox jComboBox1;
+ private JComboBox<String> jComboBox1;
private JLabel jLabel2 = new JLabel();
private JTextField jTextField1 = new JTextField();
private JLabel jLabel3 = new JLabel();
private final JTextField nBaths = new JTextField();
private final JLabel lblParkings = new JLabel("Parking slots:");
private final JTextField nParkings = new JTextField();
- private HouseManager houseMan = new HouseManager();
+ private HouseInterface houseMan = null;
private final JLabel lblNumberOfLivings = new JLabel("Number of Livings:");
private final JTextField nLivings = new JTextField();
private final JLabel feedback = new JLabel("");
public QueryAvailabilityGUI2() {
+
+ try {
+ houseMan = (HouseInterface) Naming
+ .lookup(___IntNames.HouseManager);
+ } catch (Exception e1) {
+ System.out.println("Error accessing remote authentication: "
+ + e1.toString());
+ }
nLivings.setText("0");
nLivings.setColumns(10);
nParkings.setText("0");
this.setSize(new Dimension(550, 500));
this.setTitle("Query Availability");
- jComboBox1 = new JComboBox(new DefaultComboBoxModel(
+ jComboBox1 = new JComboBox<String>(new DefaultComboBoxModel<String>(
Districs.longNames()));
jComboBox1.setEnabled(false);
jComboBox1.setBounds(new Rectangle(115, 30, 115, 20));
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
- .getSelectedItem().toString(), Integer.parseInt(nBedrooms
- .getText()), Integer.parseInt(nKitchens.getText()), Integer
- .parseInt(nBaths.getText()), Integer.parseInt(nParkings
- .getText()), Integer.parseInt(nLivings.getText()));
+ Vector<RuralHouse> houses = null;
+ try {
+ houses = houseMan.getHouses(null, null, jComboBox1
+ .getSelectedItem().toString(), Integer.parseInt(nBedrooms
+ .getText()), Integer.parseInt(nKitchens.getText()), Integer
+ .parseInt(nBaths.getText()), Integer.parseInt(nParkings
+ .getText()), Integer.parseInt(nLivings.getText()));
+ } catch (NumberFormatException | RemoteException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
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(null, 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() {