DeleteOffers and Modify Offers completed, both logic and GUI
authorEneko Pinzolas Murua <kelossus@localhost.localdomain>
Sat, 4 Apr 2015 12:23:48 +0000 (14:23 +0200)
committerEneko Pinzolas Murua <kelossus@localhost.localdomain>
Sat, 4 Apr 2015 12:23:48 +0000 (14:23 +0200)
ruralHouses/src/businessLogic/OfferManager.java
ruralHouses/src/domain/Offer.java
ruralHouses/src/gui/CreateOfferGUI.java [moved from ruralHouses/src/gui/IntroduceOffer2GUI.java with 98% similarity]
ruralHouses/src/gui/DeleteOfferGUI.java
ruralHouses/src/gui/ModifyOfferGUI.java [new file with mode: 0644]
ruralHouses/src/gui/OffersRelatedOwnerGUI.java
ruralHouses/src/gui/OwnerMenuGUI.java

index 6d35620..c286a40 100644 (file)
@@ -66,7 +66,10 @@ public final class OfferManager {
                if (firstDay.compareTo(lastDay)>=0) throw new BadDates();
 
                boolean b = dbMngr.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated
                if (firstDay.compareTo(lastDay)>=0) throw new BadDates();
 
                boolean b = dbMngr.existsOverlappingOffer(ruralHouse,firstDay,lastDay); // The ruralHouse object in the client may not be updated
-               if (!b) return dbMngr.createOffer(ruralHouse,firstDay,lastDay,price);                   
+               if (!b) {
+                       ruralHouse.createOffer(offerNumber, firstDay, lastDay, price);
+                       return dbMngr.createOffer(ruralHouse,firstDay,lastDay,price);                   
+               }
                return null;
        }
 
                return null;
        }
 
index c0dfade..7a6d7de 100644 (file)
@@ -141,6 +141,6 @@ public class Offer implements Serializable {
        }
        
        public String toString(){
        }
        
        public String toString(){
-               return offerNumber+";"+firstDay.toString()+";"+lastDay.toString()+";"+price+";"+ruralHouse;
+               return firstDay.toString()+", "+lastDay.toString()+", "+price;
        }
 }
\ No newline at end of file
        }
 }
\ No newline at end of file
similarity index 98%
rename from ruralHouses/src/gui/IntroduceOffer2GUI.java
rename to ruralHouses/src/gui/CreateOfferGUI.java
index db1e2fe..a6f07d9 100644 (file)
@@ -17,7 +17,7 @@ import com.toedter.calendar.JCalendar;
 
 import domain.RuralHouse;
 
 
 import domain.RuralHouse;
 
