Model modified so that owners now request for a new house insetion or a house removal...
authorEneko Pinzolas Murua <kelossus@localhost.localdomain>
Sun, 12 Apr 2015 18:11:42 +0000 (20:11 +0200)
committerEneko Pinzolas Murua <kelossus@localhost.localdomain>
Sun, 12 Apr 2015 18:11:42 +0000 (20:11 +0200)
ruralHouses/src/businessLogic/AdminManager.java [new file with mode: 0644]
ruralHouses/src/businessLogic/HouseManager.java
ruralHouses/src/businessLogic/HouseManagerInterface.java
ruralHouses/src/domain/Administrator.java
ruralHouses/src/gui/AdminMenuGUI.java [new file with mode: 0644]
ruralHouses/src/gui/HousesRelatedOwnerGUI.java
ruralHouses/src/gui/RequestDeleteHouseGUI.java [moved from ruralHouses/src/gui/DeleteHouseGUI.java with 91% similarity]
ruralHouses/src/gui/RequestNewHouseGUI.java [moved from ruralHouses/src/gui/NewHouseGUI.java with 95% similarity]
ruralHouses/src/gui/listOfAdditionRequestsGUI.java [new file with mode: 0644]
ruralHouses/src/gui/listOfRemovalRequestsGUI.java [new file with mode: 0644]

diff --git a/ruralHouses/src/businessLogic/AdminManager.java b/ruralHouses/src/businessLogic/AdminManager.java
new file mode 100644 (file)
index 0000000..7c827ae
--- /dev/null
@@ -0,0 +1,31 @@
+package businessLogic;
+
+import java.util.Vector;
+
+import domain.RuralHouse;
+import domain.Administrator;
+
+public class AdminManager {
+       public AdminManager (){
+               
+       }
+       public Vector<RuralHouse> getAdditionRequests(){
+               return new Vector<RuralHouse>(Administrator.getAddRequest());
+       }
+       
+       public Vector<RuralHouse> getDeletionRequests(){
+               return new Vector<RuralHouse>(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);
+       }
+}
index 70e8985..c87db68 100644 (file)
@@ -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) {
index 321b82e..4a0ba9a 100644 (file)
@@ -40,5 +40,7 @@ public interface HouseManagerInterface {
         */
        public Vector<RuralHouse> getAllRuralHouses()throws RemoteException,
        Exception;
+
+       boolean registerNewHouse(RuralHouse rh);
        
 }
index 8a554de..15d5e48 100644 (file)
@@ -4,22 +4,16 @@ import java.util.LinkedList;
 
 public class Administrator {
 
-       private LinkedList<RuralHouse> addRequest;
-       private LinkedList<RuralHouse> removeRequest;
-       
+       private static LinkedList<RuralHouse> addRequest = new LinkedList<RuralHouse>();
+       private static LinkedList<RuralHouse> removeRequest = new LinkedList<RuralHouse>();
        private Administrator(){
        }
-       
-       public LinkedList<RuralHouse> getAddRequest() {
+
+       public static LinkedList<RuralHouse> getAddRequest() {
                return addRequest;
        }
-       public void setAddRequest(LinkedList<RuralHouse> addRequest) {
-               this.addRequest = addRequest;
-       }
-       public LinkedList<RuralHouse> getRemoveRequest() {
+       public static LinkedList<RuralHouse> getRemoveRequest() {
                return removeRequest;
        }
-       public void setRemoveRequest(LinkedList<RuralHouse> removeRequest) {
-               this.removeRequest = removeRequest;
-       }
+
 }
diff --git a/ruralHouses/src/gui/AdminMenuGUI.java b/ruralHouses/src/gui/AdminMenuGUI.java
new file mode 100644 (file)
index 0000000..f8d9d85
--- /dev/null
@@ -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);
+       }
+
+}
index a7d292f..c0f9ec9 100644 (file)
@@ -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);
                        }
                });
similarity index 91%
rename from ruralHouses/src/gui/DeleteHouseGUI.java
rename to ruralHouses/src/gui/RequestDeleteHouseGUI.java
index 82f9e0f..539c9e4 100644 (file)
@@ -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);
        }
 }
similarity index 95%
rename from ruralHouses/src/gui/NewHouseGUI.java
rename to ruralHouses/src/gui/RequestNewHouseGUI.java
index b4639f4..39725c6 100644 (file)
@@ -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 (file)
index 0000000..4ab671f
--- /dev/null
@@ -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<RuralHouse> 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<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());
+                       tableModel.addRow(row);
+               }
+
+       }
+}
diff --git a/ruralHouses/src/gui/listOfRemovalRequestsGUI.java b/ruralHouses/src/gui/listOfRemovalRequestsGUI.java
new file mode 100644 (file)
index 0000000..fbde5a4
--- /dev/null
@@ -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<RuralHouse> 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<RuralHouse> 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<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());
+                       tableModel.addRow(row);
+               }
+
+       }
+}