Merged the two branches, DB separated
[RRRRHHHH_Code] / ruralHouses / src / gui / listOfBookingRequestsGUI.java
index 80e1800..423ea4d 100644 (file)
@@ -1,11 +1,14 @@
 package gui;
 
+import java.awt.Color;
+import java.awt.Component;
 import java.awt.Font;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
 import java.util.Enumeration;
-import java.util.LinkedList;
 import java.util.Vector;
 
 import javax.swing.JButton;
@@ -15,13 +18,14 @@ import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
 import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.DefaultTableModel;
 
-import businessLogic.BookingManager;
+import common.BookingInterface;
+
+import configuration.___IntNames;
 import domain.Booking;
 import domain.Offer;
-import domain.Owner;
-import domain.RuralHouse;
 
 public class listOfBookingRequestsGUI extends JFrame {
 
@@ -31,17 +35,18 @@ public class listOfBookingRequestsGUI extends JFrame {
        private static final long serialVersionUID = 1L;
        private JPanel contentPane;
        private JTable table;
-       private Owner own;
-       private BookingManager bookM = new BookingManager();
+       private Offer off;
+       private BookingInterface bookM = null;
        private DefaultTableModel tableModel;
        private Vector<Booking> bookings = new Vector<Booking>();
 
        /**
         * Create the frame.
         */
-       public listOfBookingRequestsGUI(Owner own) {
+       public listOfBookingRequestsGUI(Offer of) {
                setTitle("Adding requests");
-               this.own = own;
+               this.off = of;
+
                try {
 
                        init();
@@ -51,22 +56,17 @@ public class listOfBookingRequestsGUI extends JFrame {
        }
 
        private void init() throws Exception {
-               setBounds(100, 100, 600, 450);
+               setBounds(100, 100, 600, 500);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
                contentPane.setLayout(null);
-               
-               this.bookings= this.bookM.getAllBookings(own);
+
+               this.bookings = this.off.getBookings();
                JLabel lblNewLabel = new JLabel();
                lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
                lblNewLabel.setBounds(23, 41, 536, 33);
                contentPane.add(lblNewLabel);
-               if (bookings.isEmpty())
-                       lblNewLabel
-                                       .setText("There are not bookings to be confirmed or denied");
-               else
-                       lblNewLabel.setText("List of bookings:");
                JScrollPane scrollPane = new JScrollPane();
                scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
                scrollPane.setBounds(23, 113, 536, 271);
@@ -80,47 +80,118 @@ public class listOfBookingRequestsGUI extends JFrame {
                        };
                };
                scrollPane.setViewportView(table);
-               tableModel = new DefaultTableModel(null, new String[] {
-                               "Booking Number", "Is paid", "Booking Date", "Telephone",
-                               "Offer" });
+               tableModel = new DefaultTableModel(null,
+                               new String[] { "Booking Number", "Booking Date", "Name",
+                                               "E-mail", "Telephone" });
 
-               // Maybe there is a better way to avoid interaction.
-               // table.setEnabled(false);
                table.setModel(tableModel);
 
                JButton btnNewButton = new JButton("Confirm Booking");
                btnNewButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
+                               try {
+                                       bookM = (BookingInterface) Naming
+                                                       .lookup(___IntNames.BookingManager);
+                               } catch (Exception e1) {
+                                       System.out
+                                                       .println("Error accessing remote authentication: "
+                                                                       + e1.toString());
+                               }
                                if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+                                       if (table.getRowCount() != 0
+                                                       && table.getSelectedRow() != -1) {
+                                               Booking book = bookings.get(table.getSelectedRow());
+                                               try {
+                                                       bookM.acceptBooking(book);
+                                               } catch (RemoteException e1) {
+                                                       e1.printStackTrace();
+                                               }
+                                               contentPane.setVisible(false);
+
+                                       }
 
                                }
                        }
                });
-               btnNewButton.setBounds(88, 396, 169, 25);
+               btnNewButton.setBounds(33, 396, 169, 25);
                contentPane.add(btnNewButton);
 
                JButton btnDenyAddition = new JButton("Deny Booking");
                btnDenyAddition.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
+                               try {
+                                       bookM = (BookingInterface) Naming
+                                                       .lookup(___IntNames.BookingManager);
+                               } catch (Exception e1) {
+                                       System.out
+                                                       .println("Error accessing remote authentication: "
+                                                                       + e1.toString());
+                               }
                                if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+                                       Booking book = bookings.get(table.getSelectedRow());
+                                       try {
+                                               bookM.denyBooking(book);
+                                       } catch (RemoteException e) {
+                                               e.printStackTrace();
+                                       }
+                                       ((DefaultTableModel) table.getModel()).removeRow(table
+                                                       .getSelectedRow());
+                                       bookings.remove(book);
 
                                }
                        }
                });
-               btnDenyAddition.setBounds(300, 396, 169, 25);
+               if (bookings.isEmpty())
+                       lblNewLabel
+                                       .setText("There are not bookings to be confirmed or denied");
+               else {
+                       lblNewLabel.setText("List of bookings:");
+                       if (this.bookings.get(0).getOffer().isBooked()) {
+                               btnDenyAddition.setEnabled(false);
+                               btnNewButton.setEnabled(false);
+                       }
+               }
+               
+               btnDenyAddition.setBounds(390, 395, 169, 25);
                contentPane.add(btnDenyAddition);
+
                Enumeration<Booking> en = this.bookings.elements();
                Booking book;
                while (en.hasMoreElements()) {
                        book = en.nextElement();
                        Vector<Object> row = new Vector<Object>();
                        row.add(book.getBookNumber());
-                       row.add(book.isPaid());
                        row.add(book.getBookDate());
-                       row.add(book.getTelephone());
-                       row.add(book.getOffer());
+                       row.add(book.getClient().getName());
+                       row.add(book.getClient().getMailAccount());
+                       row.add(book.getClient().getTelephone());
                        tableModel.addRow(row);
                }
+               table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
+                       /**
+                        * 
+                        */
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       public Component getTableCellRendererComponent(JTable table,
+                                       Object value, boolean isSelected, boolean hasFocus,
+                                       int row, int col) {
 
+                               super.getTableCellRendererComponent(table, value, isSelected,
+                                               hasFocus, row, col);
+
+                               if (!bookings.get(row).getOffer().isBooked()) {
+                                       setBackground(Color.RED);
+                                       setForeground(Color.BLACK);
+                               } else {
+                                       setBackground(Color.GREEN);
+                                       setForeground(Color.BLACK);
+                               }
+
+                               return this;
+                       }
+               });
        }
+
 }