Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard

Diff Revisions d30bcc ... vs ccac99 ... for ruralHouses client/src/gui/listOfBookingRequestsGUI.java

Diff revisions: vs.
  @@ -1,9 +1,12 @@
1 1 package gui;
2 2
3 + import java.awt.Color;
4 + import java.awt.Component;
3 5 import java.awt.Font;
4 6 import java.awt.Rectangle;
5 7 import java.awt.event.ActionEvent;
6 8 import java.awt.event.ActionListener;
9 + import java.rmi.Naming;
7 10 import java.rmi.RemoteException;
8 11 import java.util.Enumeration;
9 12 import java.util.Vector;
  @@ -15,10 +18,12 @@
15 18 import javax.swing.JScrollPane;
16 19 import javax.swing.JTable;
17 20 import javax.swing.border.EmptyBorder;
21 + import javax.swing.table.DefaultTableCellRenderer;
18 22 import javax.swing.table.DefaultTableModel;
19 23
20 24 import common.BookingInterface;
21 25
26 + import configuration.___IntNames;
22 27 import domain.Booking;
23 28 import domain.Offer;
24 29
  @@ -31,7 +36,7 @@
31 36 private JPanel contentPane;
32 37 private JTable table;
33 38 private Offer off;
34 - private BookingInterface bookM =null;
39 + private BookingInterface bookM = null;
35 40 private DefaultTableModel tableModel;
36 41 private Vector<Booking> bookings = new Vector<Booking>();
37 42
  @@ -56,17 +61,12 @@
56 61 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
57 62 setContentPane(contentPane);
58 63 contentPane.setLayout(null);
59 -
60 - this.bookings= this.off.getBookings();
64 +
65 + this.bookings = this.off.getBookings();
61 66 JLabel lblNewLabel = new JLabel();
62 67 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
63 68 lblNewLabel.setBounds(23, 41, 536, 33);
64 69 contentPane.add(lblNewLabel);
65 - if (bookings.isEmpty())
66 - lblNewLabel
67 - .setText("There are not bookings to be confirmed or denied");
68 - else
69 - lblNewLabel.setText("List of bookings:");
70 70 JScrollPane scrollPane = new JScrollPane();
71 71 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
72 72 scrollPane.setBounds(23, 113, 536, 271);
  @@ -80,24 +80,34 @@
80 80 };
81 81 };
82 82 scrollPane.setViewportView(table);
83 - tableModel = new DefaultTableModel(null, new String[] {
84 - "Booking Number", "Booking Date","Name","E-mail", "Telephone" });
83 + tableModel = new DefaultTableModel(null,
84 + new String[] { "Booking Number", "Booking Date", "Name",
85 + "E-mail", "Telephone" });
85 86
86 - // Maybe there is a better way to avoid interaction.
87 - // table.setEnabled(false);
88 87 table.setModel(tableModel);
89 88
90 89 JButton btnNewButton = new JButton("Confirm Booking");
91 90 btnNewButton.addActionListener(new ActionListener() {
92 91 public void actionPerformed(ActionEvent e) {
92 + try {
93 + bookM = (BookingInterface) Naming
94 + .lookup(___IntNames.BookingManager);
95 + } catch (Exception e1) {
96 + System.out
97 + .println("Error accessing remote authentication: "
98 + + e1.toString());
99 + }
93 100 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
94 - if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
101 + if (table.getRowCount() != 0
102 + && table.getSelectedRow() != -1) {
95 103 Booking book = bookings.get(table.getSelectedRow());
96 104 try {
97 105 bookM.acceptBooking(book);
98 106 } catch (RemoteException e1) {
99 107 e1.printStackTrace();
100 108 }
109 + contentPane.setVisible(false);
110 +
101 111 }
102 112
103 113 }
  @@ -109,20 +119,42 @@
109 119 JButton btnDenyAddition = new JButton("Deny Booking");
110 120 btnDenyAddition.addActionListener(new ActionListener() {
111 121 public void actionPerformed(ActionEvent arg0) {
122 + try {
123 + bookM = (BookingInterface) Naming
124 + .lookup(___IntNames.BookingManager);
125 + } catch (Exception e1) {
126 + System.out
127 + .println("Error accessing remote authentication: "
128 + + e1.toString());
129 + }
112 130 if (table.getRowCount() != 0 && table.getSelectedRow() != -1) {
113 131 Booking book = bookings.get(table.getSelectedRow());
114 132 try {
115 - bookM.removeDenyBooking(book);
133 + bookM.denyBooking(book);
116 134 } catch (RemoteException e) {
117 135 e.printStackTrace();
118 136 }
137 + ((DefaultTableModel) table.getModel()).removeRow(table
138 + .getSelectedRow());
139 + bookings.remove(book);
119 140
120 141 }
121 142 }
122 143 });
144 + if (bookings.isEmpty())
145 + lblNewLabel
146 + .setText("There are not bookings to be confirmed or denied");
147 + else {
148 + lblNewLabel.setText("List of bookings:");
149 + if (this.bookings.get(0).getOffer().isBooked()) {
150 + btnDenyAddition.setEnabled(false);
151 + btnNewButton.setEnabled(false);
152 + }
153 + }
154 +
123 155 btnDenyAddition.setBounds(390, 395, 169, 25);
124 156 contentPane.add(btnDenyAddition);
125 -
157 +
126 158 Enumeration<Booking> en = this.bookings.elements();
127 159 Booking book;
128 160 while (en.hasMoreElements()) {
  @@ -135,6 +167,31 @@
135 167 row.add(book.getClient().getTelephone());
136 168 tableModel.addRow(row);
137 169 }
170 + table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
171 + /**
172 + *
173 + */
174 + private static final long serialVersionUID = 1L;
175 +
176 + @Override
177 + public Component getTableCellRendererComponent(JTable table,
178 + Object value, boolean isSelected, boolean hasFocus,
179 + int row, int col) {
180 +
181 + super.getTableCellRendererComponent(table, value, isSelected,
182 + hasFocus, row, col);
183 +
184 + if (!bookings.get(row).getOffer().isBooked()) {
185 + setBackground(Color.RED);
186 + setForeground(Color.BLACK);
187 + } else {
188 + setBackground(Color.GREEN);
189 + setForeground(Color.BLACK);
190 + }
138 191
192 + return this;
193 + }
194 + });
139 195 }
196 +
140 197 }