--- /dev/null
+package businessLogic;
+
+import dataAccess.DB4oManager;
+import domain.Account;
+
+public class AccountManager {
+
+ private DB4oManager dbMngr;
+
+
+ public AccountManager() {
+ try {
+ dbMngr = DB4oManager.getInstance();
+ } catch (Exception e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ public boolean addAccount(Account ac){
+ if(this.dbMngr.addAccount(ac))
+ return true;
+ return false;
+
+ }
+
+ public boolean removeAccount(Account ac){
+ if(this.dbMngr.removeAccount(ac))
+ return true;
+ return false;
+
+ }
+}
import java.util.Vector;
+import domain.Account;
import domain.Administrator;
import domain.RuralHouse;
.getRemoveRequest());
}
+ public Vector<Account> getOwnerAdditionReuests() {
+ return new Vector<Account>(Administrator.getInstance()
+ .getNewOwnerRequest());
+ }
+
public void removeHouseAdditionRequests(RuralHouse house) {
Administrator.getInstance().getAddRequest().remove(house);
}
public void removeHouseDeletionRequests(RuralHouse house) {
Administrator.getInstance().getRemoveRequest().remove(house);
}
-
+ public void removeOwnerAdditionRequests(Account acc) {
+ Administrator.getInstance().getNewOwnerRequest().remove(acc);
+ }
public boolean addAdditionRequest(RuralHouse rh) {
if (this.getAdditionRequests().contains(rh)) {
return false;
return false;
return Administrator.getInstance().getRemoveRequest().add(rh);
}
+
+ public boolean addAccount(Account acc) {
+ if (this.getOwnerAdditionReuests().contains(acc)) {
+ return false;
+ }
+ return Administrator.getInstance().getNewOwnerRequest().add(acc);
+ }
+
+// public boolean removeAccount(Account acc) {
+// if (this.getDeletionRequests().contains(acc))
+// return false;
+// return Administrator.getInstance().getNewOwnerRequest().add(acc);
+// }
}
}
- public Vector<Booking> getAllBookings(Owner ow) {
- Vector<Booking> books = new Vector<Booking>();
- for (RuralHouse rh : ow.getRuralHouses()) {
- Vector<Offer> off = rh.getAllOffers();
- for (Offer of : off) {
- System.out.print(of.toString());
- if (of.getBooking() != null) {
-
- books.add(of.getBooking());
- }
- }
- }
- return books;
- }
/**
* This method creates a book with a corresponding parameters
import domain.RuralHouse;
public class HouseManager implements HouseManagerInterface {
- DB4oManager dbMngr;
+
+ private DB4oManager dbMngr;
public HouseManager() {
try {
public void initializeDB() {
try {
- Owner jon = new Owner("Jon");
- Owner alfredo = new Owner("Alfredo");
+ Owner jon = new Owner("Jon", "1349 5677 21 2133567777",
+ "Jon@gmail.com");
+ Owner alfredo = new Owner("Alfredo", "4144 0087 23 9700002133",
+ "alfredo@gmail.com");
jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Beatriz", 3, 3, 3,
3, 3);
jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Guazate", 4, 4,
4, 4, 4);
- jon.setBankAccount("1349 5677 21 2133567777");
alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Vegas", 5, 5,
5, 5, 5);
alfredo.addRuralHouse("Murgoitz", "", "Cedro", 6, 6, 6, 6, 6);
- alfredo.setBankAccount("4144 0087 23 9700002133");
Account jonAcc = new Account("1", "1", jon);
Account alfredoAcc = new Account("userAlfredo", "passAlfredo",
alfredo);
openDB();
try {
- Owner proto = new Owner(null, null);
+ Owner proto = new Owner(null, null, null);
ObjectSet<Owner> result = db.queryByExample(proto);
while (result.hasNext()) {
Owner o = (Owner) result.next();
}
}
-
public Administrator getAdminData() {
if (c.isDatabaseLocal() == false)
openSDB();
}
});
-
- admL.get(0).setAddRequest(Administrator.getInstance().getAddRequest());
- admL.get(0).setRemoveRequest(Administrator.getInstance().getRemoveRequest());
- admL.get(0).setNewOwnerRequest(Administrator.getInstance().getNewOwnerRequest());
+ admL.get(0).setAddRequest(
+ Administrator.getInstance().getAddRequest());
+ admL.get(0).setRemoveRequest(
+ Administrator.getInstance().getRemoveRequest());
+ admL.get(0).setNewOwnerRequest(
+ Administrator.getInstance().getNewOwnerRequest());
db.commit();
} catch (Exception e) {
openDB();
try {
- Owner proto = new Owner(null, null);
+ Owner proto = new Owner(null, null, null);
ObjectSet<Owner> result = db.queryByExample(proto);
Vector<Owner> owners = new Vector<Owner>();
while (result.hasNext())
* @throws RemoteException
* @throws Exception
*/
- public Vector<Account> getAccount(Account proto)
- throws RemoteException, Exception {
+ public Vector<Account> getAccount(Account proto) throws RemoteException,
+ Exception {
if (c.isDatabaseLocal() == false)
openSDB();
}
+ public boolean addAccount(Account acc) {
+ if (c.isDatabaseLocal() == false)
+ openSDB();
+ else
+ openDB();
+
+ try {
+ //TODO realize if there is another account with same username. Quite difficult with the f***ing salt
+ db.store(acc);
+ db.commit();
+ } catch (Exception exc) {
+ exc.printStackTrace();
+ } finally {
+ db.close();
+ }
+ return true;
+ }
+
+ //TODO remove account
+
+ public boolean removeAccount(Account acc) {
+ return false;
+ }
+
}
package domain;
+import java.util.Arrays;
+
import businessLogic.SecurityManager;
public class Account {
+
+
private byte[] username;
private byte[] password;
private byte[] salt;
public void setSalt(byte[] salt) {
this.salt = salt;
}
+
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Account other = (Account) obj;
+ if (!Arrays.equals(password, other.password))
+ return false;
+ if (!Arrays.equals(username, other.username))
+ return false;
+ return true;
+ }
}
private static Administrator admin = null;
private static LinkedList<RuralHouse> addRequest;
private static LinkedList<RuralHouse> removeRequest;
- private static LinkedList<Owner> newOwnerRequest;
+ private static LinkedList<Account> newOwnerRequest;
static ConfigXML c;
private Administrator() {
addRequest = new LinkedList<RuralHouse>();
removeRequest = new LinkedList<RuralHouse>();
- newOwnerRequest = new LinkedList<Owner>();
+ newOwnerRequest = new LinkedList<Account>();
}
public static Administrator getInstance() {
Administrator.removeRequest = removeRequest;
}
- public LinkedList<Owner> getNewOwnerRequest() {
+ public LinkedList<Account> getNewOwnerRequest() {
return newOwnerRequest;
}
- public void setNewOwnerRequest(LinkedList<Owner> newOwnerRequest) {
+ public void setNewOwnerRequest(LinkedList<Account> newOwnerRequest) {
Administrator.newOwnerRequest = newOwnerRequest;
}
private int bookingNumber;
private boolean isPaid;
private Date bookingDate;
- private String telephone;
+ private Client client;
private Offer offer;
private boolean isAccepted;
public Booking() {
}
- public Booking(int bN ,String telephone, Offer offer) {
+ public Booking(int bN , Offer offer,Client client) {
this.bookingNumber = bN;
- this.telephone=telephone;
this.offer = offer;
- //this.price = price;
+ this.client=client;
//Booking date is assigned to actual date
this.bookingDate= new java.util.Date(System.currentTimeMillis());
this.isPaid=false;
System.out.println(bookingNumber);
System.out.println(isPaid);
System.out.println(bookingDate);
- System.out.println(telephone);
+ System.out.println(client.toString());
System.out.println(offer);
System.out.println(this.isAccepted);
}
return this.bookingDate;
}
- public void setTelephone(String telephone) {
- this.telephone = telephone;
- }
-
- public String getTelephone() {
- return this.telephone;
- }
-
public void paid() {
this.isPaid = true;
}
public boolean isAccepted(){
return this.isAccepted;
}
+
+ public Client getClient() {
+ return client;
+ }
+
+ public void setClient(Client client) {
+ this.client = client;
+ }
}
\ No newline at end of file
--- /dev/null
+package domain;
+
+public class Client {
+
+ private String name;
+ private String mailAccount;
+ private String telephone;
+
+ public Client(String name, String mailAccount, String telephone) {
+ super();
+ this.name = name;
+ this.mailAccount = mailAccount;
+ this.telephone = telephone;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMailAccount() {
+ return mailAccount;
+ }
+
+ public void setMailAccount(String mailAccount) {
+ this.mailAccount = mailAccount;
+ }
+
+ public String getTelephone() {
+ return telephone;
+ }
+
+ public void setTelephone(String telephone) {
+ this.telephone = telephone;
+ }
+
+}
import java.io.Serializable;
import java.util.Date;
+import java.util.LinkedList;
+import java.util.Vector;
@SuppressWarnings("serial")
private Date firstDay; // Dates are stored as java.util.Date objects instead of java.sql.Date objects
private Date lastDay; // because, they are not well stored in db4o as java.util.Date objects
private float price; // This is coherent because objects of java.sql.Date are objects of java.util.Date
- private Booking booking; // That is: java.sql.Date is a subclass (or extends) java.util.Date
+ private Vector<Booking> bookings; // That is: java.sql.Date is a subclass (or extends) java.util.Date
private RuralHouse ruralHouse;
this.price = price;
}
- /**
- * Get the book number
- *
- * @return book object
- */
- public Booking getBooking() {
- return this.booking;
- }
-
- /**
- * Set the book object
- *
- * @param book
- * Book object
- * @return None
- */
- public void setBooking(Booking booking) {
- this.booking = booking;
- }
/**
* This method creates a book with a corresponding parameters
* @param First day, last day, house number and telephone
* @return a book
*/
- public Booking createBooking(int numBooking,String bookTelephoneNumber) {
- return booking=new Booking(numBooking,bookTelephoneNumber,this);
+ public Booking createBooking(int numBooking,String bookTelephoneNumber,String name , String mail) {
+ Client client = new Client(name,mail,bookTelephoneNumber);
+ Booking b = new Booking(numBooking,this,client);
+ this.bookings.add(b);
+ return b;
}
public String toString(){
return firstDay.toString()+", "+lastDay.toString()+", "+price;
}
+ public Vector<Booking> getBookings() {
+ return bookings;
+ }
+ public void setBookings(Vector<Booking> bookings) {
+ this.bookings = bookings;
+ }
}
\ No newline at end of file
private String bankAccount = "";
private String name = "";
+ private String mailAccount = "";
private Vector<RuralHouse> ruralHouses;
- public Owner(String name) {
- this.name = name;
- ruralHouses = new Vector<RuralHouse>();
- }
+// public Owner(String name) {
+// this.name = name;
+// ruralHouses = new Vector<RuralHouse>();
+// }
- public Owner(String name, String bankAccount) {
+ public Owner(String name, String bankAccount,String mail) {
this.bankAccount = bankAccount;
this.name = name;
+ this.mailAccount = mail;
ruralHouses = new Vector<RuralHouse>();
}
return name;
}
+ public String getMailAccount() {
+ return mailAccount;
+ }
+
+ public void setMailAccount(String mailAccount) {
+ this.mailAccount = mailAccount;
+ }
+
+ public Vector<Offer> getAllOffers (){
+ Vector<Offer> offers = new Vector<Offer>();
+ for(RuralHouse rh: this.ruralHouses){
+ for(Offer of : rh.getAllOffers()){
+ offers.add(of);
+ }
+ }
+ return offers;
+ }
+
}
\ No newline at end of file
return this.offers;
}
- /**
- * This method obtains the offer that match exactly with a given dates that
- * has not been booked
- *
- * @param firstDay
- * , first day in a period range
- * @param lastDay
- * , last day in a period range
- * @return the offer(Offer class) available for a this period
- */
- public Offer findOffer(Date firstDay, Date lastDay) {
- Iterator<Offer> e = offers.iterator();
- Offer offer = null;
- while (e.hasNext()) {
- offer = e.next();
- if ((offer.getFirstDay().compareTo(firstDay) == 0)
- && (offer.getLastDay().compareTo(lastDay) == 0)
- && (offer.getBooking() == null))
- return offer;
- }
- return null;
- }
+// /**
+// * This method obtains the offer that match exactly with a given dates that
+// * has not been booked
+// *
+// * @param firstDay
+// * , first day in a period range
+// * @param lastDay
+// * , last day in a period range
+// * @return the offer(Offer class) available for a this period
+// */
+// public Offer findOffer(Date firstDay, Date lastDay) {
+// Iterator<Offer> e = offers.iterator();
+// Offer offer = null;
+// while (e.hasNext()) {
+// offer = e.next();
+// if ((offer.getFirstDay().compareTo(firstDay) == 0)
+// && (offer.getLastDay().compareTo(lastDay) == 0)
+// && (offer.getBooking() == null))
+// return offer;
+// }
+// return null;
+// }
public Offer overlapsWith(Date firstDay, Date lastDay) {
private JPanel contentPane;
- public static void main(String[] args){
- Frame a = new AdminMenuGUI();
- a.setVisible(true);
- }
+
/**
* Create the frame.
*/
});
JButton btnOwneraddition = new JButton("OwnerAddition");
+ btnOwneraddition.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ Frame a = new ownerAddittionRequests();
+ a.setVisible(true);
+ }
+ });
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(
gl_contentPane.createParallelGroup(Alignment.LEADING)
Enumeration<Offer> rhs = rh.getAllOffers().elements();
while (rhs.hasMoreElements()) {
Offer of = rhs.nextElement();
- if (of.getBooking() == null) {
+ if (of.getBookings().size()==1&&of.getBookings().get(0).isAccepted()) {
Vector<Object> row = new Vector<Object>();
row.add(of.getOfferNumber());
row.add(of.getFirstDay());
private JPasswordField passwordField;
private LoginManagerInterface loginManager = new LoginManager();
private JLabel loginFeedback;
+ private JButton btnRegister;
public LoginGUI() {
super();
initialize();
jButton_ActionPerformed(arg0);
}
});
- loginButton.setBounds(164, 179, 117, 25);
+ loginButton.setBounds(95, 179, 117, 25);
jContentPane.add(loginButton);
loginFeedback = new JLabel("");
loginFeedback.setHorizontalAlignment(SwingConstants.CENTER);
loginFeedback.setBounds(83, 216, 269, 25);
jContentPane.add(loginFeedback);
+
+ btnRegister = new JButton("Register");
+ btnRegister.setBounds(222, 180, 113, 23);
+ btnRegister.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+
+ jButton_ActionPerformed2(arg0);
+ }
+ });
+ jContentPane.add(btnRegister);
}
return jContentPane;
}
-
+ private void jButton_ActionPerformed2(ActionEvent e){
+
+
+ this.setVisible(false);
+ Frame a = new OwnerRegistrationGUI();
+ a.setVisible(true);
+
+
+ }
private void jButton_ActionPerformed(ActionEvent e){
Account acc = loginManager.checkCredentials(usernameField.getText(),new String(passwordField.getPassword()));
JButton btnBookings = new JButton("Bookings");
btnBookings.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- Frame a = new listOfBookingRequestsGUI(owner);
+ Frame a = new listOfOffers(owner);
a.setVisible(true);
}
});
--- /dev/null
+package gui;
+
+import java.awt.BorderLayout;
+import java.awt.EventQueue;
+import java.awt.Frame;
+
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import javax.swing.JButton;
+
+import businessLogic.AdminManager;
+import domain.Account;
+import domain.Owner;
+
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+public class OwnerRegistrationGUI extends JFrame {
+
+ private JPanel panel;
+ private JTextField nameField;
+ private JTextField userNameField;
+ private AdminManager am = new AdminManager();
+ private JTextField passField;
+ private JTextField bank1Field;
+ private JTextField bank2Field;
+ private JTextField bank3Field;
+ private JTextField bank4Field;
+ private JTextField emailField;
+ private JLabel lblWhenAcceptedYou;
+ private JLabel feedback;
+
+ /**
+ * Create the frame.
+ */
+ public OwnerRegistrationGUI() {
+ setTitle("Owner registration");
+ setBounds(100, 100, 500, 400);
+ panel = new JPanel();
+ panel.setBorder(new EmptyBorder(5, 5, 5, 5));
+ setContentPane(panel);
+ panel.setLayout(null);
+
+ JLabel nameLb = new JLabel("Name:");
+ nameLb.setBounds(37, 45, 46, 14);
+ panel.add(nameLb);
+
+ nameField = new JTextField();
+ nameField.setBounds(147, 42, 86, 20);
+ panel.add(nameField);
+ nameField.setColumns(10);
+
+ JLabel lblUsername = new JLabel("Username:");
+ lblUsername.setBounds(37, 212, 69, 14);
+ panel.add(lblUsername);
+
+ userNameField = new JTextField();
+ userNameField.setBounds(147, 209, 86, 20);
+ panel.add(userNameField);
+ userNameField.setColumns(10);
+
+ JLabel lblPassword = new JLabel("Password:");
+ lblPassword.setBounds(37, 258, 69, 14);
+ panel.add(lblPassword);
+
+ passField = new JTextField();
+ passField.setBounds(147, 255, 86, 20);
+ panel.add(passField);
+ passField.setColumns(10);
+
+ JLabel lblBankAccount = new JLabel("Bank account:");
+ lblBankAccount.setBounds(37, 94, 69, 14);
+ panel.add(lblBankAccount);
+
+ bank1Field = new JTextField();
+ bank1Field.setBounds(147, 91, 61, 20);
+ panel.add(bank1Field);
+
+ bank2Field = new JTextField();
+ bank2Field.setBounds(218, 91, 61, 20);
+ panel.add(bank2Field);
+
+ bank3Field = new JTextField();
+ bank3Field.setBounds(289, 91, 32, 20);
+ panel.add(bank3Field);
+
+ bank4Field = new JTextField();
+ bank4Field.setBounds(331, 91, 117, 20);
+ panel.add(bank4Field);
+
+ JButton btnSendRegistrationRequest = new JButton(
+ "Send registration request");
+ btnSendRegistrationRequest.setBounds(127, 316, 194, 23);
+ btnSendRegistrationRequest.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+
+ jButton_ActionPerformed(arg0);
+ }
+ });
+
+ panel.add(btnSendRegistrationRequest);
+
+ JLabel lblEmail = new JLabel("E-mail:");
+ lblEmail.setBounds(37, 155, 46, 14);
+ panel.add(lblEmail);
+
+ emailField = new JTextField();
+ emailField.setBounds(147, 152, 148, 20);
+ panel.add(emailField);
+ emailField.setColumns(10);
+
+ lblWhenAcceptedYou = new JLabel(
+ "When accepted you will receive an e-mail");
+ lblWhenAcceptedYou.setForeground(Color.GREEN);
+ lblWhenAcceptedYou.setBounds(127, 291, 214, 14);
+ panel.add(lblWhenAcceptedYou);
+
+ feedback = new JLabel("");
+ feedback.setForeground(Color.RED);
+ feedback.setEnabled(false);
+ feedback.setBounds(127, 344, 214, 20);
+ panel.add(feedback);
+ }
+
+ private void jButton_ActionPerformed(ActionEvent e) {
+
+ Owner own = new Owner(this.nameField.getText(),
+ this.bank1Field.getText() + " " + this.bank2Field.getText()
+ + " " + this.bank3Field.getText() + " "
+ + this.bank4Field.getText(), this.emailField.getText());
+ Account acc = new Account(this.userNameField.getText(),
+ this.passField.getText(), own);
+
+ if (this.am.addAccount(acc)) {
+ this.feedback.setText("Request sended");
+ } else {
+ this.feedback.setText("Can't send the request");
+ }
+
+ }
+}
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTable table;
- private Owner own;
+ private Offer off;
private BookingManager bookM = new BookingManager();
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();
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);
row.add(book.getBookNumber());
row.add(book.isPaid());
row.add(book.getBookDate());
- row.add(book.getTelephone());
+ row.add(book.getClient());
row.add(book.getOffer());
tableModel.addRow(row);
}
--- /dev/null
+package gui;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Enumeration;
+import java.util.LinkedList;
+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 businessLogic.BookingManager;
+import domain.Booking;
+import domain.Offer;
+import domain.Owner;
+import domain.RuralHouse;
+
+public class listOfOffers extends JFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private JPanel contentPane;
+ private JTable table;
+ private Owner owner;
+ private BookingManager bookM = new BookingManager();
+ private DefaultTableModel tableModel;
+ private Vector<Offer> offers = new Vector<Offer>();
+
+ /**
+ * Create the frame.
+ */
+ public listOfOffers(Owner own) {
+ setTitle("Adding requests");
+ this.owner = own;
+ try {
+
+ 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);
+
+ this.offers = this.owner.getAllOffers();
+ JLabel lblNewLabel = new JLabel();
+ lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
+ lblNewLabel.setBounds(23, 41, 536, 33);
+ contentPane.add(lblNewLabel);
+ if (this.offers.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[] { "Offer #",
+ "FirstDay", "LastDay", "Price" });
+
+ // 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) {
+
+ }
+ }
+ });
+ btnNewButton.setBounds(88, 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) {
+
+ }
+ }
+ });
+ btnDenyAddition.setBounds(300, 396, 169, 25);
+ contentPane.add(btnDenyAddition);
+ Enumeration<Offer> rhs = this.offers.elements();
+ while (rhs.hasMoreElements()) {
+ Offer of = rhs.nextElement();
+ Vector<Object> row = new Vector<Object>();
+ row.add(of.getOfferNumber());
+ row.add(of.getFirstDay());
+ row.add(of.getLastDay());
+ row.add(of.getPrice());
+ tableModel.addRow(row);
+
+ }
+
+ }
+}
--- /dev/null
+package gui;
+
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+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 businessLogic.AccountManager;
+import businessLogic.AdminManager;
+import domain.Account;
+import domain.Administrator;
+
+public class ownerAddittionRequests extends JFrame {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private JPanel contentPane;
+ private JTable table;
+ private DefaultTableModel tableModel;
+ private AdminManager am = new AdminManager();
+ private Vector<Account> accounts;
+ /**
+ * Create the frame.
+ */
+ public ownerAddittionRequests() {
+ setTitle("Adding requests");
+ try {
+ this.accounts= am.getOwnerAdditionReuests();
+ 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 (accounts.isEmpty())
+ lblNewLabel.setText("There are not owners to be added");
+ else
+ lblNewLabel.setText("List of owners to be added:");
+ 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[] {
+ "Name", "E-mail", "Bank Account" });
+
+ //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 && table.getSelectedRow() != -1) {
+ AccountManager ama = new AccountManager();
+ Account accou = accounts.get(table.getSelectedRow());
+ //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
+ ama.addAccount(accou);
+ am.removeOwnerAdditionRequests(accou);;
+ Administrator.saveInstance();
+ ((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(accou));
+ accounts.remove(accou);
+ }
+ }
+ });
+ btnNewButton.setBounds(88, 396, 169, 25);
+ contentPane.add(btnNewButton);
+
+ JButton btnDenyAddition = new JButton("Deny Addition");
+ btnDenyAddition.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent arg0) {
+ if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
+ Account acc = accounts.get(table.getSelectedRow());
+ am.removeOwnerAdditionRequests(acc);
+ Administrator.saveInstance();
+ ((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(acc));
+ accounts.remove(acc);
+ }
+ }
+ });
+ btnDenyAddition.setBounds(300, 396, 169, 25);
+ contentPane.add(btnDenyAddition);
+ Enumeration<Account> en = accounts.elements();
+ Account acc;
+
+ while (en.hasMoreElements()) {
+ acc = en.nextElement();
+ Vector<Object> row = new Vector<Object>();
+ row.add(acc.getOwner().getName());
+ row.add(acc.getOwner().getMailAccount());
+ row.add(acc.getOwner().getBankAccount());
+ tableModel.addRow(row);
+ }
+
+ }
+}