From: Eneko Pinzolas Murua Date: Sun, 12 Apr 2015 18:11:42 +0000 (+0200) Subject: Model modified so that owners now request for a new house insetion or a house removal... X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/66f0c834c28b40aeac91b173d6def82e24c3b02b Model modified so that owners now request for a new house insetion or a house removal. Furthermore, all Administrator GUI and bussines logic create. However, Login GUI and BussinesLogic are to be modified so that they integrate Admin identification. --- diff --git a/ruralHouses/src/businessLogic/AdminManager.java b/ruralHouses/src/businessLogic/AdminManager.java new file mode 100644 index 0000000..7c827ae --- /dev/null +++ b/ruralHouses/src/businessLogic/AdminManager.java @@ -0,0 +1,31 @@ +package businessLogic; + +import java.util.Vector; + +import domain.RuralHouse; +import domain.Administrator; + +public class AdminManager { + public AdminManager (){ + + } + public Vector getAdditionRequests(){ + return new Vector(Administrator.getAddRequest()); + } + + public Vector getDeletionRequests(){ + return new Vector(Administrator.getRemoveRequest()); + } + public void removeHouseAdditionRequests(RuralHouse house){ + Administrator.getAddRequest().remove(house); + } + public void removeHouseDeletionRequests(RuralHouse house){ + Administrator.getRemoveRequest().remove(house); + } + public void addAdditionRequest(RuralHouse rh){ + Administrator.getAddRequest().add(rh); + } + public void addDeletionRequest(RuralHouse rh){ + Administrator.getRemoveRequest().add(rh); + } +} diff --git a/ruralHouses/src/businessLogic/HouseManager.java b/ruralHouses/src/businessLogic/HouseManager.java index 70e8985..c87db68 100644 --- a/ruralHouses/src/businessLogic/HouseManager.java +++ b/ruralHouses/src/businessLogic/HouseManager.java @@ -41,8 +41,17 @@ public class HouseManager implements HouseManagerInterface { stored = this.dbMngr.storeRuralHouses(rh); return stored; } - + @Override + + public boolean registerNewHouse(RuralHouse rh) { + + boolean stored = false; + + rh.getOwner().getRuralHouses().add(rh); + stored = this.dbMngr.storeRuralHouses(rh); + return stored; + } public void removeHouse(RuralHouse rh , Owner owner) { diff --git a/ruralHouses/src/businessLogic/HouseManagerInterface.java b/ruralHouses/src/businessLogic/HouseManagerInterface.java index 321b82e..4a0ba9a 100644 --- a/ruralHouses/src/businessLogic/HouseManagerInterface.java +++ b/ruralHouses/src/businessLogic/HouseManagerInterface.java @@ -40,5 +40,7 @@ public interface HouseManagerInterface { */ public Vector getAllRuralHouses()throws RemoteException, Exception; + + boolean registerNewHouse(RuralHouse rh); } diff --git a/ruralHouses/src/domain/Administrator.java b/ruralHouses/src/domain/Administrator.java index 8a554de..15d5e48 100644 --- a/ruralHouses/src/domain/Administrator.java +++ b/ruralHouses/src/domain/Administrator.java @@ -4,22 +4,16 @@ import java.util.LinkedList; public class Administrator { - private LinkedList addRequest; - private LinkedList removeRequest; - + private static LinkedList addRequest = new LinkedList(); + private static LinkedList removeRequest = new LinkedList(); private Administrator(){ } - - public LinkedList getAddRequest() { + + public static LinkedList getAddRequest() { return addRequest; } - public void setAddRequest(LinkedList addRequest) { - this.addRequest = addRequest; - } - public LinkedList getRemoveRequest() { + public static LinkedList getRemoveRequest() { return removeRequest; } - public void setRemoveRequest(LinkedList removeRequest) { - this.removeRequest = removeRequest; - } + } diff --git a/ruralHouses/src/gui/AdminMenuGUI.java b/ruralHouses/src/gui/AdminMenuGUI.java new file mode 100644 index 0000000..f8d9d85 --- /dev/null +++ b/ruralHouses/src/gui/AdminMenuGUI.java @@ -0,0 +1,79 @@ +package gui; + +import java.awt.Frame; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.JButton; + +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class AdminMenuGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + + + public static void main(String[] args){ + Frame a = new AdminMenuGUI(); + a.setVisible(true); + } + /** + * Create the frame. + */ + public AdminMenuGUI() { + + + + this.setTitle("Owner Menu"); + this.getContentPane().setLayout(null); + setBounds(100, 100, 450, 473); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + //TODO BOTH BUTTONS ARE TO MODIFY + JButton btnAdd = new JButton("Add Requests"); + btnAdd.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Frame a = new listOfAdditionRequestsGUI(); + a.setVisible(true); + } + }); + + JButton btnDel = new JButton("Delete Requests"); + btnDel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Frame a = new listOfRemovalRequestsGUI(); + a.setVisible(true); + } + }); + GroupLayout gl_contentPane = new GroupLayout(contentPane); + gl_contentPane.setHorizontalGroup( + gl_contentPane.createParallelGroup(Alignment.LEADING) + .addGroup(gl_contentPane.createSequentialGroup() + .addGap(115) + .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING) + .addComponent(btnDel, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE) + .addComponent(btnAdd, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)) + .addContainerGap(145, Short.MAX_VALUE)) + ); + gl_contentPane.setVerticalGroup( + gl_contentPane.createParallelGroup(Alignment.LEADING) + .addGroup(gl_contentPane.createSequentialGroup() + .addGap(62) + .addComponent(btnAdd, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) + .addGap(58) + .addComponent(btnDel, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) + .addContainerGap(142, Short.MAX_VALUE)) + ); + contentPane.setLayout(gl_contentPane); + } + +} diff --git a/ruralHouses/src/gui/HousesRelatedOwnerGUI.java b/ruralHouses/src/gui/HousesRelatedOwnerGUI.java index a7d292f..c0f9ec9 100644 --- a/ruralHouses/src/gui/HousesRelatedOwnerGUI.java +++ b/ruralHouses/src/gui/HousesRelatedOwnerGUI.java @@ -43,7 +43,7 @@ public class HousesRelatedOwnerGUI extends JFrame { JButton btnCreateHouses = new JButton("Create Houses"); btnCreateHouses.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - Frame a = new NewHouseGUI(owner); + Frame a = new RequestNewHouseGUI(owner); a.setVisible(true); } }); @@ -61,7 +61,7 @@ public class HousesRelatedOwnerGUI extends JFrame { JButton btnDeleteHouses = new JButton("Delete Houses"); btnDeleteHouses.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - Frame a = new DeleteHouseGUI(owner); + Frame a = new RequestDeleteHouseGUI(owner); a.setVisible(true); } }); diff --git a/ruralHouses/src/gui/DeleteHouseGUI.java b/ruralHouses/src/gui/RequestDeleteHouseGUI.java similarity index 91% rename from ruralHouses/src/gui/DeleteHouseGUI.java rename to ruralHouses/src/gui/RequestDeleteHouseGUI.java index 82f9e0f..539c9e4 100644 --- a/ruralHouses/src/gui/DeleteHouseGUI.java +++ b/ruralHouses/src/gui/RequestDeleteHouseGUI.java @@ -17,23 +17,25 @@ import javax.swing.JComboBox; import javax.swing.JRadioButton; import javax.swing.JButton; +import businessLogic.AdminManager; import businessLogic.HouseManager; import businessLogic.HouseManagerInterface; import domain.Owner; import domain.RuralHouse; -public class DeleteHouseGUI extends JFrame { +public class RequestDeleteHouseGUI extends JFrame { private JPanel contentPane; private Owner owner; private JComboBox comboBox; private JButton btnDelete; - + private AdminManager am; /** * Create the frame. */ - public DeleteHouseGUI(Owner o) { + public RequestDeleteHouseGUI(Owner o) { + am = new AdminManager(); this.owner = o; setBounds(100, 100, 450, 300); contentPane = new JPanel(); @@ -45,7 +47,7 @@ public class DeleteHouseGUI extends JFrame { JRadioButton rdbtnIAmSure = new JRadioButton("I am sure"); - btnDelete = new JButton("DELETE"); + btnDelete = new JButton("REQUEST"); btnDelete.setEnabled(false); rdbtnIAmSure.addItemListener(new ItemListener() { @@ -103,8 +105,6 @@ public class DeleteHouseGUI extends JFrame { private void actionListenerButton(ActionEvent e){ RuralHouse toDel = (RuralHouse)comboBox.getSelectedItem(); - HouseManagerInterface hm = new HouseManager(); - hm.removeHouse(toDel,this.owner); - comboBox.removeItem(toDel); + am.addDeletionRequest(toDel); } } diff --git a/ruralHouses/src/gui/NewHouseGUI.java b/ruralHouses/src/gui/RequestNewHouseGUI.java similarity index 95% rename from ruralHouses/src/gui/NewHouseGUI.java rename to ruralHouses/src/gui/RequestNewHouseGUI.java index b4639f4..39725c6 100644 --- a/ruralHouses/src/gui/NewHouseGUI.java +++ b/ruralHouses/src/gui/RequestNewHouseGUI.java @@ -25,10 +25,11 @@ import java.awt.event.ActionEvent; import javax.swing.JTextPane; +import businessLogic.AdminManager; import businessLogic.HouseManager; import businessLogic.HouseManagerInterface; -public class NewHouseGUI extends JFrame { +public class RequestNewHouseGUI extends JFrame { /** * @@ -53,12 +54,15 @@ public class NewHouseGUI extends JFrame { private JLabel lblBaths; private JTextField baths_f; private JButton btnRegister; + private AdminManager am; /** * Create the frame. */ - public NewHouseGUI(Owner o) { + public RequestNewHouseGUI(Owner o) { + + am = new AdminManager(); this.setTitle("New House"); setBackground(Color.WHITE); this.getContentPane().setLayout(null); @@ -118,24 +122,26 @@ public class NewHouseGUI extends JFrame { baths_f = new JTextField(); baths_f.setColumns(10); - btnRegister = new JButton("Register House"); + btnRegister = new JButton("Request registration"); btnRegister.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { + RuralHouse rh = null; try { - HouseManagerInterface hm = new HouseManager(); //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that. - hm.registerNewHouse(Code_f.getText(), + rh = new RuralHouse(Code_f.getText(), owner, description_f.getText(), - Town_f.getText() ,Integer.parseInt(rooms_f.getText()), + Town_f.getText() ,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()) ); + Integer.parseInt(parkings_f.getText())) ); } catch(NumberFormatException e ){ e.printStackTrace(); } + + am.addAdditionRequest(rh); } }); GroupLayout gl_contentPane = new GroupLayout(contentPane); diff --git a/ruralHouses/src/gui/listOfAdditionRequestsGUI.java b/ruralHouses/src/gui/listOfAdditionRequestsGUI.java new file mode 100644 index 0000000..4ab671f --- /dev/null +++ b/ruralHouses/src/gui/listOfAdditionRequestsGUI.java @@ -0,0 +1,127 @@ +package gui; + +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.JLabel; + +import java.awt.Font; + +import javax.swing.JTextField; +import javax.swing.JScrollPane; + +import java.awt.Rectangle; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +import java.awt.Component; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.sql.Date; +import java.util.Enumeration; +import java.util.LinkedList; +import java.util.Vector; + +import javax.swing.Box; +import javax.swing.JButton; + +import businessLogic.AdminManager; +import businessLogic.HouseManager; +import businessLogic.HouseManagerInterface; + +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class listOfAdditionRequestsGUI extends JFrame { + + private JPanel contentPane; + private JTable table; + private DefaultTableModel tableModel; + private AdminManager am = new AdminManager(); + private Vector houses; + /** + * Create the frame. + */ + public listOfAdditionRequestsGUI() { + 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 matching your search"); + else + lblNewLabel.setText("List of houses that match your search:"); + 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) { + 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); + houses.remove(rh); + am.removeHouseAdditionRequests(rh); + } + } + }); + btnNewButton.setBounds(301, 394, 169, 25); + contentPane.add(btnNewButton); + 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 new file mode 100644 index 0000000..fbde5a4 --- /dev/null +++ b/ruralHouses/src/gui/listOfRemovalRequestsGUI.java @@ -0,0 +1,124 @@ +package gui; + +import java.awt.BorderLayout; +import java.awt.EventQueue; + +import domain.*; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JLabel; + +import java.awt.Font; + +import javax.swing.JTextField; +import javax.swing.JScrollPane; + +import java.awt.Rectangle; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.sql.Date; +import java.util.Enumeration; +import java.util.LinkedList; +import java.util.Vector; + +import javax.swing.Box; + +import businessLogic.AdminManager; +import businessLogic.HouseManager; +import businessLogic.HouseManagerInterface; + +public class listOfRemovalRequestsGUI extends JFrame { + + private JPanel contentPane; + private JTable table; + private DefaultTableModel tableModel; + private AdminManager am = new AdminManager(); + private Vector houses; + /** + * Create the frame. + */ + public listOfRemovalRequestsGUI() { + try { + this.houses= am.getDeletionRequests(); + 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 matching your search"); + else + lblNewLabel.setText("List of houses that match your search:"); + 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); + Enumeration en = houses.elements(); + RuralHouse rh; + JButton btnNewButton = new JButton("Confirm Deletion"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (table.getRowCount()!=0) { + 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.removeHouse(rh, rh.getOwner()); + houses.remove(rh); + am.removeHouseDeletionRequests(rh); + } + } + }); + btnNewButton.setBounds(301, 394, 169, 25); + contentPane.add(btnNewButton); + 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); + } + + } +}