4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.rmi.Naming;
8 import java.rmi.RemoteException;
9 import java.util.Enumeration;
10 import java.util.Vector;
12 import javax.swing.JButton;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
16 import javax.swing.JScrollPane;
17 import javax.swing.JTable;
18 import javax.swing.border.EmptyBorder;
19 import javax.swing.table.DefaultTableModel;
21 import common.AccountInterface;
22 import common.AdminInterface;
24 import configuration.___IntNames;
25 import domain.Account;
27 public class listOfOwnerAddittionRequests extends JFrame {
32 private static final long serialVersionUID = 1L;
33 private JPanel contentPane;
35 private DefaultTableModel tableModel;
36 private AdminInterface am = null;
37 private Vector<Account> accounts;
41 public listOfOwnerAddittionRequests() {
43 am = (AdminInterface) Naming
44 .lookup(___IntNames.AdminManager);
45 } catch (Exception e1) {
46 System.out.println("Error accessing remote authentication: "
49 setTitle("Adding requests");
51 this.accounts= am.getOwnerAdditionRequests();
53 } catch (Exception e) {
58 private void init() throws Exception {
61 am = (AdminInterface) Naming
62 .lookup(___IntNames.AdminManager);
63 } catch (Exception e1) {
64 System.out.println("Error accessing remote authentication: "
67 setBounds(100, 100, 600, 450);
68 contentPane = new JPanel();
69 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
70 setContentPane(contentPane);
71 contentPane.setLayout(null);
73 JLabel lblNewLabel = new JLabel();
74 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
75 lblNewLabel.setBounds(23, 41, 536, 33);
76 contentPane.add(lblNewLabel);
77 if (accounts.isEmpty())
78 lblNewLabel.setText("There are not owners to be added");
80 lblNewLabel.setText("List of owners to be added:");
81 JScrollPane scrollPane = new JScrollPane();
82 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
83 scrollPane.setBounds(23, 113, 536, 271);
84 contentPane.add(scrollPane);
86 table = new JTable() {
87 private static final long serialVersionUID = 1L;
89 public boolean isCellEditable(int row, int column) {
93 scrollPane.setViewportView(table);
94 tableModel = new DefaultTableModel(null, new String[] {
95 "Name", "E-mail", "Bank Account" });
97 //Maybe there is a better way to avoid interaction.
98 //table.setEnabled(false);
99 table.setModel(tableModel);
101 JButton btnNewButton = new JButton("Confirm Addition");
102 btnNewButton.addActionListener(new ActionListener() {
103 public void actionPerformed(ActionEvent e) {
104 if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
105 AccountInterface acm = null;
108 acm = (AccountInterface) Naming
109 .lookup(___IntNames.AdminManager);
110 } catch (Exception e1) {
111 System.out.println("Error accessing remote authentication: "
114 Account accou = accounts.get(table.getSelectedRow());
116 acm.addAccount(accou);
117 am.removeOwnerAdditionRequests(accou);
119 } catch (RemoteException e1) {
120 // TODO Auto-generated catch block
121 e1.printStackTrace();
124 ((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(accou));
125 accounts.remove(accou);
129 btnNewButton.setBounds(88, 396, 169, 25);
130 contentPane.add(btnNewButton);
132 JButton btnDenyAddition = new JButton("Deny Addition");
133 btnDenyAddition.addActionListener(new ActionListener() {
134 public void actionPerformed(ActionEvent arg0) {
135 if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
136 Account acc = accounts.get(table.getSelectedRow());
138 am.removeOwnerAdditionRequests(acc);
140 } catch (RemoteException e) {
141 // TODO Auto-generated catch block
145 ((DefaultTableModel)table.getModel()).removeRow(accounts.indexOf(acc));
146 accounts.remove(acc);
150 btnDenyAddition.setBounds(300, 396, 169, 25);
151 contentPane.add(btnDenyAddition);
152 Enumeration<Account> en = accounts.elements();
155 while (en.hasMoreElements()) {
156 acc = en.nextElement();
157 Vector<Object> row = new Vector<Object>();
158 row.add(acc.getOwner().getName());
159 row.add(acc.getOwner().getMailAccount());
160 row.add(acc.getOwner().getBankAccount());
161 tableModel.addRow(row);