From: pinene Date: Wed, 20 May 2015 16:42:17 +0000 (+0200) Subject: Merge branch 'master' of ssh://xp-dev.com/RRRRHHHH_Code X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/commitdiff_plain/ccac9974c8183f7f0d30e8cabd84ee0386e8cd97 Merge branch 'master' of ssh://xp-dev.com/RRRRHHHH_Code Conflicts: ruralHouses client/src/domain/Owner.java ruralHouses client/src/domain/RuralHouse.java ruralHouses client/src/gui/BookRuralHouseConfirmationWindow.java ruralHouses client/src/gui/ModifyOfferGUI.java ruralHouses/src/dataAccess/DB4oManager.java ruralHouses/src/domain/Booking.java --- ccac9974c8183f7f0d30e8cabd84ee0386e8cd97 diff --cc ruralHouses client/src/common/BookingInterface.java index 0d2db53,8780f2f..598a537 --- a/ruralHouses client/src/common/BookingInterface.java +++ b/ruralHouses client/src/common/BookingInterface.java @@@ -13,9 -13,10 +13,9 @@@ import exceptions.OfferCanNotBeBooked public interface BookingInterface extends Remote { - public int getNumber() throws RemoteException; - public void removeDenyBooking(Booking b) throws RemoteException; + public void denyBooking(Booking b) throws RemoteException; public void acceptBooking(Booking b) throws RemoteException; diff --cc ruralHouses client/src/domain/Administrator.java index 0d516c5,845d089..d1ea781 --- a/ruralHouses client/src/domain/Administrator.java +++ b/ruralHouses client/src/domain/Administrator.java @@@ -24,7 -23,16 +24,7 @@@ public class Administrator implements S newOwnerRequest = new LinkedList(); } - public static Administrator getInstance() { - return null; - - - } - - public static void saveInstance() { - - } -- ++ public LinkedList getAddRequest() { return addRequest; } diff --cc ruralHouses client/src/domain/RuralHouse.java index 27f8d7f,d988b39..0c7fbb7 --- a/ruralHouses client/src/domain/RuralHouse.java +++ b/ruralHouses client/src/domain/RuralHouse.java @@@ -14,8 -14,9 +14,9 @@@ public class RuralHouse implements Seri private Owner owner; private String district; private HouseFeatures features; - private Vector offers; - private boolean isAccepted; + public Vector offers; + + public RuralHouse() { super(); } @@@ -113,11 -166,13 +114,12 @@@ return null; } + - public boolean isAccepted() { - return isAccepted; - } + public Vector getAllOffers() { - public void setAccepted(boolean isAccepted) { - this.isAccepted = isAccepted; + return this.offers; } ++ } diff --cc ruralHouses client/src/gui/BookRuralHouseConfirmationWindow.java index c26d9df,a313f3f..21f9ab6 --- a/ruralHouses client/src/gui/BookRuralHouseConfirmationWindow.java +++ b/ruralHouses client/src/gui/BookRuralHouseConfirmationWindow.java @@@ -79,10 -79,10 +79,11 @@@ public class BookRuralHouseConfirmation jTextField3.setBounds(new Rectangle(180, 140, 115, 25)); jTextField3.setEditable(false); - jTextField3.setText(Float.toString(book.getOffer().getPrice()) + " �"); - jTextField3.setText(Float.toString(book.getPrice()) + "€"); ++ jTextField3.setText(Float.toString(book.getOffer().getPrice()) + " €"); jTextField4.setBounds(new Rectangle(180, 175, 115, 25)); jTextField4.setEditable(false); - jTextField4.setText(Float.toString(book.getOffer().getPrice()*(float)0.2) + " �"); - jTextField4.setText(Float.toString(book.getPrice()*(float)0.2) + "€"); ++ jTextField4.setText(Float.toString(book.getOffer().getPrice()*(float)0.2) + " €"); ++ this.getContentPane().add(jTextField4, null); this.getContentPane().add(jTextField3, null); this.getContentPane().add(jLabel5, null); diff --cc ruralHouses client/src/gui/DeleteOwnerGUI.java index 0000000,19d5513..982e022 mode 000000,100644..100644 --- a/ruralHouses client/src/gui/DeleteOwnerGUI.java +++ b/ruralHouses client/src/gui/DeleteOwnerGUI.java @@@ -1,0 -1,139 +1,139 @@@ + package gui; + + 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.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.AccountInterface; + import common.AdminInterface; + + import configuration.___IntNames; + import domain.Owner; + + public class DeleteOwnerGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTable table; + + private DefaultTableModel tableModel; + private AdminInterface AdM = null; + private Vector owners = new Vector(); + + /** + * Create the frame. + */ + public DeleteOwnerGUI() { + setTitle("Current owners:"); + 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); + try { + AdM = (AdminInterface) Naming + .lookup(___IntNames.AdminManager); + } catch (Exception e1) { + System.out + .println("Error accessing remote authentication: " + + e1.toString()); + } + this.owners = AdM.getAllOwners(); + JLabel lblNewLabel = new JLabel(); + lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); + lblNewLabel.setBounds(23, 41, 536, 33); + contentPane.add(lblNewLabel); + if (this.owners.isEmpty()) + lblNewLabel + .setText("There are not owners in the system"); + else + lblNewLabel.setText("List of owners:"); + JScrollPane scrollPane = new JScrollPane(); + scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); + scrollPane.setBounds(23, 113, 536, 271); + contentPane.add(scrollPane); - JLabel feedback = new JLabel(""); ++ final JLabel feedback = new JLabel(""); + feedback.setBounds(134, 447, 307, 14); + contentPane.add(feedback); + JButton btnNewButton = new JButton("Delete from the system"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (table.getRowCount()!=0 && table.getSelectedRow() != -1) { + AccountInterface acm = null; + + try { + acm = (AccountInterface) Naming + .lookup(___IntNames.AccountManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + + try { + if(acm.removeAccount(table.getSelectedRow())) + { + feedback.setText("Deleted from the system"); + } + } catch (RemoteException e1) { + e1.printStackTrace(); + } + + ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow()); + } + } + }); + btnNewButton.setBounds(88, 396, 428, 40); + contentPane.add(btnNewButton); + 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" }); + + table.setModel(tableModel); + + + Enumeration rhs = this.owners.elements(); + while (rhs.hasMoreElements()) { + Owner own = rhs.nextElement(); + Vector row = new Vector(); + row.add(own.getName()); + row.add(own.getMailAccount()); + row.add(own.getBankAccount()); + tableModel.addRow(row); + } + + + } + } diff --cc ruralHouses client/src/gui/ModifyOfferGUI.java index d5422bf,14dd98d..3e7a6c6 --- a/ruralHouses client/src/gui/ModifyOfferGUI.java +++ b/ruralHouses client/src/gui/ModifyOfferGUI.java @@@ -89,9 -89,7 +89,9 @@@ public class ModifyOfferGUI extends JFr Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0); } catch (RemoteException e1) { e1.printStackTrace(); - } + } + - ++ jComboBox1 = new JComboBox(Hlist); comboBox_o = new JComboBox( diff --cc ruralHouses/src/businessLogic/BookingManager.java index 985bf56,f0d0a54..138484b --- a/ruralHouses/src/businessLogic/BookingManager.java +++ b/ruralHouses/src/businessLogic/BookingManager.java @@@ -35,10 -39,41 +37,9 @@@ public final class BookingManager exten } } - /** - * This method returns the next Booking number - * - * @return the book number - */ - - public int getNumber() throws RemoteException{ - ObjectContainer db=DB4oManager.getContainer(); - BookingManager b=getInstance(); - b.bookingNumber++; - db.store(b); - db.commit(); - return b.bookingNumber; - } - /** - * This method returns the instance of the BookingManager class - * - * @return the booking manager - * @throws RemoteException - */ - - public BookingManager getInstance() throws RemoteException { - ObjectContainer db=DB4oManager.getContainer(); - BookingManager b = new BookingManager(); - ObjectSet result = db.queryByExample(b); - if (!result.hasNext()){ - theBookingManager = new BookingManager(); - db.store(theBookingManager); - db.commit(); - } else theBookingManager=(BookingManager)result.next(); - return theBookingManager; - } - public void removeDenyBooking(Booking b) throws RemoteException{ - b.getOffer().getBookings().remove(b); + public void denyBooking(Booking b) throws RemoteException{ this.dbMngr.removeBooking(b); } diff --cc ruralHouses/src/common/BookingInterface.java index 0d2db53,8780f2f..598a537 --- a/ruralHouses/src/common/BookingInterface.java +++ b/ruralHouses/src/common/BookingInterface.java @@@ -13,9 -13,10 +13,9 @@@ import exceptions.OfferCanNotBeBooked public interface BookingInterface extends Remote { - public int getNumber() throws RemoteException; - public void removeDenyBooking(Booking b) throws RemoteException; + public void denyBooking(Booking b) throws RemoteException; public void acceptBooking(Booking b) throws RemoteException; diff --cc ruralHouses/src/dataAccess/DB4oManager.java index baab98a,a52ba8c..d17876f --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@@ -371,6 -380,23 +380,8 @@@ public class DB4oManager } } - public Vector getAllRuralHouses() throws RemoteException, - Exception { + - if (c.isDatabaseLocal() == false) - openSDB(); - else - openDB(); - - try { - RuralHouse proto = new RuralHouse(null, null, null, null, null); - ObjectSet result = db.queryByExample(proto); - return new Vector(result); - } finally { - db.close(); - } - } + public boolean existsOverlappingOffer(RuralHouse rh, Date firstDay, Date lastDay) throws RemoteException, OverlappingOfferExists { @@@ -539,11 -567,9 +548,9 @@@ openDB(); try { - ObjectSet result = db.queryByExample(new Account(acc - .getUsername())); - ObjectSet result = db.queryByExample(new Account(own)); ++ ObjectSet result = db.queryByExample(new Account(null,null,own)); if (!result.isEmpty()) { db.delete(result.get(0)); - ; db.commit(); return true; } diff --cc ruralHouses/src/domain/Account.java index ff19267,08e841c..7fb472c --- a/ruralHouses/src/domain/Account.java +++ b/ruralHouses/src/domain/Account.java @@@ -2,9 -2,9 +2,9 @@@ package domain import java.io.Serializable; import java.util.Arrays; -- import businessLogic.SecurityManager; ++ public class Account implements Serializable { /** @@@ -21,7 -21,7 +21,6 @@@ private Owner owner; private boolean admin = false; -- public Account(byte[] usr){ this.username = usr; this.salt =null; @@@ -48,7 -55,7 +47,9 @@@ } ++ ++ public byte[] getUsername() { return username; } diff --cc ruralHouses/src/domain/Administrator.java index 8244f09,8244f09..eb42f26 --- a/ruralHouses/src/domain/Administrator.java +++ b/ruralHouses/src/domain/Administrator.java @@@ -55,6 -55,6 +55,7 @@@ public class Administrator implements S } } ++ public LinkedList getAddRequest() { return addRequest; } diff --cc ruralHouses/src/domain/Booking.java index 68575c6,60cfd2f..4b68a70 --- a/ruralHouses/src/domain/Booking.java +++ b/ruralHouses/src/domain/Booking.java @@@ -13,19 -13,31 +13,26 @@@ public class Booking implements Seriali private Date bookingDate; private Client client; private Offer offer; - - public Booking(int bN, Offer offer, Client client, Date date) { + + + + public Booking(int bN , Offer offer,Client client) { + this.bookingNumber = bN; this.offer = offer; - this.client = client; - // Booking date is assigned to actual date - this.bookingDate = date; + this.client=client; + //Booking date is assigned to actual date + this.bookingDate= new java.util.Date(System.currentTimeMillis()); } + - public Booking(int bN, Offer offer, Client client) { - ++ public Booking(int bN , Offer offer,Client client, Date bookDate) { + this.bookingNumber = bN; + this.offer = offer; - this.client = client; - // Booking date is assigned to actual date - this.bookingDate = new java.util.Date(System.currentTimeMillis()); - } ++ this.client=client; ++ this.bookingDate= bookDate; } + - public void imprimete() { - System.out.println(bookingNumber); - System.out.println(bookingDate); - System.out.println(client.toString()); - System.out.println(offer); - } + public int getBookNumber() { return this.bookingNumber; } diff --cc ruralHouses/src/domain/Client.java index 4dd9eb2,28730df..a4c0baf --- a/ruralHouses/src/domain/Client.java +++ b/ruralHouses/src/domain/Client.java @@@ -1,7 -1,13 +1,13 @@@ package domain; - public class Client { + import java.io.Serializable; -public class Client implements Serializable{ ++public class Client implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1L; private String name; private String mailAccount; private String telephone; diff --cc ruralHouses/src/domain/Owner.java index eb436f9,eb436f9..6bf0f97 --- a/ruralHouses/src/domain/Owner.java +++ b/ruralHouses/src/domain/Owner.java @@@ -14,10 -14,10 +14,6 @@@ public class Owner implements Serializa private String mailAccount = ""; private Vector ruralHouses; --// public Owner(String name) { --// this.name = name; --// ruralHouses = new hVector(); --// } public Owner(String name, String bankAccount,String mail) { this.bankAccount = bankAccount; diff --cc ruralHouses/src/domain/RuralHouse.java index 27f8d7f,529f691..0c7fbb7 --- a/ruralHouses/src/domain/RuralHouse.java +++ b/ruralHouses/src/domain/RuralHouse.java @@@ -14,8 -14,10 +14,9 @@@ public class RuralHouse implements Seri private Owner owner; private String district; private HouseFeatures features; - private Vector offers; - private boolean isAccepted; + public Vector offers; + public RuralHouse() { super(); } @@@ -113,11 -167,13 +114,12 @@@ return null; } + - public boolean isAccepted() { - return isAccepted; - } + public Vector getAllOffers() { - public void setAccepted(boolean isAccepted) { - this.isAccepted = isAccepted; + return this.offers; } ++ } diff --cc ruralHouses/src/gui/AdminMenuGUI.java index eef2ba4,0000000..24dcb27 mode 100644,000000..100644 --- a/ruralHouses/src/gui/AdminMenuGUI.java +++ b/ruralHouses/src/gui/AdminMenuGUI.java @@@ -1,84 -1,0 +1,76 @@@ +package gui; + +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + - import javax.swing.GroupLayout; - import javax.swing.GroupLayout.Alignment; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; + +public class AdminMenuGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + + + + /** + * Create the frame. + */ + public AdminMenuGUI() { + + + this.setTitle("Administrator Menu"); + this.getContentPane().setLayout(null); - setBounds(100, 100, 450, 473); ++ setBounds(100, 100, 450, 500); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + //TODO BOTH BUTTONS ARE TO MODIFY + JButton btnAdd = new JButton("Add requests"); ++ btnAdd.setBounds(120, 67, 164, 81); + btnAdd.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Frame a = new listOfAdditionRequestsGUI(); + a.setVisible(true); + } + }); + + JButton btnDel = new JButton("Delete Requests"); ++ btnDel.setBounds(120, 159, 164, 73); + btnDel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Frame a = new listOfRemovalRequestsGUI(); + a.setVisible(true); + } + }); + + JButton btnOwneraddition = new JButton("OwnerAddition"); ++ btnOwneraddition.setBounds(120, 243, 164, 73); + btnOwneraddition.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + Frame a = new listOfOwnerAddittionRequests(); + a.setVisible(true); + } + }); - GroupLayout gl_contentPane = new GroupLayout(contentPane); - gl_contentPane.setHorizontalGroup( - gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(115) - .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false) - .addComponent(btnOwneraddition, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(btnDel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE) - .addComponent(btnAdd, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)) - .addContainerGap(145, Short.MAX_VALUE)) - ); - gl_contentPane.setVerticalGroup( - gl_contentPane.createParallelGroup(Alignment.LEADING) - .addGroup(gl_contentPane.createSequentialGroup() - .addGap(62) - .addComponent(btnAdd, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) - .addGap(58) - .addComponent(btnDel, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE) - .addGap(52) - .addComponent(btnOwneraddition, GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE) - .addContainerGap()) - ); - contentPane.setLayout(gl_contentPane); ++ contentPane.setLayout(null); ++ contentPane.add(btnOwneraddition); ++ contentPane.add(btnDel); ++ contentPane.add(btnAdd); ++ ++ JButton btnOwnerDeletion = new JButton("Owner Deletion"); ++ btnOwnerDeletion.setBounds(120, 331, 164, 73); ++ btnOwnerDeletion.addActionListener(new ActionListener() { ++ public void actionPerformed(ActionEvent e) { ++ Frame a = new DeleteOwnerGUI(); ++ a.setVisible(true); ++ } ++ }); ++ contentPane.add(btnOwnerDeletion); + } +} diff --cc ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java index c26d9df,0000000..21f9ab6 mode 100644,000000..100644 --- a/ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java +++ b/ruralHouses/src/gui/BookRuralHouseConfirmationWindow.java @@@ -1,102 -1,0 +1,103 @@@ +package gui; + +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JTextField; + +import domain.Booking; + +public class BookRuralHouseConfirmationWindow extends JFrame { + private static final long serialVersionUID = 1L; + + private JLabel jLabel1 = new JLabel(); + private JTextField jTextField1 = new JTextField(); + private JLabel jLabel2 = new JLabel(); + private JTextField jTextField2 = new JTextField(); + private JLabel jLabel3 = new JLabel(); + private JButton jButton1 = new JButton(); + private JLabel jLabel4 = new JLabel(); + private JLabel jLabel5 = new JLabel(); + private JTextField jTextField3 = new JTextField(); + private JTextField jTextField4 = new JTextField(); + + public BookRuralHouseConfirmationWindow(Booking book) + { + try + { + jbInit(book); + } + catch(Exception e) + { + e.printStackTrace(); + } + + } + + private void jbInit(Booking book) throws Exception + { + + + this.getContentPane().setLayout(null); + this.setSize(new Dimension(416, 316)); + this.setTitle("See Booking Details"); + this.setResizable(false); + jLabel1.setText("Owner Bank account number:"); + jLabel1.setBounds(new Rectangle(20, 20, 200, 25)); + jTextField1.setBounds(new Rectangle(225, 20, 165, 25)); + jTextField1.setEditable(false); + + jTextField1.setText(book.getOffer().getRuralHouse().getOwner().getBankAccount()); + + jLabel2.setText("Booking number:"); + jLabel2.setBounds(new Rectangle(20, 60, 130, 25)); + jTextField2.setBounds(new Rectangle(225, 60, 165, 25)); + jTextField2.setEditable(false); + + jTextField2.setText(Integer.toString(book.getBookNumber())); + + jLabel3.setText("You must deposit 20% of the total ammount of a book in the next three days."); + jLabel3.setBounds(new Rectangle(20, 105, 370, 25)); + jButton1.setText("Close"); + jButton1.setBounds(new Rectangle(135, 235, 130, 30)); + jButton1.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + jButton1_actionPerformed(e); + } + }); + jLabel4.setText("Total:"); + jLabel4.setBounds(new Rectangle(70, 140, 85, 25)); + jLabel5.setText("Deposit ammount:"); + jLabel5.setBounds(new Rectangle(70, 175, 100, 25)); + jTextField3.setBounds(new Rectangle(180, 140, 115, 25)); + jTextField3.setEditable(false); + - jTextField3.setText(Float.toString(book.getOffer().getPrice()) + " �"); ++ jTextField3.setText(Float.toString(book.getOffer().getPrice()) + " €"); + jTextField4.setBounds(new Rectangle(180, 175, 115, 25)); + jTextField4.setEditable(false); - jTextField4.setText(Float.toString(book.getOffer().getPrice()*(float)0.2) + " �"); ++ jTextField4.setText(Float.toString(book.getOffer().getPrice()*(float)0.2) + " €"); ++ + this.getContentPane().add(jTextField4, null); + this.getContentPane().add(jTextField3, null); + this.getContentPane().add(jLabel5, null); + this.getContentPane().add(jLabel4, null); + this.getContentPane().add(jButton1, null); + this.getContentPane().add(jLabel3, null); + this.getContentPane().add(jTextField2, null); + this.getContentPane().add(jLabel2, null); + this.getContentPane().add(jTextField1, null); + this.getContentPane().add(jLabel1, null); + } + + private void jButton1_actionPerformed(ActionEvent e) + { + this.setVisible(false); + } +} diff --cc ruralHouses/src/gui/DeleteOfferGUI.java index d3a79e4,0000000..d9f5ab8 mode 100644,000000..100644 --- a/ruralHouses/src/gui/DeleteOfferGUI.java +++ b/ruralHouses/src/gui/DeleteOfferGUI.java @@@ -1,145 -1,0 +1,159 @@@ +package gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.rmi.Naming; ++import java.rmi.RemoteException; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.border.EmptyBorder; + ++import common.HouseInterface; +import common.OfferInterface; + +import configuration.___IntNames; +import domain.Offer; +import domain.Owner; +import domain.RuralHouse; + +public class DeleteOfferGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; - private Owner owner; + private JLabel feedback; + private JComboBox comboBox; + private JComboBox comboBox_1; + private JButton btnDelete; ++ private Vector Hlist = null; ++ private HouseInterface hm = null; + + /** + * Create the frame. + */ + public DeleteOfferGUI(Owner o) { - this.owner = o; ++ try { ++ hm = (HouseInterface) Naming ++ .lookup(___IntNames.HouseManager); ++ } catch (Exception e1) { ++ System.out.println("Error accessing remote authentication: " ++ + e1.toString()); ++ } ++ try { ++ Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0); ++ } catch (RemoteException e1) { ++ e1.printStackTrace(); ++ } + setBounds(100, 100, 450, 300); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + - comboBox = new JComboBox(this.owner.getRuralHouses()); ++ comboBox = new JComboBox(this.Hlist); + comboBox.setBounds(101, 38, 314, 20); + + comboBox_1 = new JComboBox(); + comboBox_1.setBounds(101, 76, 314, 20); - Vector vo = ((RuralHouse) comboBox.getSelectedItem()).offers; ++ Vector vo = ((RuralHouse) comboBox.getSelectedItem()).getAllOffers(); + comboBox_1.removeAllItems(); + for (Offer of : vo) { + comboBox_1.addItem(of); + ; + } + + JRadioButton rdbtnIAmSure = new JRadioButton("I am sure"); + rdbtnIAmSure.setBounds(101, 134, 108, 23); + + btnDelete = new JButton("DELETE"); + btnDelete.setBounds(92, 226, 117, 23); + btnDelete.setEnabled(false); + + comboBox.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent arg0) { - Vector vo = ((RuralHouse) comboBox.getSelectedItem()).offers; ++ Vector vo = ((RuralHouse) comboBox.getSelectedItem()).getAllOffers(); + comboBox_1.removeAllItems(); + for (Offer of : vo) { + comboBox_1.addItem(of); + ; + } + + } + + }); + + rdbtnIAmSure.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + int state = e.getStateChange(); + if (state == ItemEvent.SELECTED) { + if (comboBox_1.getSelectedItem() != null) + btnDelete.setEnabled(true); + } else if (state == ItemEvent.DESELECTED) { + btnDelete.setEnabled(false); + } + } + }); + + JLabel lblHouse = new JLabel("House:"); + lblHouse.setBounds(25, 41, 68, 14); + + JLabel lblOffer = new JLabel("Offer:"); + lblOffer.setBounds(25, 79, 68, 14); + contentPane.setLayout(null); + contentPane.add(btnDelete); + contentPane.add(rdbtnIAmSure); + contentPane.add(lblHouse); + contentPane.add(lblOffer); + contentPane.add(comboBox); + contentPane.add(comboBox_1); + + feedback = new JLabel(""); + feedback.setBounds(140, 178, 202, 23); + contentPane.add(feedback); + + btnDelete.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + actionListenerButton(arg0); + + } + + }); + } + + private void actionListenerButton(ActionEvent e) { + + Offer toDel = (Offer) comboBox_1.getSelectedItem(); + OfferInterface oM = null; + try { + oM = (OfferInterface) Naming + .lookup(___IntNames.OfferManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + + try { + oM.deleteOffer((RuralHouse) comboBox.getSelectedItem(), toDel); + comboBox_1.removeItem(toDel); + btnDelete.setEnabled(false); + feedback.setText("Offer correctly deleted"); + } catch (Exception e1) { + feedback.setText("Imposible to delete the offer"); + e1.printStackTrace(); + } + + } +} diff --cc ruralHouses/src/gui/DeleteOwnerGUI.java index 0000000,0000000..982e022 new file mode 100644 --- /dev/null +++ b/ruralHouses/src/gui/DeleteOwnerGUI.java @@@ -1,0 -1,0 +1,139 @@@ ++package gui; ++ ++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.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.AccountInterface; ++import common.AdminInterface; ++ ++import configuration.___IntNames; ++import domain.Owner; ++ ++public class DeleteOwnerGUI extends JFrame { ++ ++ /** ++ * ++ */ ++ private static final long serialVersionUID = 1L; ++ private JPanel contentPane; ++ private JTable table; ++ ++ private DefaultTableModel tableModel; ++ private AdminInterface AdM = null; ++ private Vector owners = new Vector(); ++ ++ /** ++ * Create the frame. ++ */ ++ public DeleteOwnerGUI() { ++ setTitle("Current owners:"); ++ 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); ++ try { ++ AdM = (AdminInterface) Naming ++ .lookup(___IntNames.AdminManager); ++ } catch (Exception e1) { ++ System.out ++ .println("Error accessing remote authentication: " ++ + e1.toString()); ++ } ++ this.owners = AdM.getAllOwners(); ++ JLabel lblNewLabel = new JLabel(); ++ lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27)); ++ lblNewLabel.setBounds(23, 41, 536, 33); ++ contentPane.add(lblNewLabel); ++ if (this.owners.isEmpty()) ++ lblNewLabel ++ .setText("There are not owners in the system"); ++ else ++ lblNewLabel.setText("List of owners:"); ++ JScrollPane scrollPane = new JScrollPane(); ++ scrollPane.setBounds(new Rectangle(45, 305, 320, 116)); ++ scrollPane.setBounds(23, 113, 536, 271); ++ contentPane.add(scrollPane); ++ final JLabel feedback = new JLabel(""); ++ feedback.setBounds(134, 447, 307, 14); ++ contentPane.add(feedback); ++ JButton btnNewButton = new JButton("Delete from the system"); ++ btnNewButton.addActionListener(new ActionListener() { ++ public void actionPerformed(ActionEvent e) { ++ if (table.getRowCount()!=0 && table.getSelectedRow() != -1) { ++ AccountInterface acm = null; ++ ++ try { ++ acm = (AccountInterface) Naming ++ .lookup(___IntNames.AccountManager); ++ } catch (Exception e1) { ++ System.out.println("Error accessing remote authentication: " ++ + e1.toString()); ++ } ++ ++ try { ++ if(acm.removeAccount(table.getSelectedRow())) ++ { ++ feedback.setText("Deleted from the system"); ++ } ++ } catch (RemoteException e1) { ++ e1.printStackTrace(); ++ } ++ ++ ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow()); ++ } ++ } ++ }); ++ btnNewButton.setBounds(88, 396, 428, 40); ++ contentPane.add(btnNewButton); ++ 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" }); ++ ++ table.setModel(tableModel); ++ ++ ++ Enumeration rhs = this.owners.elements(); ++ while (rhs.hasMoreElements()) { ++ Owner own = rhs.nextElement(); ++ Vector row = new Vector(); ++ row.add(own.getName()); ++ row.add(own.getMailAccount()); ++ row.add(own.getBankAccount()); ++ tableModel.addRow(row); ++ } ++ ++ ++ } ++} diff --cc ruralHouses/src/gui/HouseFeaturesGUI.java index 62e81e9,0000000..39d0bc9 mode 100644,000000..100644 --- a/ruralHouses/src/gui/HouseFeaturesGUI.java +++ b/ruralHouses/src/gui/HouseFeaturesGUI.java @@@ -1,319 -1,0 +1,322 @@@ +package gui; + +import java.awt.Color; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.rmi.Naming; +import java.util.Date; +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.JTextField; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; + +import common.BookingInterface; + +import configuration.___IntNames; +import domain.Booking; +import domain.Client; +import domain.Offer; +import domain.RuralHouse; + +public class HouseFeaturesGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JLabel lblDistrict; + private JTextField District_f; + private JLabel lblDescription; + private JTextField description_f; + private JLabel lblKitchen; + private JTextField kitchens_f; + private JLabel lblRooms; + private JTextField rooms_f; + private JLabel lblLivings; + private JTextField lRooms_f; + private JLabel lblParkings; + private JTextField parkings_f; + private JLabel lblBaths; + private JTextField baths_f; + private JTable table; + private DefaultTableModel tableModel; + private RuralHouse rh; ++ private Vector offers= new Vector(); + private JTextField telIn; + private int row; + private JLabel labelPhone; + private JLabel lblName; + private JTextField nameField; + private JLabel lblEmail; + private JTextField mailField; + + /** + * Create the frame. + */ + + public HouseFeaturesGUI(RuralHouse RH, final Date FirstDay, + final Date LastDay) { + this.rh = RH; + this.getContentPane().setLayout(null); + setBounds(100, 100, 500, 700); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + + lblDistrict = new JLabel("District:"); + lblDistrict.setBounds(23, 67, 70, 14); + lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT); + + District_f = new JTextField(); + District_f.setEditable(false); + District_f.setBounds(103, 64, 86, 20); + District_f.setColumns(10); + + lblDescription = new JLabel("Description:"); + lblDescription.setBounds(215, 67, 90, 14); + lblDescription.setHorizontalAlignment(SwingConstants.RIGHT); + + description_f = new JTextField(); + description_f.setEditable(false); + description_f.setBounds(238, 99, 178, 129); + description_f.setColumns(10); + + lblKitchen = new JLabel("Kitchens:"); + lblKitchen.setBounds(23, 211, 70, 14); + lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT); + + kitchens_f = new JTextField(); + kitchens_f.setEditable(false); + kitchens_f.setBounds(103, 202, 86, 20); + kitchens_f.setColumns(10); + + lblRooms = new JLabel("Rooms:"); + lblRooms.setBounds(23, 102, 70, 14); + lblRooms.setHorizontalAlignment(SwingConstants.RIGHT); + + rooms_f = new JTextField(); + rooms_f.setEditable(false); + rooms_f.setBounds(103, 99, 86, 20); + rooms_f.setColumns(10); + + lblLivings = new JLabel("Living rooms:"); + lblLivings.setBounds(30, 236, 63, 14); + lblLivings.setHorizontalAlignment(SwingConstants.RIGHT); + + lRooms_f = new JTextField(); + lRooms_f.setEditable(false); + lRooms_f.setBounds(103, 233, 86, 20); + lRooms_f.setColumns(10); + + lblParkings = new JLabel("Parkings:"); + lblParkings.setBounds(23, 174, 70, 14); + lblParkings.setHorizontalAlignment(SwingConstants.RIGHT); + + parkings_f = new JTextField(); + parkings_f.setEditable(false); + parkings_f.setBounds(103, 171, 86, 20); + parkings_f.setColumns(10); + + lblBaths = new JLabel("Baths:"); + lblBaths.setBounds(23, 143, 70, 14); + lblBaths.setHorizontalAlignment(SwingConstants.RIGHT); + + baths_f = new JTextField(); + baths_f.setEditable(false); + baths_f.setBounds(103, 140, 86, 20); + baths_f.setColumns(10); + contentPane.setLayout(null); + contentPane.add(lblParkings); + contentPane.add(parkings_f); + contentPane.add(lblRooms); + contentPane.add(rooms_f); + contentPane.add(lblBaths); + contentPane.add(baths_f); + contentPane.add(lblDistrict); + contentPane.add(District_f); + contentPane.add(lblLivings); + contentPane.add(lRooms_f); + contentPane.add(lblKitchen); + contentPane.add(kitchens_f); + contentPane.add(description_f); + contentPane.add(lblDescription); + parkings_f.setText(Integer.toString(rh.getFeatures().getnParkings())); + rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); + baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); + District_f.setText(rh.getDistrict()); + kitchens_f.setText(Integer.toString(rh.getFeatures().getnKitchens())); + description_f.setText(rh.getDescription()); + lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings())); + JLabel lblAvailbleOffers = new JLabel("Availble Offers:"); + lblAvailbleOffers.setBounds(30, 286, 86, 14); + contentPane.add(lblAvailbleOffers); + JScrollPane scrollPane = new JScrollPane(); + scrollPane.setBounds(40, 311, 376, 183); + contentPane.add(scrollPane); + + table = new JTable() { + private static final long serialVersionUID = 1L; + + public boolean isCellEditable(int row, int column) { + return false; + }; + }; + tableModel = new DefaultTableModel(null, new String[] { "Offer #", + "FirstDay", "LastDay", "Price" }); + table.setModel(tableModel); + scrollPane.setViewportView(table); + + JButton btnBookSelected = new JButton("Book SelectedOffer"); + btnBookSelected.setBounds(238, 614, 178, 23); + contentPane.add(btnBookSelected); + + btnBookSelected.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + jButton_ActionPerformed(arg0); + } + + }); + + JLabel lblNewLabel = new JLabel( + "Green: Suit your dates. Red: Do not suit your dates"); + lblNewLabel.setEnabled(false); + lblNewLabel.setBounds(170, 282, 261, 23); + contentPane.add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("Telephone num:"); + lblNewLabel_1.setBounds(10, 618, 83, 14); + contentPane.add(lblNewLabel_1); + + telIn = new JTextField(); + telIn.setBounds(103, 615, 129, 20); + contentPane.add(telIn); + telIn.setColumns(10); + + labelPhone = new JLabel(""); + labelPhone.setBounds(238, 252, 178, 14); + contentPane.add(labelPhone); + + lblName = new JLabel("Name:"); + lblName.setBounds(10, 516, 46, 14); + contentPane.add(lblName); + + nameField = new JTextField(); + nameField.setBounds(103, 513, 178, 20); + contentPane.add(nameField); + nameField.setColumns(10); + + lblEmail = new JLabel("E-mail:"); + lblEmail.setBounds(10, 565, 46, 14); + contentPane.add(lblEmail); + + mailField = new JTextField(); + mailField.setBounds(103, 562, 178, 20); + contentPane.add(mailField); + mailField.setColumns(10); + + table.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent arg0) { + row = table.getSelectedRow(); + } + }); + + Enumeration rhs = rh.getAllOffers().elements(); + while (rhs.hasMoreElements()) { + Offer of = rhs.nextElement(); - if (of.getBookings() != null) { ++ if (of.getBookings() == null ++ || !of.isBooked()) { ++ offers.add(of); + Vector row = new Vector(); + row.add(of.getOfferNumber()); + row.add(of.getFirstDay()); + row.add(of.getLastDay()); + row.add(of.getPrice()); + 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); + + Date firstDay = (Date) table.getModel().getValueAt(row, 1); + Date lastDay = (Date) table.getModel().getValueAt(row, 2); + if (FirstDay != null && LastDay != null) { + if (LastDay.before(lastDay) || FirstDay.after(firstDay)) { + setBackground(Color.RED); + setForeground(Color.BLACK); + } else { + setBackground(Color.GREEN); + setForeground(Color.BLACK); + } + } + return this; + } + }); + } + + private void jButton_ActionPerformed(ActionEvent arg0) { + + BookingInterface bookingM = null; + try { + bookingM = (BookingInterface) Naming + .lookup(___IntNames.BookingManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + + if (telIn.getText().matches("[976]\\d{2}[.\\- ]?\\d{3}[.\\- ]?\\d{3}") + && mailField + .getText() + .matches( + "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$") + && !nameField.getText().isEmpty()) { + labelPhone.setText(""); + Vector book = null; + try { + if (table.getRowCount() != 0) { + Client cl = new Client(nameField.getText(), + mailField.getText(), telIn.getText()); - book = bookingM.createBooking(rh, rh.offers.get(row) - .getFirstDay(), rh.offers.get(row).getLastDay(),cl); ++ book = bookingM.createBooking(rh, offers.get(row) ++ .getFirstDay(), offers.get(row).getLastDay(),cl); + } + } catch (Exception e) { + e.printStackTrace(); + } + if (book != null) { + BookRuralHouseConfirmationWindow confirmWindow = new BookRuralHouseConfirmationWindow( + book.lastElement()); + confirmWindow.setVisible(true); + } + } else { + labelPhone.setText("Bad formatted data."); + + } + } +} diff --cc ruralHouses/src/gui/ModifyHouseGUI.java index 691b0ca,0000000..d5db84c mode 100644,000000..100644 --- a/ruralHouses/src/gui/ModifyHouseGUI.java +++ b/ruralHouses/src/gui/ModifyHouseGUI.java @@@ -1,236 -1,0 +1,237 @@@ +package gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.rmi.Naming; +import java.rmi.RemoteException; +import java.util.Vector; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; + +import common.HouseInterface; ++ +import configuration.___IntNames; +import domain.Districs; +import domain.HouseFeatures; +import domain.Owner; +import domain.RuralHouse; + +public class ModifyHouseGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private Owner owner; + private JLabel lblDistrict; + private JLabel feedback; + private JLabel lblDescription; + private JTextField description_f; + private JLabel lblKitchen; + private JTextField kitchens_f; + private JLabel lblRooms; + private JTextField rooms_f; + private JLabel lblLivings; + private JTextField lRooms_f; + private JLabel lblParkings; + private JTextField parkings_f; + private JLabel lblBaths; + private String[] distric; + private JTextField baths_f; + private JButton btnConfirm; + private JComboBox houseBox; + private JComboBox comboBox; + private RuralHouse rh; + + /** + * Create the frame. + */ + public ModifyHouseGUI(final Owner o) { + this.distric=Districs.longNames(); + comboBox = new JComboBox(new DefaultComboBoxModel( + + this.distric)); + this.getContentPane().setLayout(null); + owner = o; + setBounds(100, 100, 500, 583); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPane); + + JLabel lblCode = new JLabel("House Name:"); + lblCode.setBounds(15, 88, 64, 14); + lblCode.setHorizontalAlignment(SwingConstants.RIGHT); + + lblDistrict = new JLabel("District:"); + lblDistrict.setBounds(39, 119, 70, 14); + lblDistrict.setHorizontalAlignment(SwingConstants.RIGHT); + + lblDescription = new JLabel("Description:"); + lblDescription.setBounds(231, 88, 90, 14); + lblDescription.setHorizontalAlignment(SwingConstants.RIGHT); + + description_f = new JTextField(); + description_f.setBounds(241, 113, 178, 129); + description_f.setColumns(10); + + lblKitchen = new JLabel("Kitchens:"); + lblKitchen.setBounds(230, 316, 70, 14); + lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT); + + kitchens_f = new JTextField(); + kitchens_f.setBounds(318, 313, 86, 20); + kitchens_f.setColumns(10); + + lblRooms = new JLabel("Rooms:"); + lblRooms.setBounds(39, 316, 70, 14); + lblRooms.setHorizontalAlignment(SwingConstants.RIGHT); + + rooms_f = new JTextField(); + rooms_f.setBounds(127, 313, 86, 20); + rooms_f.setColumns(10); + + lblLivings = new JLabel("Living rooms:"); + lblLivings.setBounds(237, 354, 63, 14); + lblLivings.setHorizontalAlignment(SwingConstants.RIGHT); + + lRooms_f = new JTextField(); + lRooms_f.setBounds(318, 351, 86, 20); + lRooms_f.setColumns(10); + + lblParkings = new JLabel("Parkings:"); + lblParkings.setBounds(39, 404, 70, 14); + lblParkings.setHorizontalAlignment(SwingConstants.RIGHT); + + parkings_f = new JTextField(); + parkings_f.setBounds(127, 401, 86, 20); + parkings_f.setColumns(10); + + lblBaths = new JLabel("Baths:"); + lblBaths.setBounds(39, 354, 70, 14); + lblBaths.setHorizontalAlignment(SwingConstants.RIGHT); + + baths_f = new JTextField(); + baths_f.setBounds(127, 351, 86, 20); + baths_f.setColumns(10); + + btnConfirm = new JButton("Confirm"); + btnConfirm.setBounds(145, 462, 69, 23); + btnConfirm.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + RuralHouse newRh = new RuralHouse(rh.getHouseName(), owner, + description_f.getText(), (String)comboBox.getSelectedItem(), + new HouseFeatures(new Integer(rooms_f.getText()), + new Integer(kitchens_f.getText()), new Integer( + baths_f.getText()), new Integer( + lRooms_f.getText()), new Integer( + parkings_f.getText()))); + HouseInterface hm= null; + try { + hm = (HouseInterface) Naming + .lookup(___IntNames.HouseManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + + try { + if (hm.registerNewHouse(newRh)) { + owner.getRuralHouses().add(newRh); + houseBox.removeItem(rh); + feedback.setText("House properly modified"); + } else + feedback.setText("Imposible to modify the house"); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + }); + HouseInterface hm= null; + try { + hm = (HouseInterface) Naming + .lookup(___IntNames.HouseManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + Vector list = null; + try { + list = hm.getHouses(o, null, null, 0, 0, 0, 0, 0); + } catch (RemoteException e1) { + e1.printStackTrace(); + } + + houseBox = new JComboBox(list); + if (!o.getRuralHouses().isEmpty()) { + rh = (RuralHouse) houseBox.getSelectedItem(); + comboBox.setSelectedItem(rh.getDistrict()); + description_f.setText(rh.getDescription()); + kitchens_f.setText(Integer + .toString(rh.getFeatures().getnKitchens())); + rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); + lRooms_f.setText(Integer.toString(rh.getFeatures().getnLivings())); + parkings_f.setText(Integer + .toString(rh.getFeatures().getnParkings())); + baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); + houseBox.setBounds(89, 85, 124, 20); + }else{ + feedback.setText("Not available houses"); + btnConfirm.setEnabled(false); + } + houseBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + rh = (RuralHouse) houseBox.getSelectedItem(); + comboBox.setSelectedItem(rh.getDistrict()); + description_f.setText(rh.getDescription()); + kitchens_f.setText(Integer.toString(rh.getFeatures() + .getnKitchens())); + rooms_f.setText(Integer.toString(rh.getFeatures().getnRooms())); + lRooms_f.setText(Integer.toString(rh.getFeatures() + .getnLivings())); + parkings_f.setText(Integer.toString(rh.getFeatures() + .getnParkings())); + baths_f.setText(Integer.toString(rh.getFeatures().getnBaths())); + + } + }); + contentPane.setLayout(null); + contentPane.add(lblParkings); + contentPane.add(parkings_f); + contentPane.add(lblRooms); + contentPane.add(rooms_f); + contentPane.add(lblCode); + contentPane.add(houseBox); + contentPane.add(lblBaths); + contentPane.add(baths_f); + contentPane.add(lblDistrict); + contentPane.add(lblLivings); + contentPane.add(lRooms_f); + contentPane.add(lblKitchen); + contentPane.add(kitchens_f); + contentPane.add(description_f); + contentPane.add(lblDescription); + contentPane.add(btnConfirm); + + feedback = new JLabel(""); + feedback.setBounds(189, 510, 195, 23); + contentPane.add(feedback); + + comboBox.setBounds(127, 116, 86, 20); + contentPane.add(comboBox); + } +} diff --cc ruralHouses/src/gui/ModifyOfferGUI.java index d5422bf,0000000..3e7a6c6 mode 100644,000000..100644 --- a/ruralHouses/src/gui/ModifyOfferGUI.java +++ b/ruralHouses/src/gui/ModifyOfferGUI.java @@@ -1,333 -1,0 +1,334 @@@ +package gui; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.rmi.Naming; +import java.rmi.RemoteException; +import java.sql.Date; +import java.text.DateFormat; +import java.util.Calendar; +import java.util.Locale; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JTextField; + +import com.toedter.calendar.JCalendar; - +import common.HouseInterface; +import common.OfferInterface; ++ +import configuration.___IntNames; +import domain.Offer; +import domain.Owner; +import domain.RuralHouse; +import exceptions.BadDates; + +public class ModifyOfferGUI extends JFrame { + + private static final long serialVersionUID = 1L; + + private JComboBox 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 comboBox_o; + private Vector Hlist = null; + private OfferInterface om = null; + private HouseInterface hm = null; + + + public ModifyOfferGUI(Owner o) { + try { + jbInit(o); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void jbInit(Owner o) throws Exception { + this.getContentPane().setLayout(null); + this.setSize(new Dimension(513, 433)); + this.setTitle("Set availability"); + + + try { + om = (OfferInterface) Naming + .lookup(___IntNames.OfferManager); + hm = (HouseInterface) Naming + .lookup(___IntNames.HouseManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + try { + Hlist = hm.getHouses(o, null, null, 0, 0, 0, 0, 0); + } catch (RemoteException e1) { + e1.printStackTrace(); + } + - ++ + jComboBox1 = new JComboBox(Hlist); + + comboBox_o = new JComboBox( + ((RuralHouse) jComboBox1.getSelectedItem()).getAllOffers()); + DateFormat dateformat1 = DateFormat.getDateInstance(1, + jCalendar1.getLocale()); + if (!((RuralHouse) jComboBox1.getSelectedItem()).getAllOffers() + .isEmpty()) { + jTextField1.setText(dateformat1.format(((Offer) comboBox_o + .getSelectedItem()).getFirstDay())); + jTextField2.setText(dateformat1.format(((Offer) comboBox_o + .getSelectedItem()).getLastDay())); + jLabel4.setText(Float.toString(((Offer) comboBox_o + .getSelectedItem()).getPrice())); + jTextField3.setText(Float.toString(((Offer) comboBox_o + .getSelectedItem()).getPrice())); + } else { + jLabel5.setText("There are no offers for the selected rural house"); + jCalendar1.setEnabled(false); + jCalendar2.setEnabled(false); + jButton1.setEnabled(false); + comboBox_o.setEnabled(false); + jTextField3.setEnabled(false); + } + 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 vo= null; + try { + vo = om.getRuralHouseOffers((RuralHouse) jComboBox1.getSelectedItem()); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + comboBox_o.removeAllItems(); + if (!vo.isEmpty()) { + jCalendar1.setEnabled(true); + jCalendar2.setEnabled(true); + jButton1.setEnabled(true); + comboBox_o.setEnabled(true); + jTextField3.setEnabled(true); + jLabel5.setText(""); + for (Offer of : vo) { + comboBox_o.addItem(of); + } + } else { + jLabel5.setText("There are no offers for the selected rural house"); + jCalendar1.setEnabled(false); + jCalendar2.setEnabled(false); + jButton1.setEnabled(false); + comboBox_o.setEnabled(false); + jTextField3.setEnabled(false); + + } + } + + }); + + 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()); + + + try { + + // It could be to trigger an exception if the introduced string is + // not a number + float price = Float.parseFloat(jTextField3.getText()); + + // Obtain the business logic from a StartWindow class (local or + // remote) + OfferInterface offerM = null; + try { + offerM = (OfferInterface) Naming + .lookup(___IntNames.OfferManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + + offerM.deleteOffer(ruralHouse, (Offer) comboBox_o.getSelectedItem()); + offerM.createOffer(ruralHouse, firstDay, lastDay, price); + + jLabel5.setText("Offer modified"); + + } catch (java.lang.NumberFormatException e1) { + jLabel5.setText(jTextField3.getText() + " is not a valid price"); + } catch (BadDates e1) { + jLabel5.setText("Last day is before first day in the offer"); + } 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"); + } + } +} diff --cc ruralHouses/src/gui/OwnerRegistrationGUI.java index 5a4ffe9,0000000..62395d5 mode 100644,000000..100644 --- a/ruralHouses/src/gui/OwnerRegistrationGUI.java +++ b/ruralHouses/src/gui/OwnerRegistrationGUI.java @@@ -1,162 -1,0 +1,170 @@@ +package gui; + +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.rmi.Naming; +import java.rmi.RemoteException; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; + +import common.AdminInterface; + +import configuration.___IntNames; +import domain.Owner; + +public class OwnerRegistrationGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel panel; + private JTextField nameField; + private JTextField userNameField; + private AdminInterface am = null; + 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() { - ++ + try { - am = (AdminInterface) Naming - .lookup(___IntNames.AdminManager); ++ am = (AdminInterface) Naming.lookup(___IntNames.AdminManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + 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()); - - - try { - if (this.am.addAccountRequest(this.userNameField.getText(), - this.passField.getText(), own)) { - this.am.saveInstance(); - this.feedback.setText("Request sended"); - } else { - this.feedback.setText("Can't send the request"); ++ if (!emailField ++ .getText() ++ .matches( ++ "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$") ++ || !this.nameField.getText().isEmpty()||this.bank1Field.getText().length()!=4 || this.bank2Field.getText().length()!=4 ++ ||this.bank3Field.getText().length()!=2 || this.bank4Field.getText().length()!=10) { ++ Owner own = new Owner(this.nameField.getText(), ++ this.bank1Field.getText() + " " + this.bank2Field.getText() ++ + " " + this.bank3Field.getText() + " " ++ + this.bank4Field.getText(), ++ this.emailField.getText()); ++ ++ try { ++ if (this.am.addAccountRequest(this.userNameField.getText(), ++ this.passField.getText(), own)) { ++ this.am.saveInstance(); ++ this.feedback.setText("Request sended"); ++ } else { ++ this.feedback.setText("Can't send the request"); ++ } ++ } catch (RemoteException e1) { ++ // TODO Auto-generated catch block ++ e1.printStackTrace(); + } - } catch (RemoteException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); ++ } else { ++ this.feedback.setText("Bad formatted data"); + } + + } +} diff --cc ruralHouses/src/gui/listOfAdditionRequestsGUI.java index d112532,0000000..30e5e66 mode 100644,000000..100644 --- a/ruralHouses/src/gui/listOfAdditionRequestsGUI.java +++ b/ruralHouses/src/gui/listOfAdditionRequestsGUI.java @@@ -1,163 -1,0 +1,162 @@@ +package gui; + +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.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.AdminInterface; +import common.HouseInterface; + +import configuration.___IntNames; +import domain.RuralHouse; + +public class listOfAdditionRequestsGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTable table; + private DefaultTableModel tableModel; + private AdminInterface am = null; + private Vector houses; + /** + * Create the frame. + */ + public listOfAdditionRequestsGUI() { + + try { + am = (AdminInterface) Naming + .lookup(___IntNames.AdminManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + + setTitle("Adding requests"); + try { + this.houses= am.getAdditionRequests(); + 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 (houses.isEmpty()) + lblNewLabel.setText("There are not houses to be added"); + else + lblNewLabel.setText("List of houses 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[] { + "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings", + "Livings" }); + + //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) { + HouseInterface hm= null; + try { + hm = (HouseInterface) Naming + .lookup(___IntNames.HouseManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + + RuralHouse rh = houses.get(table.getSelectedRow()); + //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that. + try { + hm.registerNewHouse(rh); + am.removeHouseAdditionRequests(rh); + am.saveInstance(); + } catch (RemoteException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); - houses.remove(rh); + } + } + }); + 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) { + RuralHouse rh = houses.get(table.getSelectedRow()); + try { + am.removeHouseAdditionRequests(rh); + am.saveInstance(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); + houses.remove(rh); + } + } + }); + btnDenyAddition.setBounds(300, 396, 169, 25); + contentPane.add(btnDenyAddition); + Enumeration en = houses.elements(); + RuralHouse rh; + + while (en.hasMoreElements()) { + rh = en.nextElement(); + Vector row = new Vector(); + row.add(rh.getHouseName()); + row.add(rh.getFeatures().getnRooms()); + row.add(rh.getFeatures().getnKitchens()); + row.add(rh.getFeatures().getnBaths()); + row.add(rh.getFeatures().getnParkings()); + row.add(rh.getFeatures().getnLivings()); + tableModel.addRow(row); + } + + } +} diff --cc ruralHouses/src/gui/listOfBookingRequestsGUI.java index 982d7f2,0000000..423ea4d mode 100644,000000..100644 --- a/ruralHouses/src/gui/listOfBookingRequestsGUI.java +++ b/ruralHouses/src/gui/listOfBookingRequestsGUI.java @@@ -1,140 -1,0 +1,197 @@@ +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.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.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; + +import common.BookingInterface; + ++import configuration.___IntNames; +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 BookingInterface bookM = null; + private DefaultTableModel tableModel; + private Vector bookings = new Vector(); + + /** + * 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(); ++ ++ 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" }); ++ 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) { ++ 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(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.removeDenyBooking(book); ++ bookM.denyBooking(book); + } catch (RemoteException e) { + e.printStackTrace(); + } ++ ((DefaultTableModel) table.getModel()).removeRow(table ++ .getSelectedRow()); ++ bookings.remove(book); + + } + } + }); ++ 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 en = this.bookings.elements(); + Booking book; + while (en.hasMoreElements()) { + book = en.nextElement(); + Vector row = new Vector(); + 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); + } ++ 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; ++ } ++ }); + } ++ +} diff --cc ruralHouses/src/gui/listOfOffers.java index 1a49f1c,0000000..7d61def mode 100644,000000..100644 --- a/ruralHouses/src/gui/listOfOffers.java +++ b/ruralHouses/src/gui/listOfOffers.java @@@ -1,110 -1,0 +1,138 @@@ +package gui; + ++import java.awt.Color; ++import java.awt.Component; +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Enumeration; +import java.util.Vector; + +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.DefaultTableCellRenderer; +import javax.swing.table.DefaultTableModel; + +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 DefaultTableModel tableModel; + private Vector offers = new Vector(); + + /** + * 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 = new Vector(); + for (RuralHouse rh: this.owner.getRuralHouses()){ + this.offers.addAll(rh.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 offers:"); + 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" ,"RuralHouse"}); + + // Maybe there is a better way to avoid interaction. + // table.setEnabled(false); + table.setModel(tableModel); + table.addMouseListener( new MouseAdapter(){ + @Override + public void mouseClicked(MouseEvent arg0) { + int row = table.getSelectedRow(); + listOfBookingRequestsGUI feat = new listOfBookingRequestsGUI(offers.get(row)); + feat.setVisible(true); + } + }); + Enumeration rhs = this.offers.elements(); + while (rhs.hasMoreElements()) { + Offer of = rhs.nextElement(); + Vector row = new Vector(); + row.add(of.getOfferNumber()); + row.add(of.getFirstDay()); + row.add(of.getLastDay()); + row.add(of.getPrice()); + row.add(of.getRuralHouse().getHouseName()); + 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 (!offers.get(row).isBooked()) { ++ setBackground(Color.ORANGE); ++ setForeground(Color.BLACK); ++ } else { ++ setBackground(Color.GREEN); ++ setForeground(Color.BLACK); ++ } ++ ++ return this; ++ } ++ }); + + } +} diff --cc ruralHouses/src/gui/listOfOwnerAddittionRequests.java index 01aaf8f,0000000..b3297b4 mode 100644,000000..100644 --- a/ruralHouses/src/gui/listOfOwnerAddittionRequests.java +++ b/ruralHouses/src/gui/listOfOwnerAddittionRequests.java @@@ -1,158 -1,0 +1,159 @@@ +package gui; + +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.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.AccountInterface; +import common.AdminInterface; + +import configuration.___IntNames; +import domain.Account; + +public class listOfOwnerAddittionRequests extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTable table; + private DefaultTableModel tableModel; + private AdminInterface am = null; + private Vector accounts; + /** + * Create the frame. + */ + public listOfOwnerAddittionRequests() { + try { + am = (AdminInterface) Naming + .lookup(___IntNames.AdminManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + setTitle("Adding requests"); + try { + this.accounts= am.getOwnerAdditionRequests(); + init(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void init() throws Exception { + + try { + am = (AdminInterface) Naming + .lookup(___IntNames.AdminManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + 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" }); + + 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) { + AccountInterface acm = null; + + try { + acm = (AccountInterface) Naming + .lookup(___IntNames.AccountManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + + try { + acm.addAccount(table.getSelectedRow()); + am.removeOwnerAdditionRequests(table.getSelectedRow()); + am.saveInstance(); + } catch (RemoteException e1) { + e1.printStackTrace(); + } - ++ + ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow()); ++ + } + } + }); + 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) { + try { + am.removeOwnerAdditionRequests(table.getSelectedRow()); + am.saveInstance(); + } catch (RemoteException e) { + e.printStackTrace(); + } + + ((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow()); + } + } + }); + btnDenyAddition.setBounds(300, 396, 169, 25); + contentPane.add(btnDenyAddition); + Enumeration en = accounts.elements(); + Account acc; + + while (en.hasMoreElements()) { + acc = en.nextElement(); + Vector row = new Vector(); + row.add(acc.getOwner().getName()); + row.add(acc.getOwner().getMailAccount()); + row.add(acc.getOwner().getBankAccount()); + tableModel.addRow(row); + } + + } +} diff --cc ruralHouses/src/gui/listOfRemovalRequestsGUI.java index 62daded,0000000..a85c246 mode 100644,000000..100644 --- a/ruralHouses/src/gui/listOfRemovalRequestsGUI.java +++ b/ruralHouses/src/gui/listOfRemovalRequestsGUI.java @@@ -1,160 -1,0 +1,158 @@@ +package gui; + +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.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.AdminInterface; +import common.HouseInterface; + +import configuration.___IntNames; +import domain.RuralHouse; + +public class listOfRemovalRequestsGUI extends JFrame { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTable table; + private DefaultTableModel tableModel; + private AdminInterface am = null; + private Vector houses; + + /** + * Create the frame. + */ + public listOfRemovalRequestsGUI() { + try { - am = (AdminInterface) Naming - .lookup(___IntNames.AdminManager); ++ am = (AdminInterface) Naming.lookup(___IntNames.AdminManager); + } catch (Exception e1) { + System.out.println("Error accessing remote authentication: " + + e1.toString()); + } + setTitle("Deleting requests"); + try { + this.houses = am.getDeletionRequests(); + 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 (houses.isEmpty()) + lblNewLabel.setText("There are not houses to be deleted"); + else + lblNewLabel.setText("List of houses to be deleted:"); + 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[] { "House Name", + "Bedrooms", "Kitchens", "Baths", "Parkings", "Livings" }); + + table.setModel(tableModel); + Enumeration en = houses.elements(); + RuralHouse rh; + JButton btnNewButton = new JButton("Confirm Deletion"); + btnNewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { - HouseInterface hm= null; ++ HouseInterface hm = null; + try { + hm = (HouseInterface) Naming + .lookup(___IntNames.HouseManager); + } catch (Exception e1) { - System.out.println("Error accessing remote authentication: " - + e1.toString()); ++ System.out ++ .println("Error accessing remote authentication: " ++ + e1.toString()); + } + RuralHouse rh = houses.get(table.getSelectedRow()); - ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); - try { - hm.removeHouse(rh, rh.getOwner()); - am.removeHouseDeletionRequests(rh); - am.saveInstance(); - } catch (RemoteException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - houses.remove(rh); - - - ++ ++ try { ++ hm.removeHouse(rh, rh.getOwner()); ++ am.removeHouseDeletionRequests(rh); ++ am.saveInstance(); ++ } catch (RemoteException e1) { ++ e1.printStackTrace(); ++ } ++ ((DefaultTableModel) table.getModel()).removeRow(houses ++ .indexOf(rh)); ++ houses.remove(rh); ++ + } + } + }); + btnNewButton.setBounds(90, 396, 169, 25); + contentPane.add(btnNewButton); - ++ + JButton btnNewButton_1 = new JButton("Deny Deletion"); + btnNewButton_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (table.getRowCount() != 0 && table.getSelectedRow() != -1) { + RuralHouse rh = houses.get(table.getSelectedRow()); - ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh)); - houses.remove(rh); - try { - am.removeHouseDeletionRequests(rh); - am.saveInstance(); - } catch (RemoteException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - - ++ ((DefaultTableModel) table.getModel()).removeRow(houses ++ .indexOf(rh)); ++ houses.remove(rh); ++ try { ++ am.removeHouseDeletionRequests(rh); ++ am.saveInstance(); ++ } catch (RemoteException e1) { ++ // TODO Auto-generated catch block ++ e1.printStackTrace(); ++ } ++ + } + } + }); + btnNewButton_1.setBounds(291, 396, 169, 25); + contentPane.add(btnNewButton_1); + while (en.hasMoreElements()) { + rh = en.nextElement(); + Vector row = new Vector(); + row.add(rh.getHouseName()); + row.add(rh.getFeatures().getnRooms()); + row.add(rh.getFeatures().getnKitchens()); + row.add(rh.getFeatures().getnBaths()); + row.add(rh.getFeatures().getnParkings()); + row.add(rh.getFeatures().getnLivings()); + tableModel.addRow(row); + } + + } +}