From: Eneko Pinzolas Murua Date: Mon, 27 Apr 2015 12:01:38 +0000 (+0200) Subject: Started creating the booking interface for the owners. X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/d7fd1754bcc5ee9a9e87e27c0fde6c2b020f4bfd Started creating the booking interface for the owners. --- diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 6b4dd25..c594b1c 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -81,6 +81,7 @@ public class DB4oManager { configuration.common().activationDepth(c.getActivationDepth()); configuration.common().updateDepth(c.getUpdateDepth()); configuration.common().objectClass(Owner.class).cascadeOnUpdate(true); + configuration.common().objectClass(Owner.class).cascadeOnDelete(true); configuration.common().objectClass(RuralHouse.class).cascadeOnUpdate(true); configuration.common().objectClass(Account.class).cascadeOnUpdate(true); db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename()); @@ -128,14 +129,12 @@ public class DB4oManager { alfredo.addRuralHouse("Murgoitz", "", "Cedro", 6, 6, 6, 6, 6); alfredo.setBankAccount("4144 0087 23 9700002133"); - Account jonAcc = new Account("userJon", "passJon", jon); + Account jonAcc = new Account("1", "1", jon); Account alfredoAcc = new Account("userAlfredo", "passAlfredo", alfredo); Account admin = new Account("admin","admin", true); db.store(Administrator.giveAdmin()); - db.store(jon); - db.store(alfredo); db.store(jonAcc); db.store(alfredoAcc); db.store(admin); @@ -464,12 +463,9 @@ public class DB4oManager { ObjectSet result = db.queryByExample(house); if (result.isEmpty()) { Owner ow = (Owner) db.queryByExample(rh.getOwner()).get(0); - ObjectSet orh = db.queryByExample(new RuralHouse(null, ow, null, null, null)); + rh.setOwner(ow); ow.addRuralHouse(rh); - for (RuralHouse aa: orh){ - aa.setOwner(ow); - } - db.store(ow); + db.store(rh); db.commit(); stored = true; } else { diff --git a/ruralHouses/src/domain/RuralHouse.java b/ruralHouses/src/domain/RuralHouse.java index 02ab6f9..4f73bb9 100644 --- a/ruralHouses/src/domain/RuralHouse.java +++ b/ruralHouses/src/domain/RuralHouse.java @@ -82,6 +82,8 @@ public class RuralHouse implements Serializable { return off; } + + @Override public boolean equals(Object obj) { if (this == obj) @@ -91,7 +93,10 @@ public class RuralHouse implements Serializable { if (getClass() != obj.getClass()) return false; RuralHouse other = (RuralHouse) obj; - if (houseName != other.houseName) + if (houseName == null) { + if (other.houseName != null) + return false; + } else if (!houseName.equals(other.houseName)) return false; return true; } @@ -171,8 +176,5 @@ public class RuralHouse implements Serializable { } - public boolean equals(RuralHouse oRh) { - return this.getHouseName().equals(oRh.getHouseName()); - } } diff --git a/ruralHouses/src/gui/HouseFeaturesGUI.java b/ruralHouses/src/gui/HouseFeaturesGUI.java index a8643e4..28097a7 100644 --- a/ruralHouses/src/gui/HouseFeaturesGUI.java +++ b/ruralHouses/src/gui/HouseFeaturesGUI.java @@ -252,6 +252,7 @@ public class HouseFeaturesGUI extends JFrame { BookingManager bookingM = new BookingManager(); //RegExp to see if telephone number is correct??TODO if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}")) { + labelPhone.setText(""); Booking book = null; try { if (table.getRowCount()!=0) diff --git a/ruralHouses/src/gui/ModifyHouseGUI.java b/ruralHouses/src/gui/ModifyHouseGUI.java index 393a707..06b679e 100644 --- a/ruralHouses/src/gui/ModifyHouseGUI.java +++ b/ruralHouses/src/gui/ModifyHouseGUI.java @@ -135,10 +135,8 @@ public class ModifyHouseGUI extends JFrame { HouseManager hm = new HouseManager(); if (hm.registerNewHouse(newRh)) { - owner.getRuralHouses().remove(rh); owner.getRuralHouses().add(newRh); houseBox.removeItem(rh); - hm.removeHouse(rh, o); feedback.setText("House properly modified"); } else feedback.setText("Imposible to modify the house"); diff --git a/ruralHouses/src/gui/RequestNewHouseGUI.java b/ruralHouses/src/gui/RequestNewHouseGUI.java index ba4eca9..76b2465 100644 --- a/ruralHouses/src/gui/RequestNewHouseGUI.java +++ b/ruralHouses/src/gui/RequestNewHouseGUI.java @@ -123,14 +123,14 @@ public class RequestNewHouseGUI extends JFrame { //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that. rh = new RuralHouse(Code_f.getText(), owner, description_f.getText(), - (String) comboBox.getSelectedItem() ,new HouseFeatures(Integer.parseInt(rooms_f.getText()), + (String) comboBox.getSelectedItem(), new HouseFeatures(Integer.parseInt(rooms_f.getText()), Integer.parseInt(kitchens_f.getText()), Integer.parseInt(baths_f.getText()), Integer.parseInt(lRooms_f.getText()), Integer.parseInt(parkings_f.getText())) ); } - catch(NumberFormatException e ){ + catch(NumberFormatException e){ e.printStackTrace(); } diff --git a/ruralHouses/src/gui/listOfAdditionRequestsGUI.java b/ruralHouses/src/gui/listOfAdditionRequestsGUI.java index db65fb2..cd501b5 100644 --- a/ruralHouses/src/gui/listOfAdditionRequestsGUI.java +++ b/ruralHouses/src/gui/listOfAdditionRequestsGUI.java @@ -97,8 +97,23 @@ public class listOfAdditionRequestsGUI extends JFrame { } } }); - btnNewButton.setBounds(301, 394, 169, 25); + btnNewButton.setBounds(88, 396, 169, 25); contentPane.add(btnNewButton); + + JButton btnDenyAddition = new JButton("Deny Addition"); + btnDenyAddition.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + if (table.getRowCount()!=0 && table.getSelectedRow() != -1) { + RuralHouse rh = houses.get(table.getSelectedRow()); + am.removeHouseAdditionRequests(rh); + Administrator.saveInstance(); + ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); + houses.remove(rh); + } + } + }); + btnDenyAddition.setBounds(300, 396, 169, 25); + contentPane.add(btnDenyAddition); Enumeration en = houses.elements(); RuralHouse rh; diff --git a/ruralHouses/src/gui/listOfBookingRequestsGUI.java b/ruralHouses/src/gui/listOfBookingRequestsGUI.java new file mode 100644 index 0000000..7495777 --- /dev/null +++ b/ruralHouses/src/gui/listOfBookingRequestsGUI.java @@ -0,0 +1,133 @@ +package gui; + +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Enumeration; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.border.EmptyBorder; +import javax.swing.table.DefaultTableModel; + +import businessLogic.AdminManager; +import businessLogic.HouseManager; +import businessLogic.HouseManagerInterface; +import domain.Administrator; +import domain.RuralHouse; + +public class listOfBookingRequestsGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTable table; + private DefaultTableModel tableModel; + private AdminManager am = new AdminManager(); + private Vector houses; + /** + * Create the frame. + */ + public listOfBookingRequestsGUI() { + setTitle("Adding requests"); + try { + this.houses= am.getAdditionRequests(); + init(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void init() 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(); + lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); + lblNewLabel.setBounds(23, 41, 536, 33); + contentPane.add(lblNewLabel); + if (houses.isEmpty()) + lblNewLabel.setText("There are not houses to be added"); + else + lblNewLabel.setText("List of houses to be added:"); + JScrollPane scrollPane = new JScrollPane(); + scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); + scrollPane.setBounds(23, 113, 536, 271); + contentPane.add(scrollPane); + + table = new JTable() { + private static final long serialVersionUID = 1L; + + public boolean isCellEditable(int row, int column) { + return false; + }; + }; + scrollPane.setViewportView(table); + 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); + + JButton btnNewButton = new JButton("Confirm Addition"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (table.getRowCount()!=0 && table.getSelectedRow() != -1) { + HouseManagerInterface hm = new HouseManager(); + RuralHouse rh = houses.get(table.getSelectedRow()); + //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that. + hm.registerNewHouse(rh); + am.removeHouseAdditionRequests(rh); + Administrator.saveInstance(); + ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); + houses.remove(rh); + } + } + }); + btnNewButton.setBounds(88, 396, 169, 25); + contentPane.add(btnNewButton); + + JButton btnDenyAddition = new JButton("Deny Addition"); + btnDenyAddition.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + if (table.getRowCount()!=0 && table.getSelectedRow() != -1) { + RuralHouse rh = houses.get(table.getSelectedRow()); + am.removeHouseAdditionRequests(rh); + Administrator.saveInstance(); + ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); + houses.remove(rh); + } + } + }); + btnDenyAddition.setBounds(300, 396, 169, 25); + contentPane.add(btnDenyAddition); + Enumeration en = houses.elements(); + RuralHouse rh; + + while (en.hasMoreElements()) { + rh = en.nextElement(); + Vector row = new Vector(); + 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()); + tableModel.addRow(row); + } + + } +} diff --git a/ruralHouses/src/gui/listOfRemovalRequestsGUI.java b/ruralHouses/src/gui/listOfRemovalRequestsGUI.java index 53cb7e6..43db732 100644 --- a/ruralHouses/src/gui/listOfRemovalRequestsGUI.java +++ b/ruralHouses/src/gui/listOfRemovalRequestsGUI.java @@ -84,7 +84,7 @@ public class listOfRemovalRequestsGUI extends JFrame { JButton btnNewButton = new JButton("Confirm Deletion"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - if (table.getRowCount() != 0) { + if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { HouseManagerInterface hm = new HouseManager(); RuralHouse rh = houses.get(table.getSelectedRow()); ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); @@ -97,8 +97,25 @@ public class listOfRemovalRequestsGUI extends JFrame { } } }); - btnNewButton.setBounds(301, 394, 169, 25); + btnNewButton.setBounds(90, 396, 169, 25); contentPane.add(btnNewButton); + + JButton btnNewButton_1 = new JButton("Deny Deletion"); + btnNewButton_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { + RuralHouse rh = houses.get(table.getSelectedRow()); + ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); + houses.remove(rh); + am.removeHouseDeletionRequests(rh); + Administrator.saveInstance(); + + + } + } + }); + btnNewButton_1.setBounds(291, 396, 169, 25); + contentPane.add(btnNewButton_1); while (en.hasMoreElements()) { rh = en.nextElement(); Vector row = new Vector();