cleaning
[RRRRHHHH_Code] / ruralHouses / src / gui / listOfBookingRequestsGUI.java
diff --git a/ruralHouses/src/gui/listOfBookingRequestsGUI.java b/ruralHouses/src/gui/listOfBookingRequestsGUI.java
new file mode 100644 (file)
index 0000000..982d7f2
--- /dev/null
@@ -0,0 +1,140 @@
+package gui;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.RemoteException;
+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 common.BookingInterface;
+
+import domain.Booking;
+import domain.Offer;
+
+public class listOfBookingRequestsGUI extends JFrame {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       private JPanel contentPane;
+       private JTable table;
+       private Offer off;
+       private BookingInterface bookM =null;
+       private DefaultTableModel tableModel;
+       private Vector<Booking> bookings = new Vector<Booking>();
+
+       /**
+        * Create the frame.
+        */
+       public listOfBookingRequestsGUI(Offer of) {
+               setTitle("Adding requests");
+               this.off = of;
+
+               try {
+
+                       init();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       private void init() throws Exception {
+               setBounds(100, 100, 600, 500);
+               contentPane = new JPanel();
+               contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(contentPane);
+               contentPane.setLayout(null);
+               
+               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);
+               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[] {
+                               "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) {
+                               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();
+                                               }
+                                       }
+
+                               }
+                       }
+               });
+               btnNewButton.setBounds(33, 396, 169, 25);
+               contentPane.add(btnNewButton);
+
+               JButton btnDenyAddition = new JButton("Deny Booking");
+               btnDenyAddition.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+                               if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
+                                       Booking book = bookings.get(table.getSelectedRow());
+                                       try {
+                                               bookM.removeDenyBooking(book);
+                                       } catch (RemoteException e) {
+                                               e.printStackTrace();
+                                       }
+
+                               }
+                       }
+               });
+               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.getBookDate());
+                       row.add(book.getClient().getName());
+                       row.add(book.getClient().getMailAccount());
+                       row.add(book.getClient().getTelephone());
+                       tableModel.addRow(row);
+               }
+
+       }
+}