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); } } }