-public class IntroduceOffer2GUI extends JFrame  {
+public class CreateOfferGUI extends JFrame  {
        
        private static final long serialVersionUID = 1L;
 
        
        private static final long serialVersionUID = 1L;
 
@@ -38,7 +38,7 @@ public class IntroduceOffer2GUI extends JFrame  {
        private JButton jButton2 = new JButton();
        private JLabel jLabel5 = new JLabel();
 
        private JButton jButton2 = new JButton();
        private JLabel jLabel5 = new JLabel();
 
-       public IntroduceOffer2GUI(Vector<RuralHouse> v) {
+       public CreateOfferGUI(Vector<RuralHouse> v)     {
                try     {
                        jbInit(v);
                }
                try     {
                        jbInit(v);
                }
index 463919e..d58ab58 100644 (file)
@@ -24,15 +24,20 @@ import businessLogic.OfferManager;
 import domain.Offer;
 import domain.Owner;
 import domain.RuralHouse;
 import domain.Offer;
 import domain.Owner;
 import domain.RuralHouse;
+
 import javax.swing.JLabel;
 import javax.swing.LayoutStyle.ComponentPlacement;
 
 public class DeleteOfferGUI extends JFrame {
 
 import javax.swing.JLabel;
 import javax.swing.LayoutStyle.ComponentPlacement;
 
 public class DeleteOfferGUI extends JFrame {
 
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
        private JPanel contentPane;
        private Owner owner;
        private JPanel contentPane;
        private Owner owner;
-       private JComboBox comboBox;
-       private JComboBox comboBox_1;
+       private JComboBox<RuralHouse> comboBox;
+       private JComboBox<Offer> comboBox_1;
        private JButton btnDelete;
 
 
        private JButton btnDelete;
 
 
@@ -46,17 +51,31 @@ public class DeleteOfferGUI extends JFrame {
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
        
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
        
-               comboBox = new JComboBox(this.owner.getRuralHouses());
+               comboBox = new JComboBox<RuralHouse>(this.owner.getRuralHouses());
                
                
                
                
                
                
-               comboBox_1 = new JComboBox(((RuralHouse)comboBox.getSelectedItem()).offers);
+               comboBox_1 = new JComboBox<Offer>();
 
                JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
                
                btnDelete = new JButton("DELETE");
                btnDelete.setEnabled(false);
                
 
                JRadioButton rdbtnIAmSure = new JRadioButton("I am sure");
                
                btnDelete = new JButton("DELETE");
                btnDelete.setEnabled(false);
                
+               comboBox.addItemListener(new ItemListener() {
+
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+                               Vector<Offer> vo = ((RuralHouse)comboBox.getSelectedItem()).offers;
+                               comboBox_1.removeAllItems();
+                               for (Offer of: vo){
+                                       comboBox_1.addItem(of);;
+                               }
+               
+                       }
+                       
+               });
+               
                rdbtnIAmSure.addItemListener(new ItemListener() {
 
                        @Override
                rdbtnIAmSure.addItemListener(new ItemListener() {
 
                        @Override
diff --git a/ruralHouses/src/gui/ModifyOfferGUI.java b/ruralHouses/src/gui/ModifyOfferGUI.java
new file mode 100644 (file)
index 0000000..651d85c
--- /dev/null
@@ -0,0 +1,224 @@
+package gui;
+
+import java.beans.*;
+import java.sql.Date;
+import java.text.DateFormat;
+import java.util.*;
+
+import javax.swing.*;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import businessLogic.OfferManager;
+
+import com.toedter.calendar.JCalendar;
+
+import domain.Offer;
+import domain.RuralHouse;
+
+public class ModifyOfferGUI extends JFrame  {
+       
+       private static final long serialVersionUID = 1L;
+
+       private JComboBox<RuralHouse> jComboBox1;
+       private JLabel jLabel1 = new JLabel();
+       private JLabel jLabel2 = new JLabel();
+       private JTextField jTextField1 = new JTextField();
+       private JLabel jLabel3 = new JLabel();
+       private JTextField jTextField2 = new JTextField();
+       private JLabel jLabel4 = new JLabel();
+       private JTextField jTextField3 = new JTextField();
+       private JButton jButton1 = new JButton();
+       // Code for JCalendar
+       private JCalendar jCalendar1 = new JCalendar();
+       private JCalendar jCalendar2 = new JCalendar();
+       private Calendar calendarInicio = null;
+       private Calendar calendarFin = null;
+       private JButton jButton2 = new JButton();
+       private JLabel jLabel5 = new JLabel();
+       private final JLabel jLabel1_o = new JLabel();
+       private JComboBox<Offer> comboBox_o;
+
+       public ModifyOfferGUI(Vector<RuralHouse> v)     {
+               try     {
+                       jbInit(v);
+               }
+               catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void jbInit(Vector<RuralHouse> v) throws Exception {
+               this.getContentPane().setLayout(null);
+               this.setSize(new Dimension(513, 433));
+               this.setTitle("Set availability");
+
+               jComboBox1 = new JComboBox<RuralHouse>(v);
+               
+               comboBox_o = new JComboBox<Offer>();
+               
+               jComboBox1.setBounds(new Rectangle(115, 12, 115, 20));
+               jLabel1.setText("List of houses:");
+               jLabel1.setBounds(new Rectangle(25, 12, 95, 20));
+               jLabel2.setText("First day :");
+               jLabel2.setBounds(new Rectangle(25, 75, 85, 25));
+               jTextField1.setBounds(new Rectangle(25, 265, 220, 25));
+               jTextField1.setEditable(false);
+               jLabel3.setText("Last day :");
+               jLabel3.setBounds(new Rectangle(260, 75, 75, 25));
+               jTextField2.setBounds(new Rectangle(260, 265, 220, 25));
+               jTextField2.setEditable(false);
+               jLabel4.setText("Price:");
+               jLabel4.setBounds(new Rectangle(260, 30, 75, 20));
+               jTextField3.setBounds(new Rectangle(350, 30, 115, 20));
+               jTextField3.setText("0");
+               jButton1.setText("Accept");
+               jButton1.setBounds(new Rectangle(100, 360, 130, 30));
+               jTextField3.addFocusListener(new FocusListener() {
+                       public void focusGained(FocusEvent e) {}
+                       public void focusLost(FocusEvent e) {
+                               jTextField3_focusLost();
+                       }
+               });
+               
+               jComboBox1.addItemListener(new ItemListener() {
+
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+                               Vector<Offer> vo = ((RuralHouse)jComboBox1.getSelectedItem()).offers;
+                               comboBox_o.removeAllItems();
+                               for (Offer of: vo){
+                                       comboBox_o.addItem(of);
+                               }
+               
+                       }
+                       
+               });
+               
+               comboBox_o.addItemListener(new ItemListener() {
+
+                       @Override
+                       public void itemStateChanged(ItemEvent arg0) {
+                               if(arg0.getStateChange() == ItemEvent.SELECTED){
+                                       Offer of = (Offer) comboBox_o.getSelectedItem();
+                                       DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
+                                       jTextField1.setText(dateformat1.format(of.getFirstDay()));
+                                       jTextField2.setText(dateformat1.format(of.getLastDay()));
+                               }
+                       }
+                       
+               });
+               
+               jButton1.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               jButton1_actionPerformed(e);
+                       }
+               });
+               jButton2.setText("Cancel");
+               jButton2.setBounds(new Rectangle(270, 360, 130, 30));
+               jButton2.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e) {
+                               jButton2_actionPerformed(e);
+                       }
+               });
+               jLabel5.setBounds(new Rectangle(100, 320, 300, 20));
+               jLabel5.setForeground(Color.red);
+               jLabel5.setSize(new Dimension(305, 20));
+               jCalendar1.setBounds(new Rectangle(25, 100, 220, 165));
+               jCalendar2.setBounds(new Rectangle(260, 100, 220, 165));
+
+               // Code for JCalendar
+               this.jCalendar1.addPropertyChangeListener(new PropertyChangeListener() {
+                       public void propertyChange(PropertyChangeEvent propertychangeevent) {
+                               if (propertychangeevent.getPropertyName().equals("locale")) {
+                                       jCalendar1.setLocale((Locale) propertychangeevent.getNewValue());
+                                       DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar1.getLocale());
+                                       jTextField1.setText(dateformat.format(calendarInicio.getTime()));
+                               }
+                               else if (propertychangeevent.getPropertyName().equals("calendar")) {
+                                       calendarInicio = (Calendar) propertychangeevent.getNewValue();
+                                       DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar1.getLocale());
+                                       jTextField1.setText(dateformat1.format(calendarInicio.getTime()));
+                                       jCalendar1.setCalendar(calendarInicio);
+                               }
+                       } 
+               });
+
+               this.jCalendar2.addPropertyChangeListener(new PropertyChangeListener() {
+                       public void propertyChange(PropertyChangeEvent propertychangeevent) {
+                               if (propertychangeevent.getPropertyName().equals("locale")) {
+                                       jCalendar2.setLocale((Locale) propertychangeevent.getNewValue());
+                                       DateFormat dateformat = DateFormat.getDateInstance(1, jCalendar2.getLocale());
+                                       jTextField2.setText(dateformat.format(calendarFin.getTime()));
+                               }
+                               else if (propertychangeevent.getPropertyName().equals("calendar")) {
+                                       calendarFin = (Calendar) propertychangeevent.getNewValue();
+                                       DateFormat dateformat1 = DateFormat.getDateInstance(1, jCalendar2.getLocale());
+                                       jTextField2.setText(dateformat1.format(calendarFin.getTime()));
+                                       jCalendar2.setCalendar(calendarFin);
+                               }
+                       } 
+               });
+
+               this.getContentPane().add(jCalendar2, null);
+               this.getContentPane().add(jCalendar1, null);
+               this.getContentPane().add(jLabel5, null);
+               this.getContentPane().add(jButton2, null);
+               this.getContentPane().add(jButton1, null);
+               this.getContentPane().add(jTextField3, null);
+               this.getContentPane().add(jLabel4, null);
+               this.getContentPane().add(jTextField2, null);
+               this.getContentPane().add(jLabel3, null);
+               this.getContentPane().add(jTextField1, null);
+               this.getContentPane().add(jLabel2, null);
+               this.getContentPane().add(jLabel1, null);
+               this.getContentPane().add(jComboBox1, null);
+               jLabel1_o.setText("List of offers:");
+               jLabel1_o.setBounds(new Rectangle(25, 30, 95, 20));
+               jLabel1_o.setBounds(25, 44, 95, 20);
+               
+               getContentPane().add(jLabel1_o);
+               comboBox_o.setBounds(new Rectangle(115, 30, 115, 20));
+               comboBox_o.setBounds(115, 44, 115, 20);
+               
+               getContentPane().add(comboBox_o);
+       }
+
+       private void jButton1_actionPerformed(ActionEvent e) {
+               RuralHouse ruralHouse=((RuralHouse)jComboBox1.getSelectedItem());
+               Date firstDay=new Date(jCalendar1.getCalendar().getTime().getTime());
+               //Remove the hour:minute:second:ms from the date 
+               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());
+               //It could be to trigger an exception if the introduced string is not a number
+               float price= Float.parseFloat(jTextField3.getText());
+               try {
+                       //Obtain the business logic from a StartWindow class (local or remote)
+                       OfferManager offerM = new OfferManager();
+                       offerM.deleteOffer(ruralHouse, (Offer)comboBox_o.getSelectedItem());
+                       offerM.createOffer(ruralHouse, firstDay, lastDay, price); 
+
+                       this.setVisible(false);
+               }
+               catch (Exception e1) {
+                       e1.printStackTrace();
+               }
+       }
+       
+       private void jButton2_actionPerformed(ActionEvent e) {
+               this.setVisible(false);
+       }
+
+       private void jTextField3_focusLost() {
+               try {
+                       new Integer (jTextField3.getText());
+                       jLabel5.setText("");
+               }
+               catch (NumberFormatException ex) {
+                       jLabel5.setText("Error: Please introduce a number");
+               }
+       }
+}
\ No newline at end of file
index da02608..04252d4 100644 (file)
@@ -43,27 +43,25 @@ public class OffersRelatedOwnerGUI extends JFrame {
                JButton btnCreateOffers = new JButton("Create Offers");
                btnCreateOffers.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
                JButton btnCreateOffers = new JButton("Create Offers");
                btnCreateOffers.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
-                               Frame a = new NewHouseGUI(owner);
+                               Frame a = new CreateOfferGUI(owner.getRuralHouses());
                                a.setVisible(true);
                        }
                });
                
                JButton btnModifyOffers = new JButton("Modify Offers");
                                a.setVisible(true);
                        }
                });
                
                JButton btnModifyOffers = new JButton("Modify Offers");
