4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.util.Enumeration;
8 import java.util.Vector;
10 import javax.swing.JButton;
11 import javax.swing.JFrame;
12 import javax.swing.JLabel;
13 import javax.swing.JPanel;
14 import javax.swing.JScrollPane;
15 import javax.swing.JTable;
16 import javax.swing.border.EmptyBorder;
17 import javax.swing.table.DefaultTableModel;
19 import businessLogic.AccountManager;
20 import businessLogic.AdminManager;
21 import domain.Account;
22 import domain.Administrator;
24 public class ownerAddittionRequests extends JFrame {
29 private static final long serialVersionUID = 1L;
30 private JPanel contentPane;
32 private DefaultTableModel tableModel;
33 private AdminManager am = new AdminManager();
34 private Vector<Account> accounts;
38 public ownerAddittionRequests() {
39 setTitle("Adding requests");
41 this.accounts= am.getOwnerAdditionReuests();
43 } catch (Exception e) {
48 private void init() throws Exception {
49 setBounds(100, 100, 600, 450);
50 contentPane = new JPanel();
51 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
52 setContentPane(contentPane);
53 contentPane.setLayout(null);
55 JLabel lblNewLabel = new JLabel();
56 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
57 lblNewLabel.setBounds(23, 41, 536, 33);
58 contentPane.add(lblNewLabel);
59 if (accounts.isEmpty())
60 lblNewLabel.setText("There are not owners to be added");
62 lblNewLabel.setText("List of owners to be added:");
63 JScrollPane scrollPane = new JScrollPane();
64 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
65 scrollPane.setBounds(23, 113, 536, 271);
66 contentPane.add(scrollPane);
68 table = new JTable() {
69 private static final long serialVersionUID = 1L;
71 public boolean isCellEditable(int row, int column) {
75 scrollPane.setViewportView(table);
76 tableModel = new DefaultTableModel(null, new String[] {
77 "Name", "E-mail", "Bank Account" });
79 //Maybe there is a better way to avoid interaction.
80 //table.setEnabled(false);
81 table.setModel(tableModel);
83 JButton btnNewButton = new JButton("Confirm Addition");
84 btnNewButton.addActionListener(new ActionListener() {
85 public void actionPerformed(ActionEvent e) {
86 if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
87 AccountManager ama = new AccountManager();
88 Account accou = accounts.get(table.getSelectedRow());
89 //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
90 ama.addAccount(accou);
91 am.removeOwnerAdditionRequests(accou);;
92 Administrator.saveInstance();
93 ((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(accou));
94 accounts.remove(accou);
98 btnNewButton.setBounds(88, 396, 169, 25);
99 contentPane.add(btnNewButton);
101 JButton btnDenyAddition = new JButton("Deny Addition");
102 btnDenyAddition.addActionListener(new ActionListener() {
103 public void actionPerformed(ActionEvent arg0) {
104 if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
105 Account acc = accounts.get(table.getSelectedRow());
106 am.removeOwnerAdditionRequests(acc);
107 Administrator.saveInstance();
108 ((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(acc));
109 accounts.remove(acc);
113 btnDenyAddition.setBounds(300, 396, 169, 25);
114 contentPane.add(btnDenyAddition);
115 Enumeration<Account> en = accounts.elements();
118 while (en.hasMoreElements()) {
119 acc = en.nextElement();
120 Vector<Object> row = new Vector<Object>();
121 row.add(acc.getOwner().getName());
122 row.add(acc.getOwner().getMailAccount());
123 row.add(acc.getOwner().getBankAccount());
124 tableModel.addRow(row);