-               btnModifyOffers.setEnabled(false);
                btnModifyOffers.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                
                btnModifyOffers.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                
-                               /* TODO to be implemented in a future.
-                               Frame a = new ModifyHouseGUI(owner);
+                               Frame a = new ModifyOfferGUI(owner.getRuralHouses());
                                a.setVisible(true);
                                a.setVisible(true);
-                               */
+                               
                        }
                });
                
                JButton btnDeleteOffers = new JButton("Delete Offers");
                btnDeleteOffers.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                        }
                });
                
                JButton btnDeleteOffers = new JButton("Delete Offers");
                btnDeleteOffers.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
-                               Frame a = new DeleteHouseGUI(owner);
+                               Frame a = new DeleteOfferGUI(owner);
                                a.setVisible(true);
                        }
                });
                                a.setVisible(true);
                        }
                });
index 532d373..980916d 100644 (file)
@@ -51,7 +51,7 @@ public class OwnerMenuGUI extends JFrame {
                JButton btnOffers = new JButton("Offers");
                btnOffers.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                JButton btnOffers = new JButton("Offers");
                btnOffers.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
-                               Frame a = new IntroduceOffer2GUI(owner.getRuralHouses());
+                               Frame a = new OffersRelatedOwnerGUI(owner);
                                a.setVisible(true);
                        }
                });
                                a.setVisible(true);
                        }
                });